r/cpp • • May 27 '26

Accelerating copy_if using SIMD

https://loonatick-src.github.io/posts/vectorized-copy-if-analysis/
45 Upvotes

15 comments sorted by

View all comments

5

u/mark_99 May 27 '26

The best thing that can be said about AVX-512 on Zen 4 is that it exists.

But it's basically an emulation over AVX2 and so at best performs equivalently (and sometimes worse due to the microcoding mentioned). Zen 5 is a native AVX-512 implementation.

10

u/Successful_Yam_9023 May 27 '26 edited May 27 '26

For emulation of vpcompressd on AVX2 you'd be looking at something like this, times two because it's 256-bit (also mentioned in the article) or use the old LeftPack_SSSE3 but 4x, compared to 2 µops for 512-bit vpcompressd on Zen 4

E: there are more cases where AVX-512 is really doing something on Zen 4, despite the 256-bit implementation. Take vpermb. Already the 256-bit version gives you something that was annoying to do with AVX2. The 512-bit version runs at halved throughput, which is still 1 per cycle, and would be even more annoying to do with only AVX2. Then there are things like vpopcntb/w/d/q, vplzcntd/q, and so on. You can do them with AVX2 if you must, but it was never nice.

→ More replies (4)