4 ms·
Yeah but the code required for an overflow check is just one extra instruction (3 rather than 2)
by Taniwha 5y ago
Yeah but the code required for an overflow check is just one extra instruction (3 rather than 2)
- masklinn 5y agoFor generalised signed addition, the overhead is 3 instructions per addition. It can be one in specific contexts where more is known about the operands (e.g. addition of immediates). It’s always 1 in x64/ARM64 as they have built-in support for overflow.
- Taniwha 5y agoyou have to include the branch instruction too in any comparison
- kccqzy 5y agoIn x86 it is still one instruction: jc or jo after an addition.
- brucehoult 5y agoAnd in RISC-V it's a "BLT sum,summand" after an unsigned addition, and a single branch instruction after a signed addition if you know the sign of one of them e.g. adding or subtracting a constant.
- rurban 5y agobuilt-in support for overflow is not really builtin. There's only adc, but the C library has no such function, and compilers only got them added a few years ago. Almost nobody uses them, as they introduce a dependency. Most workaround that in much slower ways, worse than RISC-V