←back to thread

305 points todsacerdoti | 1 comments | | HN request time: 0.251s | source
Show context
robertknight ◴[] No.44061261[source]
Good post! The inefficient code for comparing pairs of 16-bit integers was an interesting find.
replies(1): >>44061353 #
ohr ◴[] No.44061353[source]
Thanks! Would be interesting to see if Rust/LLVM folks can get the compiler to apply this optimization whenever possible, as Rust can be much more accurate w.r.t memory initialization.
replies(3): >>44061438 #>>44061766 #>>44062908 #
1. kukkamario ◴[] No.44062908[source]
I think in this case Rust and C code aren't equivalent which maybe caused this slow down. Union trick also affects the alignment. C side struct is 32 bit aligned, but Rust struct only has 16bit alignment because it only contains fields with 16bit alignment. In practice the fields are likely anyway correctly aligned to 32bits, but compiler optimizations may have hard time verifying that.

Have you tried manually defining alignment of Rust struct?