News for hackers. Stuff that matters.
Re:Lessons learned from profiling an algorithm in Rust by chrismorgan on Monday October 14, 2024 @11:06AM (#41838236)

  - 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.)

Re:Lessons learned from profiling an algorithm in Rust by durumu on Monday October 14, 2024 @11:25AM (#41838397)
I think it's i & 32. Agreed on that being more readable.
Re:Lessons learned from profiling an algorithm in Rust by urcyanide on Monday October 14, 2024 @11:59AM (#41838771)
Yes, i&32 is more readable.
Re:Lessons learned from profiling an algorithm in Rust by urcyanide on Monday October 14, 2024 @11:18AM (#41838328)
Not really, i \in (0..dim).step_by(32), shift \in {0, 32}, but for `i % 32` it's 0..32
Re:Lessons learned from profiling an algorithm in Rust by chrismorgan on Monday October 14, 2024 @11:44AM (#41838588)
Sorry, I wrote `i % 32` by accident, I meant `i & 32`.
Re:Lessons learned from profiling an algorithm in Rust by NovaX on Monday October 14, 2024 @12:46PM (#41839263)
I believe it is (!i & 32) because the bitwise version is an incorrect rewrite.

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

Re:Lessons learned from profiling an algorithm in Rust by urcyanide on Monday October 14, 2024 @01:04PM (#41839473)
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.