News for hackers. Stuff that matters.
Re:Zlib-rs is faster than C by vlovich123 on Sunday March 16, 2025 @06:44PM (#43383264)
Those specific functions are compiler builtin vector intrinsics. The main reason is that they can easily read past ends of arrays and have type safety and aliasing issues.

By the way, the rust compiler does generate such code because under the hood LLVM runs an autovectorizer when you turn on optimizations. However, for the autovectorizer to do a good job you have to write code in a very special way and you have no way of controlling whether or not it kicked in and once it did that it did a good job.

There’s work on creating safe abstractions (that also transparently scale to the appropriate vector instruction), but progress on that has felt slow to me personally and it’s not available outside nightly currently.

Re:Zlib-rs is faster than C by throwaway2037 on Monday March 17, 2025 @12:55AM (#43385330)

    > However, for the autovectorizer to do a good job you have to write code in a very special way
Can you give an example of this "very special way"?
Re:Zlib-rs is faster than C by saagarjha on Monday March 17, 2025 @05:41AM (#43386642)
For example many autovectorizers get upset if you put control flow in your loop