News for hackers. Stuff that matters.
Re:RISC-V Is Sloooow by adgjlsfhk1 on Tuesday March 10, 2026 @06:20PM (#47329497)
> On the other hand, detecting integer overflow in software is extremely expensive

this just isn't true. both addition and multiplication can check for overflow in <2 instructions.

Re:RISC-V Is Sloooow by nine_k on Tuesday March 10, 2026 @07:36PM (#47330147)
Fewer than two is exactly one instruction. Which?
Re:RISC-V Is Sloooow by adgjlsfhk1 on Tuesday March 10, 2026 @08:19PM (#47330433)
dammmit I meant <=2. https://godbolt.org/z/4WxeW58Pc sltu or snez for add/multiply respectively.
Re:RISC-V Is Sloooow by kbolino on Wednesday March 11, 2026 @11:45AM (#47337131)
This result is misleading.

First, the code claims to be returning "unsigned long" from each of these functions, but the value will only ever be 0 or 1 (see [1]). The code is actually throwing away the result and just returning whether overflow occurred. If we take unsigned long *c as another argument to the function, so that we actually keep the result, we end up having to issue an extra instruction for multiplication (see [2]; I'm ignoring the sd instruction since it is simply there to dereference the *c pointer and wouldn't exist if the function got inlined).

Second, this is just unsigned overflow detection. If we do signed overflow detection, now we're up to 5 instructions for add and mul (see [3]). Considering that this is the bigger challenge, it compares quite unfavorably to architectures where this is just 2 instructions: the operation itself and a branch against a condition flag.

[1]: https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins...

[2]: https://godbolt.org/z/7rWWv57nx

[3]: https://godbolt.org/z/PnzKaz4x5

Re:RISC-V Is Sloooow by adgjlsfhk1 on Wednesday March 11, 2026 @12:17PM (#47337569)
That's fair. The good news is that for signed overflow, you can claw back to the cost of unsigned overflow if you know the sign of either argument (which is fairly common).
Re:RISC-V Is Sloooow by kbolino on Wednesday March 11, 2026 @12:21PM (#47337619)
Yeah, it's not the end of the world, and as others mentioned, a good implementation can recognize the instruction pattern and optimize for it.

It's just a bizarre design choice. I understand wanting to get rid of condition flags, but not replacing them with nothing at all.

EDIT: It seems the same choice was made by MIPS, which is a clear inspiration for RISC-V.

Re:RISC-V Is Sloooow by adgjlsfhk1 on Wednesday March 11, 2026 @12:43PM (#47337918)
The argument is that there are actually 3 distinct forms of replacement:

1. 64 bit signed math is a lot less overflow vulnerable than the 16/32 bit math that was extremely common 20 years ago

2. For the BigInt use-case, the Riscv design is pretty sensible since you want the top bits, not just presence of overflow

3. You can do integer operations on the FPU (using the inexact flag for detecting if rounding occurred).

4. Adding overflow detecting instructions can easily be done in an extension in the future if desired.

Re:RISC-V Is Sloooow by kbolino on Wednesday March 11, 2026 @01:42PM (#47338719)
I think in the case of MIPS, at least, the decision logic was simply: condition flags behave like an implicit register, making the use of that register explicit would complicate the instruction encoding, and that complication would be for little benefit since most compilers ignore flags anyway, except for situations which could be replaced with direct tests on the result(s).
Re:RISC-V Is Sloooow by adrian_b on Tuesday March 10, 2026 @06:51PM (#47329762)
You are delusional.

Read the RISC-V documentation to see that you need at least 3 instructions.

For addition, overflow happens when you add 2 positive numbers and the result is negative, or when you add 2 negative numbers and the result is positive.

After using an instruction to do the addition, how can you detect this complex condition with a single instruction in the impoverished RISC-V ISA?

EDIT: Someone has downvoted this, presumably because I have not been polite enough.

That may be true, but I consider much more impolite the kind of misleading false information that has been written by the poster to whom I have replied. It is difficult to read that kind of b*s*t and be cool about it.

Re:RISC-V Is Sloooow by burntoutgray on Tuesday March 10, 2026 @08:47PM (#47330619)
+1 -- misinformation is best corrected quickly. If not, AI will propagate it and many will believe the erroneous information. I guess that would be viral hallucinations.
Re:RISC-V Is Sloooow by bigstrat2003 on Wednesday March 11, 2026 @12:15PM (#47337541)
One can quickly correct misinformation without being rude. It's not hard, and does not lessen the impact of the correction to do so. There's no reason to tolerate the kind of rudeness the parent post exhibits.