[rust-dev] Integer overflow, round -2147483648

comex comexk at gmail.com
Sun Jun 22 22:11:23 PDT 2014


On Mon, Jun 23, 2014 at 12:46 AM, comex <comexk at gmail.com> wrote:
> Second of all, it may be possible to do the checks more efficiently.
> I should look at clang's assembly output.

Specifically, for the record, I propose using MPX in the future as a
poor man's version of an overflow check instruction.  For adding
32-bit integers, you would check whether the result is > 2^32 with a
preset bound register (BNDCU instruction, 4 bytes) - admittedly, Rust
doesn't use those often... similar goes for 64-bit integers to which a
constant is being added (assuming you can hoist the job of loading the
negations of those constants into bound registers).  For arbitrary
64+64, you'd have to load one of the inputs into a bounds register,
which could be more expensive.

I have no idea how this will perform when it's released in Skylake;
it's more bytes than a jump, but it avoids cluttering the branch
predictor.  Anyway, it's not exactly far future.

(I am also curious about the possibility of improvements on current
architectures by doing things like deferring overflow checks... maybe
it's not possible in genera though.)


More information about the Rust-dev mailing list