[rust-dev] Integer overflow, round -2147483648

John Regehr regehr at cs.utah.edu
Mon Jun 23 08:37:45 PDT 2014

> I would think that something simple like
>    let mut sum = 0;
>    for x in some_int_array.iter() {
>        sum += x;
>    }
> would be very hard to vectorise with unwinding integer operations.

It sounds like there are two problems.  First, you need to give up on 
precise exceptions.  So the code becomes something line:

let mut sum = 0;
overflow = false
for x in some_int_array.iter() {
   (sum,o) = x+sum
   overflow |= o
if (overflow) deal with it

The other problem is that as far as I know AVX doesn't store the overflow 
bits for integer vector operations and recovering these bits another way 
isn't necessarily cheap.

In an earlier mail Patrick said that AIR integers are research and using 
research results is risky.  This is true but keep in mind that Ada's 
approach to integer overflows is substantially similar to AIR, and Ada is 
not a research language.


More information about the Rust-dev mailing list