Re:Relive: 50 years of C, the good, the bad and the ugly
by zozbot234 on Friday December 30, 2022 @01:27PM
(#34188109)
The performance hit of overflow has nothing to do with lacking assembly instructions. It's all about having to preserve error states whenever overflow occurs and inhibiting optimization.
[ Parent
| on HN ]
Re:Relive: 50 years of C, the good, the bad and the ugly
by menaerus on Saturday December 31, 2022 @05:28AM
(#34195207)
I don't follow. If we had the saturated ADD instruction supported in hardware we wouldn't have to deal with saturation logic in software. Compiler would simply be able to emit SADD instruction whenever we asked for it to and would be given a chance to spit out more optimized code because that would essentially be a branchless code.
Reality though is that we don't have such hardware and we have to deal with it in software, so, instead of a single instruction emitted there will be a bunch of them, and of which there will be certainly branches involved.