3 ms·
When I have used intrinsics, the compiler at least has a hope of getting this right, particularly when you use patterns like: __m256i mask = _mm256_set1_epi8(0
by pclmulqdq 4y ago
When I have used intrinsics, the compiler at least has a hope of getting this right, particularly when you use patterns like:
__m256i mask = _mm256_set1_epi8(0x0f)
If you just used the intrinsic that sets the register to a constant over and over, it often repeats the instruction.
The compilers just aren't that smart about SIMD yet.
- jeffreyrogers 4y agoHe sets it once like this before the loops. __m256i c = _mm256_set1_epi32(10001); And then the disassembly has mov eax, 10001 vpbroadcastd ymm1, eax before each loop.
- pclmulqdq 4y agoYeah, if the compiler runs out of registers it will do this - it's better than spilling the constant to memory. Register allocation is one thing that compilers are still much worse at than humans, and you see it in SIMD code a lot.
- DannyBee 4y agoEh. Compilers are only worse because we don't care. Optimal register allocation + spilling is easily doable now on today's machines/algorithms. We just don't bother because it's not truly worth it in most cases (IE we get most of the performance for a very low cost)