4 ms·
Overflow checking all arithmetic is still going to be quite expensive, even with hardware support, because you have to choose between: A) exception/panic on ov
by Peaker 11y ago
Overflow checking all arithmetic is still going to be quite expensive, even with hardware support, because you have to choose between:
A) exception/panic on overflow: this is preferable to overflow but also undesirable behavior.
B) arbitrary precision integers: this is nicer, but even today significantly more expensive than ordinary integers.
- Athas 11y ago> A) exception/panic on overflow: this is preferable to overflow but also undesirable behavior. I don't find this undesirable at all. I have worked in languages where this is the default (Standard ML) and it's quite nice. You can always explicitly use a word-type if you actually want overflow. With hardware support, it is even fairly cheap to implement, as you just connect the overflow bit of your integer ALUs to something interrupt-triggering.
- psykotic 11y ago> With hardware support, it is even fairly cheap to implement, as you just connect the overflow bit of your integer ALUs to something interrupt-triggering. You can exploit the IEEE-754 inexactness exception with doubles if you're okay with 53 bits of integer precision. Tim Sweeney showed me this trick a long time ago, which he combined with run-time code patching so that an arithmetic operation would be speculatively compiled as either fixnum or bignum based on observed run-time behavior. It'd compile it to fixnum by default with an overflow trap using the FP inexact exception. The trap would patch the fixnum site with the equivalent bignum code and resume. With hindsight inspired by modern trace compilers like LuaJIT, the better approach is probably to compile entire traces speculated on either case, so you can hoist most of the guard predicates and not speculate based solely on the proximate call site but on longer traces.