function xorshift32_cl(seed::UInt32=0x92d68ca2)
y = seed
return function inner()
y = y $ (y << 13)
y = y $ (y >> 17)
y = y $ (y << 5)
return y
end
end
xorshift32_cl (generic function with 2 methods)
rgn = xorshift32_cl()
(::inner) (generic function with 1 method)
for _=1:10
println(rgn())
end
723471715 2497366906 2064144800 2008045182 3532304609 374114282 1350636274 691148861 746858951 2653896249
Base.gc()
@time for _=1:10000; rgn(); end
0.003055 seconds (59.66 k allocations: 932.203 KB)
@code_warntype rgn()
Variables: #self#::#inner#1 Body: begin SSAValue(0) = ((Core.getfield)((Core.getfield)(#self#::#inner#1,:y)::Any,:contents)::Any $ ((Core.getfield)((Core.getfield)(#self#::#inner#1,:y)::Any,:contents)::Any << 13)::Any)::Any (Core.setfield!)((Core.getfield)(#self#::#inner#1,:y)::Any,:contents,SSAValue(0))::Any # line 5: SSAValue(1) = ((Core.getfield)((Core.getfield)(#self#::#inner#1,:y)::Any,:contents)::Any $ ((Core.getfield)((Core.getfield)(#self#::#inner#1,:y)::Any,:contents)::Any >> 17)::Any)::Any (Core.setfield!)((Core.getfield)(#self#::#inner#1,:y)::Any,:contents,SSAValue(1))::Any # line 6: SSAValue(2) = ((Core.getfield)((Core.getfield)(#self#::#inner#1,:y)::Any,:contents)::Any $ ((Core.getfield)((Core.getfield)(#self#::#inner#1,:y)::Any,:contents)::Any << 5)::Any)::Any (Core.setfield!)((Core.getfield)(#self#::#inner#1,:y)::Any,:contents,SSAValue(2))::Any # line 7: return (Core.getfield)((Core.getfield)(#self#::#inner#1,:y)::Any,:contents)::Any end::Any
function xorshift32_cl2(seed::UInt32=0x92d68ca2)
y = seed
return function inner()::UInt32
_y = y::UInt32
_y = _y $ (_y << 13)
_y = _y $ (_y >> 17)
_y = _y $ (_y << 5)
y = _y
return _y
end
end
xorshift32_cl2 (generic function with 2 methods)
rgn2 = xorshift32_cl2()
(::inner) (generic function with 1 method)
for _=1:10
println(rgn2())
end
723471715 2497366906 2064144800 2008045182 3532304609 374114282 1350636274 691148861 746858951 2653896249
Base.gc()
@time for _=1:10000; rgn2(); end
0.000604 seconds (20.00 k allocations: 312.500 KB)
@code_warntype rgn2()
Variables: #self#::#inner#2 _y::UInt32 Body: begin SSAValue(0) = Main.UInt32 _y::UInt32 = (Core.typeassert)((Core.getfield)((Core.getfield)(#self#::#inner#2,:y)::Any,:contents)::Any,Main.UInt32)::UInt32 # line 5: _y::UInt32 = (Base.box)(UInt32,(Base.xor_int)(_y::UInt32,(Base.select_value)((Base.sle_int)(0,13)::Bool,(Base.box)(UInt32,(Base.shl_int)(_y::UInt32,(Base.box)(UInt64,13))),(Base.box)(UInt32,(Base.lshr_int)(_y::UInt32,(Base.box)(UInt64,(Base.box)(Int64,(Base.neg_int)(13))))))::UInt32)) # line 6: _y::UInt32 = (Base.box)(UInt32,(Base.xor_int)(_y::UInt32,(Base.select_value)((Base.sle_int)(0,17)::Bool,(Base.box)(UInt32,(Base.lshr_int)(_y::UInt32,(Base.box)(UInt64,17))),(Base.box)(UInt32,(Base.shl_int)(_y::UInt32,(Base.box)(UInt64,(Base.box)(Int64,(Base.neg_int)(17))))))::UInt32)) # line 7: _y::UInt32 = (Base.box)(UInt32,(Base.xor_int)(_y::UInt32,(Base.select_value)((Base.sle_int)(0,5)::Bool,(Base.box)(UInt32,(Base.shl_int)(_y::UInt32,(Base.box)(UInt64,5))),(Base.box)(UInt32,(Base.lshr_int)(_y::UInt32,(Base.box)(UInt64,(Base.box)(Int64,(Base.neg_int)(5))))))::UInt32)) # line 8: SSAValue(1) = _y::UInt32 (Core.setfield!)((Core.getfield)(#self#::#inner#2,:y)::Any,:contents,SSAValue(1))::UInt32 # line 9: return _y::UInt32 end::UInt32
type Xorshift32
y::UInt32
Xorshift32(seed::UInt32=0x92d68ca2) = new(seed)
end
function (g::Xorshift32)()
_y = g.y
_y = _y $ (_y << 13)
_y = _y $ (_y >> 17)
_y = _y $ (_y << 5)
g.y = _y
return _y
end
rgn3 = Xorshift32()
Xorshift32(0x92d68ca2)
for _=1:10
println(rgn3())
end
723471715 2497366906 2064144800 2008045182 3532304609 374114282 1350636274 691148861 746858951 2653896249
Base.gc()
@time for _=1:10000; rgn3(); end
0.000208 seconds (10.00 k allocations: 156.250 KB)
@code_warntype rgn3()
Variables: g::Xorshift32 _y::UInt32 Body: begin _y::UInt32 = (Core.getfield)(g::Xorshift32,:y)::UInt32 # line 8: _y::UInt32 = (Base.box)(UInt32,(Base.xor_int)(_y::UInt32,(Base.select_value)((Base.sle_int)(0,13)::Bool,(Base.box)(UInt32,(Base.shl_int)(_y::UInt32,(Base.box)(UInt64,13))),(Base.box)(UInt32,(Base.lshr_int)(_y::UInt32,(Base.box)(UInt64,(Base.box)(Int64,(Base.neg_int)(13))))))::UInt32)) # line 9: _y::UInt32 = (Base.box)(UInt32,(Base.xor_int)(_y::UInt32,(Base.select_value)((Base.sle_int)(0,17)::Bool,(Base.box)(UInt32,(Base.lshr_int)(_y::UInt32,(Base.box)(UInt64,17))),(Base.box)(UInt32,(Base.shl_int)(_y::UInt32,(Base.box)(UInt64,(Base.box)(Int64,(Base.neg_int)(17))))))::UInt32)) # line 10: _y::UInt32 = (Base.box)(UInt32,(Base.xor_int)(_y::UInt32,(Base.select_value)((Base.sle_int)(0,5)::Bool,(Base.box)(UInt32,(Base.shl_int)(_y::UInt32,(Base.box)(UInt64,5))),(Base.box)(UInt32,(Base.lshr_int)(_y::UInt32,(Base.box)(UInt64,(Base.box)(Int64,(Base.neg_int)(5))))))::UInt32)) # line 11: (Core.setfield!)(g::Xorshift32,:y,_y::UInt32)::UInt32 # line 12: return _y::UInt32 end::UInt32