58
submitted 5 months ago by chrs@programming.dev to c/rust@programming.dev
you are viewing a single comment's thread
view the rest of the comments
[-] zweieuro@lemmy.world 16 points 5 months ago

Correct me if I am wrong but isn't "loop unrolling/unwinding" something that the c++ and rust compilers do? Why does the loop here not get unwound?

[-] Giooschi@lemmy.world 14 points 5 months ago

Loop unrolling is not really the speedup, autovectorization is. Loop unrolling does often help with autovectorization, but is not enough, especially with floating point numbers. In fact the accumulation operation you're doing needs to be associative, and floating point numbers addition is not associative (i.e. (x + y) + z is not always equal to (x + (y + z)). Hence autovectorizing the code would change the semantics and the compiler is not allowed to do that.

[-] bonus_crab@lemmy.world 7 points 5 months ago

so if (somehow) the accumulator was an integer, this loop would autovectorize and the performance differences would be smaller ?

[-] Giooschi@lemmy.world 4 points 5 months ago

Very likely yes

this post was submitted on 08 Apr 2024
58 points (91.4% liked)

Rust

5754 readers
29 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS