]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #41250 - kennytm:fix-41228, r=nikomatsakis
authorCorey Farwell <coreyf@rwell.org>
Thu, 13 Apr 2017 17:04:15 +0000 (13:04 -0400)
committerGitHub <noreply@github.com>
Thu, 13 Apr 2017 17:04:15 +0000 (13:04 -0400)
commit6dfd8f6e12e94ca17009d641cff743a13a13285c
tree42d36ca52ad06607b2b8d32cd04f3d1b823b2a29
parent9eb3468e2f40ea2c3d7f00de07e51214c37f71e5
parent71a9e106690627e657a466938e578608d8bcd04a
Rollup merge of #41250 - kennytm:fix-41228, r=nikomatsakis

Fix invalid 128-bit division on 32-bit target (#41228)

The bug of #41228 is a typo, this line: https://github.com/rust-lang/rust/blob/1dca19ae3fd195fa517e326a39bfee729da7cadb/src/libcompiler_builtins/lib.rs#L183

```rust
            // 1 <= sr <= u64::bits() - 1
            q = n.wrapping_shl(64u32.wrapping_sub(sr));
```

The **64** should be **128**.

(Compare with https://github.com/rust-lang-nursery/compiler-builtins/blob/280d19f1127aa80739f4179152b11a5f7d36d79f/src/int/udiv.rs#L213-L214:

```rust
            // 1 <= sr <= <hty!($ty)>::bits() - 1
            q = n << (<$ty>::bits() - sr);
```

Or compare with the C implementation https://github.com/llvm-mirror/compiler-rt/blob/master/lib/builtins/udivmodti4.c#L113-L116

```c
        /* 1 <= sr <= n_udword_bits - 1 */
        /* q.all = n.all << (n_utword_bits - sr); */
        q.s.low = 0;
        q.s.high = n.s.low << (n_udword_bits - sr);
```
)

Added a bunch of randomly generated division test cases to try to cover every described branch of `udivmodti4`.