-
Notifications
You must be signed in to change notification settings - Fork 0
/
bit64tests.lua
459 lines (420 loc) · 28.3 KB
/
bit64tests.lua
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
458
459
local b64 = require("bit64")
local oassert, asC = assert, 0
local function assert(...)
asC = asC + 1
return oassert(...)
end
-- Int Construction
assert(b64.fromBytes (0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0):equals(b64.newInt(0x78563412, 0xf0debc9a)))
assert(b64.fromBytesBE(0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0):equals(b64.newInt(0x9abcdef0, 0x12345678)))
-- Addition
assert(b64.one() :add(b64.one() ):equals(b64.newInt(2) ))
assert(b64.one() :add(b64.zero() ):equals(b64.one() ))
assert(b64.negOne():add(b64.negOne()):equals(b64.newInt(2):arInverse()))
assert(b64.negOne():add(b64.one() ):equals(b64.zero() ))
assert(b64.newInt(0xFFFFFFFF, 0x7FFFFFFF):add(b64.one() ):equals(b64.newInt(0 , 0x80000000)))
assert(b64.newInt(0 , 0x80000000):add(b64.negOne()):equals(b64.newInt(0xFFFFFFFF, 0x7FFFFFFF)))
assert(b64.newInt(0, 0x80000000):add(b64.newInt(0, 0x80000000)):equals(b64.zero()))
assert(b64.newInt( 0x3fffffff):add(b64.one()) :equals(b64.newInt(0x40000000)))
assert(b64.newInt(0, 0x80000000):arInverse():equals(assert(b64.newInt(0, 0x80000000))))
-- Subtraction
assert(b64.one():sub(b64.one()):equals(b64.zero()))
assert(b64.one():sub(b64.zero()):equals(b64.one()))
assert(b64.negOne():sub(b64.negOne()):equals(b64.zero()))
assert(b64.newInt(0xffffffff, 0x7fffffff):sub(b64.negOne()):equals(b64.newInt(0, 0x80000000)))
assert(b64.newInt(0, 0x80000000):sub(b64.one()):equals(b64.newInt(0xffffffff, 0x7fffffff)))
assert(b64.newInt(0, 0x80000000):sub(b64.newInt(0, 0x80000000)):equals(b64.zero()))
assert(b64.newInt(0x3fffffff):sub(b64.negOne()):equals(b64.newInt(0x40000000)))
-- Multiplication
assert(b64.one() :mult(b64.one()) :equals(b64.one()))
assert(b64.one() :mult(b64.zero()) :equals(b64.zero()))
assert(b64.negOne():mult(b64.negOne()):equals(b64.one()))
assert(b64.newInt(0, 0x10000000):mult(b64.newInt(4096)):equals(b64.zero()))
assert(b64.newInt(0, 0x80000000):mult(b64.newInt(0)):equals(b64.zero()))
assert(b64.newInt(0, 0x80000000):mult(b64.negOne()):equals(b64.newInt(0, 0x80000000)))
assert(b64.newInt(0xffffffff, 0x7fffffff):mult(b64.negOne()):equals(b64.newInt(1, 0x80000000)))
assert(b64.newInt(0x89abcdef, 0x01234567):mult(b64.newInt(0x76543210, 0xfedcba98)):equals(b64.newInt(0xe5618cf0, 0x2236d88f)))
assert(b64.newInt(0xffffffff, 0x7fffffff):mult(b64.newInt(0xffffffff, 0x7fffffff)):equals(b64.one()))
-- Unsigned Division
assert(b64.newInt(1):div_u(b64.newInt(1)):equals(b64.newInt(1)))
assert(b64.newInt(0):div_u(b64.newInt(1)):equals(b64.newInt(0)))
assert(b64.newInt(0x00000000, 0x80000000):div_u(b64.negOne()):equals(b64.newInt(0)))
assert(b64.newInt(0x00000000, 0x80000000):div_u(b64.newInt(2)):equals(b64.newInt(0x00000000, 0x40000000)))
assert(b64.newInt(0x0ff00ff0, 0x8ff00ff0):div_u(b64.newInt(0x00000001, 0x1)):equals(b64.newInt(0x8ff00fef)))
assert(b64.newInt(0x00000001, 0x80000000):div_u(b64.newInt(1000)):equals(b64.newInt(0xa5e353f7, 0x20c49b)))
assert(b64.newInt(5):div_u(b64.newInt(2)):equals(b64.newInt(2)))
assert(b64.newInt(5):arInverse():div_u(b64.newInt(2)):equals(b64.newInt(0xfffffffd, 0x7fffffff)))
assert(b64.newInt(5):div_u(b64.newInt(2):arInverse()):equals(b64.newInt(0)))
assert(b64.newInt(5):arInverse():div_u(b64.newInt(2):arInverse()):equals(b64.newInt(0)))
assert(b64.newInt(7):div_u(b64.newInt(3)):equals(b64.newInt(2)))
assert(b64.newInt(11):div_u(b64.newInt(5)):equals(b64.newInt(2)))
assert(b64.newInt(17):div_u(b64.newInt(7)):equals(b64.newInt(2)))
assert(b64.negOne():div_u(b64.negOne()):equals(b64.newInt(1)))
-- Signed Division
assert(b64.newInt(1):div_s(b64.newInt(1)):equals(b64.newInt(1)))
assert(b64.newInt(0):div_s(b64.newInt(1)):equals(b64.newInt(0)))
assert(b64.newInt(0):div_s(b64.negOne()):equals(b64.newInt(0)))
assert(b64.negOne():div_s(b64.negOne()):equals(b64.newInt(1)))
assert(b64.newInt(0x00000000, 0x80000000):div_s(b64.newInt(2)):equals(b64.newInt(0x00000000, 0xc0000000)))
assert(b64.newInt(0x00000001, 0x80000000):div_s(b64.newInt(1000)):equals(b64.newInt(0x5a1cac09, 0xffdf3b64)))
assert(b64.newInt(5):div_s(b64.newInt(2)):equals(b64.newInt(2)))
assert(b64.newInt(5):arInverse():div_s(b64.newInt(2)):equals(b64.newInt(2):arInverse()))
assert(b64.newInt(5):div_s(b64.newInt(2):arInverse()):equals(b64.newInt(2):arInverse()))
assert(b64.newInt(5):arInverse():div_s(b64.newInt(2):arInverse()):equals(b64.newInt(2)))
assert(b64.newInt(7):div_s(b64.newInt(3)):equals(b64.newInt(2)))
assert(b64.newInt(7):arInverse():div_s(b64.newInt(3)):equals(b64.newInt(2):arInverse()))
assert(b64.newInt(7):div_s(b64.newInt(3):arInverse()):equals(b64.newInt(2):arInverse()))
assert(b64.newInt(7):arInverse():div_s(b64.newInt(3):arInverse()):equals(b64.newInt(2)))
assert(b64.newInt(11):div_s(b64.newInt(5)):equals(b64.newInt(2)))
assert(b64.newInt(17):div_s(b64.newInt(7)):equals(b64.newInt(2)))
-- Division (Extras)
assert(b64.newInt(0xFF000000, 0xFF000000):dividedByU(b64.newInt(0, 0x1)) == 0xFF000000)
assert(b64.newInt(0xFF000000, 0xFF000000):dividedByU(b64.newInt(0, 0x2)) == 0x7F800000)
assert(b64.newInt(0xFF000000, 0xFF000000):dividedByU(b64.newInt(0, 0x10)) == 0xFF00000)
-- Signed Modular Division
assert(b64.newInt(0xffffffff, 0x7fffffff):rem_s(b64.negOne()):equals(b64.newInt(0)))
assert(b64.newInt(1):rem_s(b64.newInt(1)):equals(b64.newInt(0)))
assert(b64.newInt(0):rem_s(b64.newInt(1)):equals(b64.newInt(0)))
assert(b64.newInt(0):rem_s(b64.negOne()):equals(b64.newInt(0)))
assert(b64.negOne():rem_s(b64.negOne()):equals(b64.newInt(0)))
assert(b64.newInt(0x00000000, 0x80000000):rem_s(b64.negOne()):equals(b64.newInt(0)))
assert(b64.newInt(0x00000000, 0x80000000):rem_s(b64.newInt(2)):equals(b64.newInt(0)))
assert(b64.newInt(0x00000001, 0x80000000):rem_s(b64.newInt(1000)):equals(b64.newInt(807):arInverse()))
assert(b64.newInt(5):rem_s(b64.newInt(2)):equals(b64.newInt(1)))
assert(b64.newInt(5):arInverse():rem_s(b64.newInt(2)):equals(b64.negOne()))
assert(b64.newInt(5):rem_s(b64.newInt(2):arInverse()):equals(b64.newInt(1)))
assert(b64.newInt(5):arInverse():rem_s(b64.newInt(2):arInverse()):equals(b64.negOne()))
assert(b64.newInt(7):rem_s(b64.newInt(3)):equals(b64.newInt(1)))
assert(b64.newInt(7):arInverse():rem_s(b64.newInt(3)):equals(b64.negOne()))
assert(b64.newInt(7):rem_s(b64.newInt(3):arInverse()):equals(b64.newInt(1)))
assert(b64.newInt(7):arInverse():rem_s(b64.newInt(3):arInverse()):equals(b64.negOne()))
assert(b64.newInt(11):rem_s(b64.newInt(5)):equals(b64.newInt(1)))
assert(b64.newInt(17):rem_s(b64.newInt(7)):equals(b64.newInt(3)))
-- Unsigned Modular Division
assert(b64.newInt(1):rem_u(b64.newInt(1)):equals(b64.newInt(0)))
assert(b64.newInt(0):rem_u(b64.newInt(1)):equals(b64.newInt(0)))
assert(b64.negOne():rem_u(b64.negOne()):equals(b64.newInt(0)))
assert(b64.newInt(0x00000000, 0x80000000):rem_u(b64.negOne()):equals(b64.newInt(0x00000000, 0x80000000)))
assert(b64.newInt(0x00000000, 0x80000000):rem_u(b64.newInt(2)):equals(b64.newInt(0)))
assert(b64.newInt(0x0ff00ff0, 0x8ff00ff0):rem_u(b64.newInt(0x00000001, 0x1)):equals(b64.newInt(0x80000001)))
assert(b64.newInt(0x00000001, 0x80000000):rem_u(b64.newInt(1000)):equals(b64.newInt(809)))
assert(b64.newInt(5):rem_u(b64.newInt(2)):equals(b64.newInt(1)))
assert(b64.newInt(5):arInverse():rem_u(b64.newInt(2)):equals(b64.newInt(1)))
assert(b64.newInt(5):rem_u(b64.newInt(2):arInverse()):equals(b64.newInt(5)))
assert(b64.newInt(5):arInverse():rem_u(b64.newInt(2):arInverse()):equals(b64.newInt(5):arInverse()))
assert(b64.newInt(7):rem_u(b64.newInt(3)):equals(b64.newInt(1)))
assert(b64.newInt(11):rem_u(b64.newInt(5)):equals(b64.newInt(1)))
assert(b64.newInt(17):rem_u(b64.newInt(7)):equals(b64.newInt(3)))
-- Left Shift
assert(b64.newInt(1):shl(b64.newInt(1)):equals(b64.newInt(2)))
assert(b64.newInt(1):shl(b64.newInt(0)):equals(b64.newInt(1)))
assert(b64.newInt(0xffffffff, 0x7fffffff):shl(b64.newInt(1)):equals(b64.newInt(0xfffffffe, 0xffffffff)))
assert(b64.newInt(0xffffffff, 0xffffffff):shl(b64.newInt(1)):equals(b64.newInt(0xfffffffe, 0xffffffff)))
assert(b64.newInt(0x00000000, 0x80000000):shl(b64.newInt(1)):equals(b64.newInt(0)))
assert(b64.newInt(0x00000000, 0x40000000):shl(b64.newInt(1)):equals(b64.newInt(0x00000000, 0x80000000)))
assert(b64.newInt(1):shl(b64.newInt(63)):equals(b64.newInt(0x00000000, 0x80000000)))
assert(b64.newInt(1):shl(b64.newInt(64)):equals(b64.newInt(1)))
assert(b64.newInt(1):shl(b64.newInt(65)):equals(b64.newInt(2)))
assert(b64.newInt(1):shl(b64.negOne()):equals(b64.newInt(0x00000000, 0x80000000)))
assert(b64.newInt(1):shl(b64.newInt(0xffffffff, 0x7fffffff)):equals(b64.newInt(0x00000000, 0x80000000)))
-- Unsigned Right Shift
assert(b64.newInt(1):shr_u(b64.newInt(1)):equals(b64.newInt(0)))
assert(b64.newInt(1):shr_u(b64.newInt(0)):equals(b64.newInt(1)))
assert(b64.negOne():shr_u(b64.newInt(1)):equals(b64.newInt(0xffffffff, 0x7fffffff)))
assert(b64.newInt(0xffffffff, 0x7fffffff):shr_u(b64.newInt(1)):equals(b64.newInt(0xffffffff, 0x3fffffff)))
assert(b64.newInt(0x00000000, 0x80000000):shr_u(b64.newInt(1)):equals(b64.newInt(0x00000000, 0x40000000)))
assert(b64.newInt(0x00000000, 0x40000000):shr_u(b64.newInt(1)):equals(b64.newInt(0x00000000, 0x20000000)))
assert(b64.newInt(1):shr_u(b64.newInt(64)):equals(b64.newInt(1)))
assert(b64.newInt(1):shr_u(b64.newInt(65)):equals(b64.newInt(0)))
assert(b64.newInt(1):shr_u(b64.negOne()):equals(b64.newInt(0)))
assert(b64.newInt(1):shr_u(b64.newInt(0xffffffff, 0x7fffffff)):equals(b64.newInt(0)))
assert(b64.newInt(1):shr_u(b64.newInt(0x00000000, 0x80000000)):equals(b64.newInt(1)))
assert(b64.newInt(0x00000000, 0x80000000):shr_u(b64.newInt(63)):equals(b64.newInt(1)))
assert(b64.negOne():shr_u(b64.newInt(64)):equals(b64.negOne()))
assert(b64.negOne():shr_u(b64.newInt(65)):equals(b64.newInt(0xffffffff, 0x7fffffff)))
assert(b64.negOne():shr_u(b64.negOne()):equals(b64.newInt(1)))
assert(b64.negOne():shr_u(b64.newInt(0xffffffff, 0x7fffffff)):equals(b64.newInt(1)))
assert(b64.negOne():shr_u(b64.newInt(0x00000000, 0x80000000)):equals(b64.negOne()))
-- Signed Right Shift
assert(b64.newInt(1):shr_s(b64.newInt(1)):equals(b64.newInt(0)))
assert(b64.newInt(1):shr_s(b64.newInt(0)):equals(b64.newInt(1)))
assert(b64.negOne():shr_s(b64.newInt(1)):equals(b64.negOne()))
assert(b64.newInt(0xffffffff, 0x7fffffff):shr_s(b64.newInt(1)):equals(b64.newInt(0xffffffff, 0x3fffffff)))
assert(b64.newInt(0x00000000, 0x80000000):shr_s(b64.newInt(1)):equals(b64.newInt(0x00000000, 0xc0000000)))
assert(b64.newInt(0x00000000, 0x40000000):shr_s(b64.newInt(1)):equals(b64.newInt(0x00000000, 0x20000000)))
assert(b64.newInt(1):shr_s(b64.newInt(64)):equals(b64.newInt(1)))
assert(b64.newInt(1):shr_s(b64.newInt(65)):equals(b64.newInt(0)))
assert(b64.newInt(1):shr_s(b64.negOne()):equals(b64.newInt(0)))
assert(b64.newInt(1):shr_s(b64.newInt(0xffffffff, 0x7fffffff)):equals(b64.newInt(0)))
assert(b64.newInt(1):shr_s(b64.newInt(0x00000000, 0x80000000)):equals(b64.newInt(1)))
assert(b64.newInt(0x00000000, 0x80000000):shr_s(b64.newInt(63)):equals(b64.negOne()))
assert(b64.newInt(0x00000000, 0x80000000):shr_s(b64.newInt(50)):equals(b64.newInt(0xffffe000, 0xffffffff)))
assert(b64.negOne():shr_s(b64.newInt(64)):equals(b64.negOne()))
assert(b64.negOne():shr_s(b64.newInt(65)):equals(b64.negOne()))
assert(b64.negOne():shr_s(b64.negOne()):equals(b64.negOne()))
assert(b64.negOne():shr_s(b64.newInt(0xffffffff, 0x7fffffff)):equals(b64.negOne()))
assert(b64.negOne():shr_s(b64.newInt(0x00000000, 0x80000000)):equals(b64.negOne()))
-- Binary AND
assert(b64.newInt(1):banded(b64.newInt(0)):equals(b64.newInt(0)))
assert(b64.newInt(0):banded(b64.newInt(1)):equals(b64.newInt(0)))
assert(b64.newInt(1):banded(b64.newInt(1)):equals(b64.newInt(1)))
assert(b64.newInt(0):banded(b64.newInt(0)):equals(b64.newInt(0)))
assert(b64.newInt(0xffffffff, 0x7fffffff):banded(b64.newInt(0x00000000, 0x80000000)):equals(b64.newInt(0)))
assert(b64.newInt(0xffffffff, 0x7fffffff):banded(b64.negOne()):equals(b64.newInt(0xffffffff, 0x7fffffff)))
assert(b64.newInt(0xf0f0ffff):banded(b64.newInt(0xfffff0f0)):equals(b64.newInt(0xf0f0f0f0)))
assert(b64.newInt(0xffffffff, 0xffffffff):banded(b64.newInt(0xffffffff, 0xffffffff)):equals(b64.newInt(0xffffffff, 0xffffffff)))
-- Binary OR
assert(b64.newInt(1):bored(b64.newInt(0)):equals(b64.newInt(1)))
assert(b64.newInt(0):bored(b64.newInt(1)):equals(b64.newInt(1)))
assert(b64.newInt(1):bored(b64.newInt(1)):equals(b64.newInt(1)))
assert(b64.newInt(0):bored(b64.newInt(0)):equals(b64.newInt(0)))
assert(b64.newInt(0xffffffff, 0x7fffffff):bored(b64.newInt(0x00000000, 0x80000000)):equals(b64.negOne()))
assert(b64.newInt(0x00000000, 0x80000000):bored(b64.newInt(0)):equals(b64.newInt(0x00000000, 0x80000000)))
assert(b64.newInt(0xf0f0ffff):bored(b64.newInt(0xfffff0f0)):equals(b64.newInt(0xffffffff)))
assert(b64.newInt(0xffffffff, 0xffffffff):bored(b64.newInt(0xffffffff, 0xffffffff)):equals(b64.newInt(0xffffffff, 0xffffffff)))
-- Binary XOR
assert(b64.newInt(1):bxored(b64.newInt(0)):equals(b64.newInt(1)))
assert(b64.newInt(0):bxored(b64.newInt(1)):equals(b64.newInt(1)))
assert(b64.newInt(1):bxored(b64.newInt(1)):equals(b64.newInt(0)))
assert(b64.newInt(0):bxored(b64.newInt(0)):equals(b64.newInt(0)))
assert(b64.newInt(0xffffffff, 0x7fffffff):bxored(b64.newInt(0x00000000, 0x80000000)):equals(b64.negOne()))
assert(b64.newInt(0x00000000, 0x80000000):bxored(b64.newInt(0)):equals(b64.newInt(0x00000000, 0x80000000)))
assert(b64.negOne():bxored(b64.newInt(0x00000000, 0x80000000)):equals(b64.newInt(0xffffffff, 0x7fffffff)))
assert(b64.negOne():bxored(b64.newInt(0xffffffff, 0x7fffffff)):equals(b64.newInt(0x00000000, 0x80000000)))
assert(b64.newInt(0xf0f0ffff):bxored(b64.newInt(0xfffff0f0)):equals(b64.newInt(0x0f0f0f0f)))
assert(b64.newInt(0xffffffff, 0xffffffff):bxored(b64.newInt(0xffffffff, 0xffffffff)):equals(b64.newInt(0)))
-- Rotate Bits Left
assert(b64.newInt(1):rotl(b64.newInt(1)):equals(b64.newInt(2)))
assert(b64.newInt(1):rotl(b64.newInt(0)):equals(b64.newInt(1)))
assert(b64.negOne():rotl(b64.newInt(1)):equals(b64.negOne()))
assert(b64.newInt(1):rotl(b64.newInt(64)):equals(b64.newInt(1)))
assert(b64.newInt(0x02468ace, 0xabcd9876):rotl(b64.newInt(1)):equals(b64.newInt(0x048d159d, 0x579b30ec)))
assert(b64.newInt(0xdc000000, 0xfe000000):rotl(b64.newInt(4)):equals(b64.newInt(0xc000000f, 0xe000000d)))
assert(b64.newInt(0xef567809, 0xabcd1234):rotl(b64.newInt(53)):equals(b64.newInt(0x469deacf, 0x013579a2)))
assert(b64.newInt(0xf567809c, 0xabd1234e):rotl(b64.newInt(63)):equals(b64.newInt(0x7ab3c04e, 0x55e891a7)))
assert(b64.newInt(0xef567809, 0xabcd1234):rotl(b64.newInt(0xf5)):equals(b64.newInt(0x469deacf, 0x013579a2)))
assert(b64.newInt(0xef567809, 0xabcd7294):rotl(b64.newInt(0xffffffed, 0xffffffff)):equals(b64.newInt(0xae529dea, 0xcf013579)))
assert(b64.newInt(0xf567809c, 0xabd1234e):rotl(b64.newInt(0x0000003f, 0x80000000)):equals(b64.newInt(0x7ab3c04e, 0x55e891a7)))
assert(b64.newInt(1):rotl(b64.newInt(63)):equals(b64.newInt(0x00000000, 0x80000000)))
assert(b64.newInt(0x00000000, 0x80000000):rotl(b64.newInt(1)):equals(b64.newInt(1)))
-- Rotate Bits Right
assert(b64.newInt(1):rotr(b64.newInt(1)):equals(b64.newInt(0x00000000, 0x80000000)))
assert(b64.newInt(1):rotr(b64.newInt(0)):equals(b64.newInt(1)))
assert(b64.negOne():rotr(b64.newInt(1)):equals(b64.negOne()))
assert(b64.newInt(1):rotr(b64.newInt(64)):equals(b64.newInt(1)))
assert(b64.newInt(0x02468ace, 0xabcd9876):rotr(b64.newInt(1)):equals(b64.newInt(0x01234567, 0x55e6cc3b)))
assert(b64.newInt(0xdc000000, 0xfe000000):rotr(b64.newInt(4)):equals(b64.newInt(0x0dc00000, 0x0fe00000)))
assert(b64.newInt(0xef567809, 0xabcd1234):rotr(b64.newInt(53)):equals(b64.newInt(0xb3c04d5e, 0x6891a77a)))
assert(b64.newInt(0xf567809c, 0xabd1234e):rotr(b64.newInt(63)):equals(b64.newInt(0xeacf0139, 0x57a2469d)))
assert(b64.newInt(0xef567809, 0xabcd1234):rotr(b64.newInt(0xf5)):equals(b64.newInt(0xb3c04d5e, 0x6891a77a)))
assert(b64.newInt(0xef567809, 0xabcd7294):rotr(b64.newInt(0xffffffed, 0xffffffff)):equals(b64.newInt(0xc04d5e6b, 0x94a77ab3)))
assert(b64.newInt(0xf567809c, 0xabd1234e):rotr(b64.newInt(0x0000003f, 0x80000000)):equals(b64.newInt(0xeacf0139, 0x57a2469d)))
assert(b64.newInt(1):rotr(b64.newInt(63)):equals(b64.newInt(2)))
assert(b64.newInt(0x00000000, 0x80000000):rotr(b64.newInt(63)):equals(b64.newInt(1)))
-- Count Leading Zeros
assert(b64.newInt(0xffffffff, 0xffffffff):clz():equals(b64.newInt(0)))
assert(b64.newInt(0):clz():equals(b64.newInt(64)))
assert(b64.newInt(0x00008000):clz():equals(b64.newInt(48)))
assert(b64.newInt(0xff):clz():equals(b64.newInt(56)))
assert(b64.newInt(0x00000000, 0x80000000):clz():equals(b64.newInt(0)))
assert(b64.newInt(1):clz():equals(b64.newInt(63)))
assert(b64.newInt(2):clz():equals(b64.newInt(62)))
assert(b64.newInt(0xffffffff, 0x7fffffff):clz():equals(b64.newInt(1)))
-- Count Trailing Zeros
assert(b64.negOne():ctz():equals(b64.newInt(0)))
assert(b64.newInt(0):ctz():equals(b64.newInt(64)))
assert(b64.newInt(0x00008000):ctz():equals(b64.newInt(15)))
assert(b64.newInt(0x00010000):ctz():equals(b64.newInt(16)))
assert(b64.newInt(0x00000000, 0x80000000):ctz():equals(b64.newInt(63)))
assert(b64.newInt(0xffffffff, 0x7fffffff):ctz():equals(b64.newInt(0)))
-- Count Set Bits
assert(b64.negOne():popcnt():equals(b64.newInt(64)))
assert(b64.newInt(0):popcnt():equals(b64.newInt(0)))
assert(b64.newInt(0x00008000):popcnt():equals(b64.newInt(1)))
assert(b64.newInt(0x80008000, 0x80008000):popcnt():equals(b64.newInt(4)))
assert(b64.newInt(0xffffffff, 0x7fffffff):popcnt():equals(b64.newInt(63)))
assert(b64.newInt(0x55555555, 0xAAAAAAAA):popcnt():equals(b64.newInt(32)))
assert(b64.newInt(0xAAAAAAAA, 0x99999999):popcnt():equals(b64.newInt(32)))
assert(b64.newInt(0xDEADBEEF, 0xDEADBEEF):popcnt():equals(b64.newInt(48)))
-- Equals Zero
assert(b64.newInt(0):eqz() == 1)
assert(b64.newInt(1):eqz() == 0)
assert(b64.newInt(0x00000000, 0x80000000):eqz() == 0)
assert(b64.newInt(0xffffffff, 0x7fffffff):eqz() == 0)
assert(b64.newInt(0xffffffff, 0xffffffff):eqz() == 0)
-- Equals
assert(b64.newInt(0):eq(b64.newInt(0)) == 1)
assert(b64.newInt(1):eq(b64.newInt(1)) == 1)
assert(b64.negOne():eq(b64.newInt(1)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):eq(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0xffffffff, 0x7fffffff):eq(b64.newInt(0xffffffff, 0x7fffffff)) == 1)
assert(b64.negOne():eq(b64.negOne()) == 1)
assert(b64.newInt(1):eq(b64.newInt(0)) == 0)
assert(b64.newInt(0):eq(b64.newInt(1)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):eq(b64.newInt(0)) == 0)
assert(b64.newInt(0):eq(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):eq(b64.negOne()) == 0)
assert(b64.negOne():eq(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):eq(b64.newInt(0xffffffff, 0x7fffffff)) == 0)
assert(b64.newInt(0xffffffff, 0x7fffffff):eq(b64.newInt(0x00000000, 0x80000000)) == 0)
-- Not Equals
assert(b64.newInt(0):ne(b64.newInt(0)) == 0)
assert(b64.newInt(1):ne(b64.newInt(1)) == 0)
assert(b64.negOne():ne(b64.newInt(1)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):ne(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0xffffffff, 0x7fffffff):ne(b64.newInt(0xffffffff, 0x7fffffff)) == 0)
assert(b64.negOne():ne(b64.negOne()) == 0)
assert(b64.newInt(1):ne(b64.newInt(0)) == 1)
assert(b64.newInt(0):ne(b64.newInt(1)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):ne(b64.newInt(0)) == 1)
assert(b64.newInt(0):ne(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):ne(b64.negOne()) == 1)
assert(b64.negOne():ne(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):ne(b64.newInt(0xffffffff, 0x7fffffff)) == 1)
assert(b64.newInt(0xffffffff, 0x7fffffff):ne(b64.newInt(0x00000000, 0x80000000)) == 1)
-- Less-than Signed
assert(b64.newInt(0):lt_s(b64.newInt(0)) == 0)
assert(b64.newInt(1):lt_s(b64.newInt(1)) == 0)
assert(b64.negOne():lt_s(b64.newInt(1)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):lt_s(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0xffffffff, 0x7fffffff):lt_s(b64.newInt(0xffffffff, 0x7fffffff)) == 0)
assert(b64.negOne():lt_s(b64.negOne()) == 0)
assert(b64.newInt(1):lt_s(b64.newInt(0)) == 0)
assert(b64.newInt(0):lt_s(b64.newInt(1)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):lt_s(b64.newInt(0)) == 1)
assert(b64.newInt(0):lt_s(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):lt_s(b64.negOne()) == 1)
assert(b64.negOne():lt_s(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):lt_s(b64.newInt(0xffffffff, 0x7fffffff)) == 1)
assert(b64.newInt(0xffffffff, 0x7fffffff):lt_s(b64.newInt(0x00000000, 0x80000000)) == 0)
-- Less-than or equal to Signed
assert(b64.newInt(0):le_s(b64.newInt(0)) == 1)
assert(b64.newInt(1):le_s(b64.newInt(1)) == 1)
assert(b64.negOne():le_s(b64.newInt(1)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):le_s(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0xffffffff, 0x7fffffff):le_s(b64.newInt(0xffffffff, 0x7fffffff)) == 1)
assert(b64.negOne():le_s(b64.negOne()) == 1)
assert(b64.newInt(1):le_s(b64.newInt(0)) == 0)
assert(b64.newInt(0):le_s(b64.newInt(1)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):le_s(b64.newInt(0)) == 1)
assert(b64.newInt(0):le_s(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):le_s(b64.negOne()) == 1)
assert(b64.negOne():le_s(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):le_s(b64.newInt(0xffffffff, 0x7fffffff)) == 1)
assert(b64.newInt(0xffffffff, 0x7fffffff):le_s(b64.newInt(0x00000000, 0x80000000)) == 0)
-- Greater-than Signed
assert(b64.newInt(0):gt_s(b64.newInt(0)) == 0)
assert(b64.newInt(1):gt_s(b64.newInt(1)) == 0)
assert(b64.negOne():gt_s(b64.newInt(1)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):gt_s(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0xffffffff, 0x7fffffff):gt_s(b64.newInt(0xffffffff, 0x7fffffff)) == 0)
assert(b64.negOne():gt_s(b64.negOne()) == 0)
assert(b64.newInt(1):gt_s(b64.newInt(0)) == 1)
assert(b64.newInt(0):gt_s(b64.newInt(1)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):gt_s(b64.newInt(0)) == 0)
assert(b64.newInt(0):gt_s(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):gt_s(b64.negOne()) == 0)
assert(b64.negOne():gt_s(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):gt_s(b64.newInt(0xffffffff, 0x7fffffff)) == 0)
assert(b64.newInt(0xffffffff, 0x7fffffff):gt_s(b64.newInt(0x00000000, 0x80000000)) == 1)
-- Greater-than or equal to Signed
assert(b64.newInt(0):ge_s(b64.newInt(0)) == 1)
assert(b64.newInt(1):ge_s(b64.newInt(1)) == 1)
assert(b64.negOne():ge_s(b64.newInt(1)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):ge_s(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0xffffffff, 0x7fffffff):ge_s(b64.newInt(0xffffffff, 0x7fffffff)) == 1)
assert(b64.negOne():ge_s(b64.negOne()) == 1)
assert(b64.newInt(1):ge_s(b64.newInt(0)) == 1)
assert(b64.newInt(0):ge_s(b64.newInt(1)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):ge_s(b64.newInt(0)) == 0)
assert(b64.newInt(0):ge_s(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):ge_s(b64.negOne()) == 0)
assert(b64.negOne():ge_s(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):ge_s(b64.newInt(0xffffffff, 0x7fffffff)) == 0)
assert(b64.newInt(0xffffffff, 0x7fffffff):ge_s(b64.newInt(0x00000000, 0x80000000)) == 1)
-- Less-than Unsigned
assert(b64.newInt(0):lt_u(b64.newInt(0)) == 0)
assert(b64.newInt(1):lt_u(b64.newInt(1)) == 0)
assert(b64.negOne():lt_u(b64.newInt(1)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):lt_u(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0xffffffff, 0x7fffffff):lt_u(b64.newInt(0xffffffff, 0x7fffffff)) == 0)
assert(b64.negOne():lt_u(b64.negOne()) == 0)
assert(b64.newInt(1):lt_u(b64.newInt(0)) == 0)
assert(b64.newInt(0):lt_u(b64.newInt(1)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):lt_u(b64.newInt(0)) == 0)
assert(b64.newInt(0):lt_u(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):lt_u(b64.negOne()) == 1)
assert(b64.negOne():lt_u(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):lt_u(b64.newInt(0xffffffff, 0x7fffffff)) == 0)
assert(b64.newInt(0xffffffff, 0x7fffffff):lt_u(b64.newInt(0x00000000, 0x80000000)) == 1)
-- Less-than or equal to Unsigned
assert(b64.newInt(0):le_u(b64.newInt(0)) == 1)
assert(b64.newInt(1):le_u(b64.newInt(1)) == 1)
assert(b64.negOne():le_u(b64.newInt(1)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):le_u(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0xffffffff, 0x7fffffff):le_u(b64.newInt(0xffffffff, 0x7fffffff)) == 1)
assert(b64.negOne():le_u(b64.negOne()) == 1)
assert(b64.newInt(1):le_u(b64.newInt(0)) == 0)
assert(b64.newInt(0):le_u(b64.newInt(1)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):le_u(b64.newInt(0)) == 0)
assert(b64.newInt(0):le_u(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):le_u(b64.negOne()) == 1)
assert(b64.negOne():le_u(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):le_u(b64.newInt(0xffffffff, 0x7fffffff)) == 0)
assert(b64.newInt(0xffffffff, 0x7fffffff):le_u(b64.newInt(0x00000000, 0x80000000)) == 1)
-- Greater than Unsigned
assert(b64.newInt(0):gt_u(b64.newInt(0)) == 0)
assert(b64.newInt(1):gt_u(b64.newInt(1)) == 0)
assert(b64.negOne():gt_u(b64.newInt(1)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):gt_u(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0xffffffff, 0x7fffffff):gt_u(b64.newInt(0xffffffff, 0x7fffffff)) == 0)
assert(b64.negOne():gt_u(b64.negOne()) == 0)
assert(b64.newInt(1):gt_u(b64.newInt(0)) == 1)
assert(b64.newInt(0):gt_u(b64.newInt(1)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):gt_u(b64.newInt(0)) == 1)
assert(b64.newInt(0):gt_u(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):gt_u(b64.negOne()) == 0)
assert(b64.negOne():gt_u(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):gt_u(b64.newInt(0xffffffff, 0x7fffffff)) == 1)
assert(b64.newInt(0xffffffff, 0x7fffffff):gt_u(b64.newInt(0x00000000, 0x80000000)) == 0)
-- Greater than or equal to Unsigned
assert(b64.newInt(0):ge_u(b64.newInt(0)) == 1)
assert(b64.newInt(1):ge_u(b64.newInt(1)) == 1)
assert(b64.negOne():ge_u(b64.newInt(1)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):ge_u(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0xffffffff, 0x7fffffff):ge_u(b64.newInt(0xffffffff, 0x7fffffff)) == 1)
assert(b64.negOne():ge_u(b64.negOne()) == 1)
assert(b64.newInt(1):ge_u(b64.newInt(0)) == 1)
assert(b64.newInt(0):ge_u(b64.newInt(1)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):ge_u(b64.newInt(0)) == 1)
assert(b64.newInt(0):ge_u(b64.newInt(0x00000000, 0x80000000)) == 0)
assert(b64.newInt(0x00000000, 0x80000000):ge_u(b64.negOne()) == 0)
assert(b64.negOne():ge_u(b64.newInt(0x00000000, 0x80000000)) == 1)
assert(b64.newInt(0x00000000, 0x80000000):ge_u(b64.newInt(0xffffffff, 0x7fffffff)) == 1)
assert(b64.newInt(0xffffffff, 0x7fffffff):ge_u(b64.newInt(0x00000000, 0x80000000)) == 0)
-- Sign extension from lower sized types (8, 16, 32)
assert(b64.newInt(0):extend8_s():equals(b64.newInt(0)))
assert(b64.newInt(0x7f):extend8_s():equals(b64.newInt(127)))
assert(b64.newInt(0x80):extend8_s():equals(b64.newInt(128):arInverse()))
assert(b64.newInt(0xff):extend8_s():equals(b64.negOne()))
assert(b64.newInt(0x89abcd00, 0x01234567):extend8_s():equals(b64.newInt(0)))
assert(b64.newInt(0x76543280, 0xfedcba98):extend8_s():equals(b64.newInt(0x80):arInverse()))
assert(b64.negOne():extend8_s():equals(b64.negOne()))
assert(b64.newInt(0):extend16_s():equals(b64.newInt(0)))
assert(b64.newInt(0x7fff):extend16_s():equals(b64.newInt(32767)))
assert(b64.newInt(0x8000):extend16_s():equals(b64.newInt(32768):arInverse()))
assert(b64.newInt(0xffff):extend16_s():equals(b64.negOne()))
assert(b64.newInt(0x9abc0000, 0x12345678):extend16_s():equals(b64.newInt(0)))
assert(b64.newInt(0x76548000, 0xfedcba98):extend16_s():equals(b64.newInt(0x8000):arInverse()))
assert(b64.negOne():extend16_s():equals(b64.negOne()))
assert(b64.newInt(0):extend32_s():equals(b64.newInt(0)))
assert(b64.newInt(0x7fff):extend32_s():equals(b64.newInt(32767)))
assert(b64.newInt(0x8000):extend32_s():equals(b64.newInt(32768)))
assert(b64.newInt(0xffff):extend32_s():equals(b64.newInt(65535)))
assert(b64.newInt(0x7fffffff):extend32_s():equals(b64.newInt(0x7fffffff)))
assert(b64.newInt(0x80000000):extend32_s():equals(b64.newInt(0x80000000):arInverse()))
assert(b64.newInt(0xffffffff):extend32_s():equals(b64.negOne()))
assert(b64.newInt(0x00000000, 0x01234567):extend32_s():equals(b64.newInt(0)))
assert(b64.newInt(0x80000000, 0xfedcba98):extend32_s():equals(b64.newInt(0x80000000):arInverse()))
assert(b64.negOne():extend32_s():equals(b64.negOne()))
print("All (" .. asC .. ") tests passed.")