3 ms·
Actually, those functions are intrinsics in the Go compiler on many platforms, so the compiler generates a single ADD / ADC opcode. The source code that you see
by giovannibajo1 8y ago
Actually, those functions are intrinsics in the Go compiler on many platforms, so the compiler generates a single ADD / ADC opcode. The source code that you see is a fallback for backends that have not implemented them as intrinsics yet.
- leni536 8y agogcc can optimize generic code for a carry check. To be fair both clang and msvc fails to optimize this specific case. https://godbolt.org/z/6WXfnL https://godbolt.org/z/6WXfnL Edit: OK, I have much worse time generating "adc" instructions, and only gcc sees the opportunity to emit "setc" where appropriate. I see the issue now.
- giovannibajo1 8y agoCorrect, gcc can generate "setc" but not "adc", AFAIK.
- boomlinde 8y agoThat's true, but I'm specifically addressing the compactness and readability concern. With respect to efficiency and particularly timing, Go and C seems to be in the same boat here in that depending on your compiler and platform it may either compile to a constant time chain of add/adc equivalent instructions or something sub-optimal and branchy.