Skip to content

Conversation

@jaredhoberock
Copy link

@jaredhoberock jaredhoberock commented Feb 15, 2019

Hi, thanks for providing this implementation of threefry4x64.

I think I may have noticed typos in the implementation of extract4x64_impl::nth. The original code has expressions like these:

return (_output[n>>3] >> ((n&111)<<3)) & 0xFF; }

I believe the n&111 is a typo. The intention seems to be a bitwise AND with three set bits. But this is integer 111, not 0b111. In practice, this can produce a right shift that is too large for the type of n and generate undefined behavior. I noticed this when comparing the behavior of programs produced by different compilers.

Correcting this to n&7 seems to produce the correct results.

Are these expressions typos?

@sitmo
Copy link
Owner

sitmo commented Feb 16, 2019 via email

@jaredhoberock
Copy link
Author

Ah, too bad.

Anyway, thanks again for putting in the effort for this implementation. I'll leave the PR open in case anyone else finds the diff useful.

@sitmo
Copy link
Owner

sitmo commented Feb 16, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants