-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Circular shifts #6
Comments
This seems to work as desired on 0.5 (with -O3), but not on 0.4 function rotr(x,y)
s = sizeof(x) << 3
(x >> (y % s)) | (x << (-y % s))
end |
Thanks, Simon. The former one seems very nice, I'll use this. BTW there's a typo in the codes that it should be |
Why would it be 63, not 64? |
I would suggest the latter one: the generality is well worth it, and hopefully 0.5 should be released by the time we're performance tuning. llvmcall is usually the last resort sort of thing. |
Oh I just found myself wrong. Okay, it's reasonable to take the second function. |
Yesterday did you mean that I should just write @inline function pcg_rotr(x::UIntTypes, y::UIntTypes)
s = sizeof(x) << 3
(x >> (y % s)) | (x << (-y % s))
end instead of the current |
Yes, exactly: You could even do this for a lot of the other functions, as it seems like the constants can mostly be computed (and so will be evaluated at compile time). |
e.g. for XSH RR, you could include in the function s = sizeof(state) << 3
t = trailing_zeros(s)-1 # log2(s)-1
p1 = (s>>1 + t)>>1
p2 = s>>1 - t
p3 = s-t which the JIT is smart enough to evaluate as constants. |
Though for 128 bits, this gives a |
I copied the constants in the PCG sources. http://www.pcg-random.org/download.html |
Ah, I see. I opened an issue here: I guess we see what the author says. |
You had a comment about moving circular shifts to assembly. One alternative is to use llvmcall:
then using 0.4, or 0.5 with -O3 (which is how packages are precompiled), gives the appropriate
rorq
instruction.The text was updated successfully, but these errors were encountered: