[rust-dev] Division and modulo for signed numbers

Patrick Walton pwalton at mozilla.com
Tue Apr 23 09:20:02 PDT 2013

On 4/23/13 8:50 AM, Erik S wrote:
> Patrick,
> I would agree with you if it weren't for the cases where F-division
> performs *better*. Division by a constant power-of-two is pretty common,
> and is much faster in F-division.
> I don't think correctness should be sacrificed for a slight performance
> improvement in one case on one supported architecture. I've had real
> bugs in my C code caused by incorrectly casting (or forgetting to cast)
> to unsigned before a % operation. T-division causes *real* bugs.
> I'm willing to spend some time implementing F-division, if I can get
> some buy-in that the patch would be accepted.

Keep in mind that you will also need to implement an LLVM intrinsic, 
port all of the LLVM optimizations that apply to division to it, and 
make sure that they don't regress LLVM benchmarks. (You may want to add 
it to clang first actually.)


More information about the Rust-dev mailing list