Hacker News new | ask | show | jobs
by PhilipRoman 1152 days ago
I wish x86 had an easy way to accumulate overflow flags, you could compile entire basic blocks as if they were using native integers, do a single check at the end, and if needed, roll back the computation.

The yielding part is harder. You need to have infrastructure in place to dynamically flush certain operations when unexpected yields happen.

1 comments

Floats can do it. Do your computation, and then check the inexact flag.
TIL such a thing exists. Although it seems like it is rarely used; there is some discussion here https://cs.stackexchange.com/questions/152373/what-are-the-u...

I guess most practical calculations would end up triggering the inexact flag.

Floats can represent all integers with magnitude <=2^53. Which is a sight smaller than integers, under the standard representation (magnitude <2^62), but still plenty for most applications—the point is to use this to implement integer math, not float math. That covers multiplication, addition, and subtraction; div/mod is admittedly a bit trickier, though it's a doozy with avx512.

(There's also a cute consequence: you can construct numbers outside the contiguous range of representable integers; so long as you never incur any rounding error, the result will be correct, and the inexact flag will not be set.)