by pjc50 · 10y ago · 0 comments
So rather than declaring vaguely that you want an "integer", you'd specify bounds, signed-ness (two or one's complement), and what happens on overflowing the bounds (wrap / saturate / exception / trap / set flag / set NAN etc.)
Saturated arithmetic intrinsics are widely available but generally not used by generated code. Similarly I've never seen an attempt at doing "integer NaN", which could be quite useful in some situations.
You'd probably also want some flags to say "give me a compiler error or warning if this code doesn't compile to intrinsics and is being emulated instead".
http://millcomputing.com/wiki/Instruction_Set_by_Category#Si...
Like this:
(Value >= 0 && Value <= 1000 && (Value & 1) == 0) || Value in(value_enum)
Would limit Value to even numbers between [0 .. 1000] except if it's an enum (for error values).
Simple example: Say, you multiply a number by two. From that, the compiler data flow analysis knows the lowest bit can only be zero. So it can safely optimize away anything that checks that bit.