Repository navigation
Commit 73f18b6
authored
This re-applies the changes in #1258 with fixes for #1303. Changes to
the `BoxedUint` proptests in #1310 also help to validate the results.
The sqrt logic is implemented on `UintRef`, meaning one version is used
for both `Uint` and `BoxedUint`. This uses algorithm 1.12 in Modern
Computer Arithmetic rather than 1.13, which scales better for large
integers (approx O(2n)).
Addition and subtraction methods in `UintRef` are adjusted to accept an
rhs smaller than self. This was inconsistently applied before.
`checked_sqrt`(_vartime) no longer performs an additional squaring, so
its performance matches `floor_sqrt`.
Performance seems to be even better now, maybe due to `bitlen` inlining
or other changes.
<details>
<summary>Sample benchmarks</summary>
```
sqrt/floor_sqrt, U256 time: [136.87 ns 137.28 ns 137.74 ns]
change: [−79.375% −79.240% −79.049%] (p = 0.00 < 0.05)
Performance has improved.
sqrt/floor_sqrt, U512 time: [297.86 ns 298.67 ns 299.63 ns]
change: [−77.808% −77.716% −77.608%] (p = 0.00 < 0.05)
Performance has improved.
sqrt/floor_sqrt_vartime, U256
time: [67.951 ns 68.141 ns 68.360 ns]
change: [−82.235% −82.158% −82.067%] (p = 0.00 < 0.05)
Performance has improved.
sqrt/floor_sqrt, one Limb
time: [45.111 ns 45.260 ns 45.440 ns]
change: [−68.637% −68.525% −68.397%] (p = 0.00 < 0.05)
Performance has improved.
sqrt/floor_sqrt_vartime, U256 one Limb
time: [6.7108 ns 6.7672 ns 6.8396 ns]
change: [+17.539% +20.940% +23.453%] (p = 0.00 < 0.05)
Performance has regressed.
sqrt/checked_sqrt, U256 time: [141.94 ns 142.42 ns 142.98 ns]
change: [−78.972% −78.899% −78.816%] (p = 0.00 < 0.05)
Performance has improved.
sqrt/checked_sqrt_vartime, U256
time: [68.770 ns 69.016 ns 69.347 ns]
change: [−82.197% −82.130% −82.049%] (p = 0.00 < 0.05)
Performance has improved.
boxed_sqrt/floor_sqrt, 4096
time: [2.4790 µs 2.4855 µs 2.4945 µs]
change: [−95.591% −95.581% −95.568%] (p = 0.00 < 0.05)
Performance has improved.
boxed_sqrt/floor_sqrt_vartime, 4096
time: [2.2306 µs 2.2339 µs 2.2376 µs]
change: [−89.510% −89.493% −89.477%] (p = 0.00 < 0.05)
Performance has improved.
boxed_sqrt/checked_sqrt, 4096
time: [2.4750 µs 2.4780 µs 2.4814 µs]
change: [−95.636% −95.628% −95.620%] (p = 0.00 < 0.05)
Performance has improved.
boxed_sqrt/checked_sqrt_vartime, 4096
time: [2.2298 µs 2.2323 µs 2.2351 µs]
change: [−89.754% −89.732% −89.713%] (p = 0.00 < 0.05)
Performance has improved.
```
</details>
---------
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
1 parent 1ceecf0 commit 73f18b6
9 files changed
Lines changed: 641 additions & 233 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1045 | 1045 | | |
1046 | 1046 | | |
1047 | 1047 | | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
1048 | 1056 | | |
1049 | 1057 | | |
1050 | 1058 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | 111 | | |
115 | 112 | | |
116 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 3 | + | |
8 | 4 | | |
9 | 5 | | |
10 | 6 | | |
| |||
18 | 14 | | |
19 | 15 | | |
20 | 16 | | |
21 | | - | |
| 17 | + | |
| 18 | + | |
22 | 19 | | |
23 | 20 | | |
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 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
61 | 24 | | |
62 | 25 | | |
63 | 26 | | |
| |||
73 | 36 | | |
74 | 37 | | |
75 | 38 | | |
76 | | - | |
| 39 | + | |
| 40 | + | |
77 | 41 | | |
78 | 42 | | |
79 | 43 | | |
80 | 44 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
117 | 48 | | |
118 | 49 | | |
119 | 50 | | |
| |||
138 | 69 | | |
139 | 70 | | |
140 | 71 | | |
141 | | - | |
142 | | - | |
143 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
144 | 75 | | |
145 | 76 | | |
146 | 77 | | |
| |||
149 | 80 | | |
150 | 81 | | |
151 | 82 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
156 | 86 | | |
157 | 87 | | |
158 | 88 | | |
159 | 89 | | |
160 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
161 | 100 | | |
162 | 101 | | |
163 | 102 | | |
164 | 103 | | |
165 | 104 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
170 | 109 | | |
171 | 110 | | |
172 | 111 | | |
| |||
192 | 131 | | |
193 | 132 | | |
194 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
195 | 158 | | |
196 | 159 | | |
197 | 160 | | |
198 | | - | |
| 161 | + | |
199 | 162 | | |
200 | 163 | | |
201 | 164 | | |
202 | | - | |
| 165 | + | |
203 | 166 | | |
204 | 167 | | |
205 | 168 | | |
| |||
218 | 181 | | |
219 | 182 | | |
220 | 183 | | |
221 | | - | |
| 184 | + | |
222 | 185 | | |
223 | 186 | | |
224 | 187 | | |
| |||
307 | 270 | | |
308 | 271 | | |
309 | 272 | | |
310 | | - | |
311 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
312 | 293 | | |
313 | 294 | | |
314 | 295 | | |
| |||
362 | 343 | | |
363 | 344 | | |
364 | 345 | | |
365 | | - | |
366 | | - | |
367 | 346 | | |
368 | 347 | | |
369 | 348 | | |
| |||
384 | 363 | | |
385 | 364 | | |
386 | 365 | | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
387 | 381 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
0 commit comments