News for hackers. Stuff that matters.
Re:Catching integer overflows in C by saagarjha on Wednesday August 22, 2018 @02:34AM (#17816789)
Not every processor has these flags.
Re:Catching integer overflows in C by Annatar on Wednesday August 22, 2018 @03:10AM (#17816926)
Processors had these en masse (6502, Z80, MC68000) since the ‘70’s of the past century. Without those, it’s extremely difficult to implement basic arithmetic with numbers larger than what the processor’s registers support.

Which contemporary processors don’t have the C and Z status bits?

Post scriptum, since “Hacker News” is of the opinion that I’m posting too fast:

MIPS does have a status register, and this register does have an overflow bit:

https://www.doc.ic.ac.uk/lab/secondyear/spim/node10.html

Re:Catching integer overflows in C by saagarjha on Wednesday August 22, 2018 @03:16AM (#17816952)
MIPS?

------------------

Addendum addressing your updates:

> MIPS does have a status register, and this register does have an overflow bit:

Yes, it does, but it doesn't function as a simple carry or zero bitfield. In MIPS, there are two instructions for performing addition: add and addu. add generates a trap which you can respond to in an exception handler (which is where you check for this exception code)–as opposed to addu, which overflows silently. Most programs explicitly looking to check for overflow just use addu followed by a sltu (set less than, unsigned).

Re:Catching integer overflows in C by Annatar on Wednesday August 22, 2018 @06:38AM (#17817699)
“u” in “addu” means unsigned, so if I’m using it, I understand what the implication is.
Re:Catching integer overflows in C by saagarjha on Thursday August 23, 2018 @02:50AM (#17825123)
What implication are you talking about?
Re:Catching integer overflows in C by Annatar on Thursday August 23, 2018 @03:29AM (#17825276)
That there is no bit used for the sign, and so I know when the registers will overflow. A lot of the assembler code I wrote exploits this very fact, since when used cleverly it’s a performance optimization.
Re:Catching integer overflows in C by AstralStorm on Wednesday August 22, 2018 @03:57AM (#17817106)
Unfortunately, the bit has overloaded meaning. Plus you're still injecting expensive branches which the branch slot is unlikely to fix.
Re:Catching integer overflows in C by Annatar on Wednesday August 22, 2018 @06:42AM (#17817712)
You’ll never feel that penalty if you’re writing the assembler code by hand, not even on the oldest, slowest MIPS processor, and if you’re using a compiler, the compiler intrinsic has to do the same thing.
Re:Catching integer overflows in C by snaky on Wednesday August 22, 2018 @03:47AM (#17817068)
Re:Catching integer overflows in C by Annatar on Wednesday August 22, 2018 @06:52AM (#17817748)
Mashey has a good argument, however I think that the sr overload could be solved with one sr per pipeline. For example, if the CPU is a six pipeline superscalar design, like MIPS R10000 was, implement sr0 to sr5.