-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy path512Math.t.sol
More file actions
457 lines (367 loc) · 18.2 KB
/
512Math.t.sol
File metadata and controls
457 lines (367 loc) · 18.2 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import {uint512, alloc, tmp} from "src/utils/512Math.sol";
import {SlowMath} from "./SlowMath.sol";
import {Test} from "@forge-std/Test.sol";
contract Lib512MathTest is Test {
function test512Math_oaddBothForeign(uint256 x, uint256 y) external pure {
(uint256 r_hi, uint256 r_lo) = tmp().oadd(x, y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullAdd(x, 0, y, 0);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_oaddForeign(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
uint512 x = alloc().from(x_hi, x_lo);
(uint256 r_hi, uint256 r_lo) = tmp().oadd(x, y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullAdd(x_lo, x_hi, y, 0);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_iaddForeign(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
(uint256 r_hi, uint256 r_lo) = tmp().from(x_hi, x_lo).iadd(y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullAdd(x_lo, x_hi, y, 0);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_oaddNative(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external pure {
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
(uint256 r_hi, uint256 r_lo) = tmp().oadd(x, y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullAdd(x_lo, x_hi, y_lo, y_hi);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_iaddNative(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external pure {
uint512 y = alloc().from(y_hi, y_lo);
(uint256 r_hi, uint256 r_lo) = tmp().from(x_hi, x_lo).iadd(y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullAdd(x_lo, x_hi, y_lo, y_hi);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_osubForeign(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
vm.assume(x_hi > 0 || x_lo >= y);
uint512 x = alloc().from(x_hi, x_lo);
(uint256 r_hi, uint256 r_lo) = tmp().osub(x, y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullSub(x_lo, x_hi, y, 0);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_isubForeign(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
vm.assume(x_hi > 0 || x_lo >= y);
(uint256 r_hi, uint256 r_lo) = tmp().from(x_hi, x_lo).isub(y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullSub(x_lo, x_hi, y, 0);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_osubNative(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external pure {
vm.assume(x_hi > y_hi || (x_hi == y_hi && x_lo >= y_lo));
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
(uint256 r_hi, uint256 r_lo) = tmp().osub(x, y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullSub(x_lo, x_hi, y_lo, y_hi);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_isubNative(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external pure {
vm.assume(x_hi > y_hi || (x_hi == y_hi && x_lo >= y_lo));
uint512 y = alloc().from(y_hi, y_lo);
(uint256 r_hi, uint256 r_lo) = tmp().from(x_hi, x_lo).isub(y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullSub(x_lo, x_hi, y_lo, y_hi);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_omulBothForeign(uint256 x, uint256 y) external pure {
(uint256 r_hi, uint256 r_lo) = tmp().omul(x, y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(x, y);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_omulForeign(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
uint512 x = alloc().from(x_hi, x_lo);
(uint256 r_hi, uint256 r_lo) = tmp().omul(x, y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(x_lo, x_hi, y, 0);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_imulForeign(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
(uint256 r_hi, uint256 r_lo) = tmp().from(x_hi, x_lo).imul(y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(x_lo, x_hi, y, 0);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_omulNative(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external pure {
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
(uint256 r_hi, uint256 r_lo) = tmp().omul(x, y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(x_lo, x_hi, y_lo, y_hi);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_imulNative(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external pure {
uint512 y = alloc().from(y_hi, y_lo);
(uint256 r_hi, uint256 r_lo) = tmp().from(x_hi, x_lo).imul(y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(x_lo, x_hi, y_lo, y_hi);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_mod(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
vm.assume(y != 0);
uint256 r = tmp().from(x_hi, x_lo).mod(y);
(uint256 e_lo, uint256 e_hi) = SlowMath.fullDiv(x_lo, x_hi, y);
(e_lo, e_hi) = SlowMath.fullMul(e_lo, e_hi, y, 0);
(e_lo, e_hi) = SlowMath.fullSub(x_lo, x_hi, e_lo, e_hi);
assertEq(r, e_lo);
assertEq(e_hi, 0);
}
// omod and imod don't have test cases because I don't have a way to derive
// a reference implementation without using 512Math's division routines
function test512Math_divForeign(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
vm.assume(y != 0);
uint256 r_lo = tmp().from(x_hi, x_lo).div(y);
(uint256 e_lo,) = SlowMath.fullDiv(x_lo, x_hi, y);
assertEq(r_lo, e_lo);
}
function test512Math_divNative(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external view {
vm.assume(y_hi != 0);
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
uint256 q = x.div(y);
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(y_lo, y_hi, q, 0);
uint512 e = alloc().from(e_hi, e_lo);
assertTrue(e <= x);
assertTrue((q == 0 && x < y) || e > tmp().osub(x, y));
}
function test512Math_odivForeign(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
vm.assume(y != 0);
uint512 x = alloc().from(x_hi, x_lo);
(uint256 r_hi, uint256 r_lo) = tmp().odiv(x, y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullDiv(x_lo, x_hi, y);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_idivForeign(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
vm.assume(y != 0);
(uint256 r_hi, uint256 r_lo) = tmp().from(x_hi, x_lo).idiv(y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullDiv(x_lo, x_hi, y);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_odivNative(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external view {
vm.assume(y_hi != 0);
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
(uint256 r_hi, uint256 r_lo) = tmp().odiv(x, y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(y_lo, y_hi, r_lo, r_hi);
uint512 e = alloc().from(e_hi, e_lo);
assertTrue(e <= x);
assertTrue((r_hi == 0 && r_lo == 0 && x < y) || e > tmp().osub(x, y));
}
function test512Math_idivNative(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external view {
vm.assume(y_hi != 0);
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
(uint256 r_hi, uint256 r_lo) = tmp().from(x).idiv(y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(y_lo, y_hi, r_lo, r_hi);
uint512 e = alloc().from(e_hi, e_lo);
assertTrue(e <= x);
assertTrue((r_hi == 0 && r_lo == 0 && x < y) || e > tmp().osub(x, y));
}
function test512Math_odivAlt(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external pure {
vm.assume(y_hi != 0);
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
(uint256 r_hi, uint256 r_lo) = tmp().odivAlt(x, y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(y_lo, y_hi, r_lo, r_hi);
uint512 e = alloc().from(e_hi, e_lo);
assertTrue(e <= x);
assertTrue((r_hi == 0 && r_lo == 0 && x < y) || e > tmp().osub(x, y));
}
function test512Math_omodAlt(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external view {
vm.assume(y_hi != 0);
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
uint512 r = alloc().omodAlt(x, y);
uint512 e = alloc().omod(x, y);
assertTrue(r == e);
}
function test512Math_sqrt(uint256 x_hi, uint256 x_lo) external pure {
uint512 x = alloc().from(x_hi, x_lo);
uint256 r = x.sqrt();
(uint256 r2_lo, uint256 r2_hi) = SlowMath.fullMul(r, r);
assertTrue((r2_hi < x_hi) || (r2_hi == x_hi && r2_lo <= x_lo), "sqrt too high");
if (r == type(uint256).max) {
assertTrue(
x_hi > 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
|| (x_hi == 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe && x_lo != 0),
"sqrt too low (overflow)"
);
} else {
r++;
(r2_lo, r2_hi) = SlowMath.fullMul(r, r);
assertTrue((r2_hi > x_hi) || (r2_hi == x_hi && r2_lo > x_lo), "sqrt too low");
}
}
function test512Math_divUpAlt(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external view {
vm.assume(y_hi != 0);
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
uint256 ceil_q = x.divUpAlt(y);
uint256 floor_q = x.div(y);
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(y_lo, y_hi, floor_q, 0);
uint512 e = alloc().from(e_hi, e_lo);
assertTrue(
ceil_q == floor_q || (floor_q == type(uint256).max && ceil_q == 0) || (e != x && ceil_q == floor_q + 1)
);
}
function test512Math_odivUpAlt(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external view {
vm.assume(y_hi != 0);
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
uint512 ceil_q = alloc().odivUpAlt(x, y);
uint512 floor_q = alloc().odiv(x, y);
(uint256 floor_q_hi, uint256 floor_q_lo) = floor_q.into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(y_lo, y_hi, floor_q_lo, floor_q_hi);
uint512 e = alloc().from(e_hi, e_lo);
assertTrue(
ceil_q == floor_q
|| (floor_q == tmp().from(type(uint256).max, type(uint256).max) && ceil_q == tmp().from(0, 0))
|| (e != x && ceil_q == tmp().oadd(floor_q, 1))
);
}
function test512Math_divUpForeign(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
vm.assume(y != 0);
uint512 x = alloc().from(x_hi, x_lo);
uint256 ceil_q = x.divUp(y);
uint256 floor_q = x.div(y);
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(y, floor_q);
uint512 e = alloc().from(e_hi, e_lo);
assertTrue(
ceil_q == floor_q || (floor_q == type(uint256).max && ceil_q == 0) || (e != x && ceil_q == floor_q + 1)
);
}
function test512Math_divUpNative(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external view {
vm.assume(y_hi != 0);
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
uint256 ceil_q = x.divUp(y);
uint256 floor_q = x.div(y);
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(y_lo, y_hi, floor_q, 0);
uint512 e = alloc().from(e_hi, e_lo);
assertTrue(
ceil_q == floor_q || (floor_q == type(uint256).max && ceil_q == 0) || (e != x && ceil_q == floor_q + 1)
);
}
function test512Math_odivUpForeign(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
vm.assume(y != 0);
uint512 x = alloc().from(x_hi, x_lo);
uint512 ceil_q = alloc().odivUp(x, y);
uint512 floor_q = alloc().odiv(x, y);
(uint256 floor_q_hi, uint256 floor_q_lo) = floor_q.into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(y, 0, floor_q_lo, floor_q_hi);
uint512 e = alloc().from(e_hi, e_lo);
assertTrue(
ceil_q == floor_q
|| (floor_q == tmp().from(type(uint256).max, type(uint256).max) && ceil_q == tmp().from(0, 0))
|| (e != x && ceil_q == tmp().oadd(floor_q, 1))
);
}
function test512Math_idivUpForeign(uint256 x_hi, uint256 x_lo, uint256 y) external pure {
vm.assume(y != 0);
uint512 x = alloc().from(x_hi, x_lo);
(uint256 ceil_q_hi, uint256 ceil_q_lo) = tmp().from(x).idivUp(y).into();
(uint256 floor_q_hi, uint256 floor_q_lo) = tmp().from(x).idiv(y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(y, 0, floor_q_lo, floor_q_hi);
uint512 e = alloc().from(e_hi, e_lo);
uint512 ceil_q = alloc().from(ceil_q_hi, ceil_q_lo);
uint512 floor_q = alloc().from(floor_q_hi, floor_q_lo);
assertTrue(
ceil_q == floor_q
|| (floor_q == tmp().from(type(uint256).max, type(uint256).max) && ceil_q == tmp().from(0, 0))
|| (e != x && ceil_q == tmp().oadd(floor_q, 1))
);
}
function test512Math_odivUpNative(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external view {
vm.assume(y_hi != 0);
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
uint512 ceil_q = alloc().odivUp(x, y);
uint512 floor_q = alloc().odiv(x, y);
(uint256 floor_q_hi, uint256 floor_q_lo) = floor_q.into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(y_lo, y_hi, floor_q_lo, floor_q_hi);
uint512 e = alloc().from(e_hi, e_lo);
assertTrue(
ceil_q == floor_q
|| (floor_q == tmp().from(type(uint256).max, type(uint256).max) && ceil_q == tmp().from(0, 0))
|| (e != x && ceil_q == tmp().oadd(floor_q, 1))
);
}
function test512Math_idivUpNative(uint256 x_hi, uint256 x_lo, uint256 y_hi, uint256 y_lo) external view {
vm.assume(y_hi != 0);
uint512 x = alloc().from(x_hi, x_lo);
uint512 y = alloc().from(y_hi, y_lo);
(uint256 ceil_q_hi, uint256 ceil_q_lo) = tmp().from(x).idivUp(y).into();
(uint256 floor_q_hi, uint256 floor_q_lo) = tmp().from(x).idiv(y).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullMul(y_lo, y_hi, floor_q_lo, floor_q_hi);
uint512 e = alloc().from(e_hi, e_lo);
uint512 ceil_q = alloc().from(ceil_q_hi, ceil_q_lo);
uint512 floor_q = alloc().from(floor_q_hi, floor_q_lo);
assertTrue(
ceil_q == floor_q
|| (floor_q == tmp().from(type(uint256).max, type(uint256).max) && ceil_q == tmp().from(0, 0))
|| (e != x && ceil_q == tmp().oadd(floor_q, 1))
);
}
function test512Math_osqrtUp(uint256 x_hi, uint256 x_lo) external pure {
uint512 x = alloc().from(x_hi, x_lo);
(uint256 r_hi, uint256 r_lo) = alloc().osqrtUp(x).into();
if (r_hi == 0 && r_lo == 0) {
// sqrtUp(0) = 0
assertTrue(x_hi == 0 && x_lo == 0, "sqrtUp of nonzero is zero");
} else if (r_hi != 0) {
// r >= 2^256, which means r must be exactly 2^256 (since sqrt of 512-bit is at most 2^256)
// r^2 = 2^512 exceeds max 512-bit value, so r^2 >= x is trivially true
// We only need to verify (r-1)^2 < x, i.e., (type(uint256).max)^2 < x
assertTrue(r_hi == 1 && r_lo == 0, "overflow result must be exactly 2^256");
(uint256 r_dec2_lo, uint256 r_dec2_hi) = SlowMath.fullMul(type(uint256).max, type(uint256).max);
assertTrue((r_dec2_hi < x_hi) || (r_dec2_hi == x_hi && r_dec2_lo < x_lo), "sqrtUp too high");
} else {
// Normal case: r fits in 256 bits
(uint256 r2_lo, uint256 r2_hi) = SlowMath.fullMul(r_lo, r_lo);
assertTrue((r2_hi > x_hi) || (r2_hi == x_hi && r2_lo >= x_lo), "sqrtUp too low");
// Check (r-1)^2 < x
if (r_lo == 1) {
// (r-1)^2 = 0, which must be less than any nonzero x. Already verified x != 0
// since we're in the r != 0 branch.
} else {
uint256 r_dec_lo = r_lo - 1;
(r2_lo, r2_hi) = SlowMath.fullMul(r_dec_lo, r_dec_lo);
assertTrue((r2_hi < x_hi) || (r2_hi == x_hi && r2_lo < x_lo), "sqrtUp too high");
}
}
}
function test512Math_sqrt_perfectSquare(uint256 r) external pure {
uint512 x = alloc().omul(r, r);
assertEq(x.sqrt(), r);
}
function test512Math_osqrtUp_perfectSquare(uint256 r) external pure {
uint512 x = alloc().omul(r, r);
(uint256 r_hi, uint256 r_lo) = alloc().osqrtUp(x).into();
assertEq(r_hi, 0);
assertEq(r_lo, r);
}
function test512Math_oshrUp(uint256 x_hi, uint256 x_lo, uint256 s) external pure {
s = bound(s, 0, 512);
uint512 x = alloc().from(x_hi, x_lo);
(uint256 r_hi, uint256 r_lo) = tmp().oshrUp(x, s).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullShrUp(x_lo, x_hi, s);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
function test512Math_ishrUp(uint256 x_hi, uint256 x_lo, uint256 s) external pure {
s = bound(s, 0, 512);
(uint256 r_hi, uint256 r_lo) = tmp().from(x_hi, x_lo).ishrUp(s).into();
(uint256 e_lo, uint256 e_hi) = SlowMath.fullShrUp(x_lo, x_hi, s);
assertEq(r_hi, e_hi);
assertEq(r_lo, e_lo);
}
}