4 ms·
I would prefer assembly code than C intrinsics (I usually go for the intel syntax).
by sylware 5y ago
I would prefer assembly code than C intrinsics (I usually go for the intel syntax).
- rincebrain 5y agoI've recently become convinced intrinsics have a strong reason to at least try them after I rewrote something that was using inline ASM into intrinsics 1:1, and got a not-insignificant speedup, evidently solely because the compiler was better at optimizing it than I was.
- ygra 5y agoInline ASM might be somewhat opaque to the compiler and interfere with optimization in general. It's not in the IR format that the optimizer uses; register allocation is probably up to the ASM code, not the compiler's choice, perhaps forcing it to either skip optimizing a complete function, just the block in which inline ASM appears, or even to add additional code outside the block to make it run correctly.
- rincebrain 5y agoAIUI compilers treat inline ASM as an entirely opaque block they cannot mutate or assume much about, so if you're inlining 100 lines of ASM, you will get the ASM you asked for, for better or worse. (Treating it as completely opaque is, I believe, also why you can get away with things like inlining AVX2 ASM on an -mno-avx2 build, for example.)
- alephnil 5y agoIf you use intrinsics, you don't have to deal with the different calling conventions of each operating system, so I have used intrinsics for that reason alone, since I otherwise had to write separate versions for Linux and Windows or have a lot of conditional code.