4 ms·
Or you could have a "sticky" overflow flag, so that you could check for overflow after each complete expression instead of after every single math operation. Th
by zvrba 12y ago
Or you could have a "sticky" overflow flag, so that you could check for overflow after each complete expression instead of after every single math operation. This needs one new flag and one new conditional instruction. (Plus compiler modifications.)
- pbsd 12y agox86-64 could repurpose the Adjust flag (bit 4 of EFLAGS) for this. It is not longer used, since BCD instructions were deprecated in the x86->x86-64 transition. There is also precedent in the last few years for new instructions that change flag semantics: ADCX and ADOX.
- stormbrew 12y agoI don't know if this solves all the associated problems. If part of the chain of operations isn't side-effect-free, eg. function call, you'll still have to check more than once for the whole chain. And if you want to do more than throw an error/exception you may need to re-run the operations on a slow path to get the correct result. But I like it a lot even so. For a general case it seems like it would help.
- xxs 12y agoThe branch is to be predicted (close to perfectly) by the hardware so the branch cost would be like an extra cycle.