Debian Codegraph @

js/src/jit-test/tests/ion/udiv-by-constant.js

raw
1 function uint_seq(count) {
2 with({}){}
3 var arr = [];
4 var x = 0xfac83126;
5 while (count--) {
6 x ^= x << 13;
7 x ^= x >> 17;
8 x ^= x << 5;
9 // SpiderMonkey does not know how to represent UInt32, only Int32, and
10 // including any UInt32 will cause the following function to be
11 // de-optimized as double math.
12 if (x|0 > 0)
13 arr.push(x|0);
14 }
15 return arr;
16 }
17
18 function test(name, asm, ion, int) {
19 with({}){}
20 let count = 10000;
21 let seq = uint_seq(count);
22 for (let x of seq) {
23 let rint = int(x);
24 let rasm = asm(x);
25 let rion = ion(x);
26 // console.log(name, x, rint, rasm, rion);
27 assertEq(rasm, rint);
28 assertEq(rion, rint);
29 }
30 }
31
32 var asmdiv2 = (function(m) {
33 "use asm"
34 function f(x) {
35 x = x|0;
36 var z = 0;
37 z = ((x>>>0) / 2)>>>0;
38 return z|0;
39 }
40 return f;
41 })()
42
43 var plaindiv2 = function(x) {
44 x = x|0;
45 var z = 0;
46 z = ((x>>>0) / 2)>>>0;
47 return z|0;
48 }
49
50 var interpdiv2 = function(x) {
51 with({}){};
52 x = x|0;
53 var z = 0;
54 z = ((x>>>0) / 2)>>>0;
55 return z|0;
56 }
57
58 test("div2", asmdiv2, plaindiv2, interpdiv2);
59
60 var asmdiv5 = (function(m) {
61 "use asm"
62 function f(x) {
63 x = x|0;
64 var z = 0;
65 z = ((x>>>0) / 5)>>>0;
66 return z|0;
67 }
68 return f;
69 })()
70
71 var plaindiv5 = function(x) {
72 x = x|0;
73 var z = 0;
74 z = ((x>>>0) / 5)>>>0;
75 return z|0;
76 }
77
78 var interpdiv5 = function(x) {
79 with({}){};
80 x = x|0;
81 var z = 0;
82 z = ((x>>>0) / 5)>>>0;
83 return z|0;
84 }
85
86 test("div5", asmdiv5, plaindiv5, interpdiv5);
87
88 var asmdiv7 = (function(m) {
89 "use asm"
90 function f(x) {
91 x = x|0;
92 var z = 0;
93 z = ((x>>>0) / 7)>>>0;
94 return z|0;
95 }
96 return f;
97 })()
98
99 var plaindiv7 = function(x) {
100 x = x|0;
101 var z = 0;
102 z = ((x>>>0) / 7)>>>0;
103 return z|0;
104 }
105
106 var interpdiv7 = function(x) {
107 with({}){};
108 x = x|0;
109 var z = 0;
110 z = ((x>>>0) / 7)>>>0;
111 return z|0;
112 }
113
114 test("div7", asmdiv7, plaindiv7, interpdiv7);