Commit 4b08b2e
authored
Rollup merge of rust-lang#128166 - ChaiTRex:isqrt, r=tgross35
Improved `checked_isqrt` and `isqrt` methods
### Improved tests of `isqrt` and `checked_isqrt` implementations
* Inputs chosen more thoroughly and systematically.
* Checks that `isqrt` and `checked_isqrt` have equivalent results for signed types, either equivalent numerically or equivalent as a panic and a `None`.
* Checks that `isqrt` has numerically-equivalent results for unsigned types and their `NonZero` counterparts.
### Added benchmarks for `isqrt` implementations
### Greatly sped up `checked_isqrt` and `isqrt` methods
* Uses a lookup table for 8-bit integers and then the Karatsuba square root algorithm for larger integers.
* Includes optimization hints that give the compiler the exact numeric range of results.
### Feature tracking issue
`isqrt` is an unstable feature tracked at rust-lang#116226.
<details><summary>Benchmarked improvements</summary>
### Command used to benchmark
./x bench library/core -- int_sqrt
### Before
benchmarks:
num::int_sqrt::i128::isqrt 439591.65/iter +/- 6652.70
num::int_sqrt::i16::isqrt 5302.97/iter +/- 160.93
num::int_sqrt::i32::isqrt 62999.11/iter +/- 2022.05
num::int_sqrt::i64::isqrt 125248.81/iter +/- 1674.43
num::int_sqrt::i8::isqrt 123.56/iter +/- 1.87
num::int_sqrt::isize::isqrt 125356.56/iter +/- 1017.03
num::int_sqrt::non_zero_u128::isqrt 437443.75/iter +/- 3535.43
num::int_sqrt::non_zero_u16::isqrt 8604.58/iter +/- 94.76
num::int_sqrt::non_zero_u32::isqrt 62933.33/iter +/- 517.30
num::int_sqrt::non_zero_u64::isqrt 125076.38/iter +/- 11340.61
num::int_sqrt::non_zero_u8::isqrt 221.51/iter +/- 1.58
num::int_sqrt::non_zero_usize::isqrt 136005.21/iter +/- 2020.35
num::int_sqrt::u128::isqrt 439014.55/iter +/- 3920.45
num::int_sqrt::u16::isqrt 8575.08/iter +/- 148.06
num::int_sqrt::u32::isqrt 63008.89/iter +/- 803.67
num::int_sqrt::u64::isqrt 125088.09/iter +/- 879.29
num::int_sqrt::u8::isqrt 230.18/iter +/- 2.04
num::int_sqrt::usize::isqrt 125237.51/iter +/- 4747.83
### After
benchmarks:
num::int_sqrt::i128::isqrt 105184.89/iter +/- 1171.38
num::int_sqrt::i16::isqrt 1910.26/iter +/- 78.50
num::int_sqrt::i32::isqrt 34260.34/iter +/- 960.84
num::int_sqrt::i64::isqrt 45939.19/iter +/- 2525.65
num::int_sqrt::i8::isqrt 22.87/iter +/- 0.45
num::int_sqrt::isize::isqrt 45884.17/iter +/- 595.49
num::int_sqrt::non_zero_u128::isqrt 106344.27/iter +/- 780.99
num::int_sqrt::non_zero_u16::isqrt 2790.19/iter +/- 53.43
num::int_sqrt::non_zero_u32::isqrt 33613.99/iter +/- 362.96
num::int_sqrt::non_zero_u64::isqrt 46235.42/iter +/- 429.69
num::int_sqrt::non_zero_u8::isqrt 31.78/iter +/- 0.75
num::int_sqrt::non_zero_usize::isqrt 46208.75/iter +/- 375.27
num::int_sqrt::u128::isqrt 106385.94/iter +/- 1649.95
num::int_sqrt::u16::isqrt 2747.69/iter +/- 28.72
num::int_sqrt::u32::isqrt 33627.09/iter +/- 475.68
num::int_sqrt::u64::isqrt 46182.29/iter +/- 311.16
num::int_sqrt::u8::isqrt 33.10/iter +/- 0.30
num::int_sqrt::usize::isqrt 46165.00/iter +/- 388.41
</details>
Tracking Issue for {u8,i8,...}::isqrt rust-lang#116226
try-job: test-variousFile tree
11 files changed
+684
-67
lines changed- library/core
- benches
- num
- int_sqrt
- src/num
- tests/num
11 files changed
+684
-67
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1641 | 1641 | | |
1642 | 1642 | | |
1643 | 1643 | | |
1644 | | - | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
1645 | 1671 | | |
1646 | 1672 | | |
1647 | 1673 | | |
| |||
2862 | 2888 | | |
2863 | 2889 | | |
2864 | 2890 | | |
| 2891 | + | |
2865 | 2892 | | |
2866 | | - | |
2867 | | - | |
2868 | | - | |
2869 | | - | |
2870 | | - | |
2871 | 2893 | | |
2872 | 2894 | | |
2873 | | - | |
| 2895 | + | |
2874 | 2896 | | |
2875 | 2897 | | |
2876 | 2898 | | |
| |||
0 commit comments