3 ms·
I'm not following you here. Most systems (if not all) are byte-addressable 2's complement systems, and in a 2's complement system, you use the same instruction
by spc476 3y ago
I'm not following you here. Most systems (if not all) are byte-addressable 2's complement systems, and in a 2's complement system, you use the same instructions for math for both signed and unsigned integers. Compiler writers aren't using different instructions for signed vs. unsigned, they're using different assumptions about interpretations, along the lines of "if X is signed, then x = x + 1 will never wrap, because that is UB, and as we all know, programmers will never intentionally or unintentionally, invoke UB, so we can skip some checks and if the program blows up, it's the programmers fault for not being perfect."
- UncleMeat 3y agoDepends on the target. If you have a 32 bit unsigned integer and your hardware wraps at 64 bit, you need special logic to wrap correctly at 32 bits. This also can prevent some vectorization since you don't have the guarantee that the result of x + 1 is one larger than x.