Re:Myths about Integer Overflow in Rust
by eridius on Friday April 29, 2016 @08:25PM
(#11599644)
That doesn't actually eliminate range checks. Hardware doesn't have native saturating overflow operations so the saturating overflow methods are implemented by doing a checked overflow and using the min/max value of the type if it overflows/underflows. Which is to say, it removes them from your code, but there's no performance benefit to it.
[ Parent
| on HN ]
>Hardware doesn't have native saturating overflow operations
Uh, what hardware are you talking about? x86 and ARM at the least have saturating arithmetic instructions.
They do? I admit I'm not an expert on either x86 or ARM assembly, but I've never seen code that used a saturating arithmetic instruction, and the saturating math in Rust is implemented using checked arithmetic as opposed to any kind of llvm intrinsic for saturating math. Looking at the LLVM docs I don't see any kind of intrinsic for saturating math either (checked math uses llvm.sadd.with.overflow.* and friends).