Hacker News new | ask | show | jobs
by chrismorgan 779 days ago

  - let shift = if (i / 32) % 2 == 0 { 32 } else { 0 };
  + let shift = ((i >> 5) & 1) << 5;
Uh, that’s just `let shift = i & 32;`, right? Much easier to read, too, in my opinion.

(Edit: fixed from i % 32 to i & 32.)

3 comments

I believe it is (!i & 32) because the bitwise version is an incorrect rewrite.

[1] https://news.ycombinator.com/item?id=41830016

Sorry for the confusing example. The bitwise one is correct since I store the binary in u64 with a different endian from the C++ version. (this happens because the C++ version is using a numpy script to do the preprocessing) My bad, I should explain it in a better way. Will update the post.
I think it's i & 32. Agreed on that being more readable.
Yes, i&32 is more readable.
Not really, i \in (0..dim).step_by(32), shift \in {0, 32}, but for `i % 32` it's 0..32
Sorry, I wrote `i % 32` by accident, I meant `i & 32`.