4 ms·
@addWithOverflow is easy to implement in C, but you still need to look at the assembler code to see if the compiler did the right thing. I don't like that tens
by nickcw 6y ago
@addWithOverflow is easy to implement in C, but you still need to look at the assembler code to see if the compiler did the right thing.
I don't like that tension between C code you've arranged in just the right way and hoping that it continues to generate the assembler output it did once.
I guess a portable set of compiler intrinsics it what is really needed to solve this problem.
There is an x86 intrinsic for 32 x 32 -> 64 bit multiply now-a-days
https://docs.microsoft.com/en-us/cpp/intrinsics/emul-emulu?view=msvc-160 https://docs.microsoft.com/en-us/cpp/intrinsics/emul-emulu?v...
And one for 32 + 32 -> 32 + carry also.
Though I don't know how portable __emulu is.. does it work on ARM for instance?
- bombcar 6y agoToo bad you can’t put some sort of assert saying “this code should generate this assembly assuming x86-64” or something - at least get a warning if the compiler upgrade changes it.
- Karliss 6y agoIf the performance is important you can have performance regression tests. If not, then it probably doesn't matter too much if it always generates optimal assembly for this specific line of code.