OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
6 | 6 |
7 function WrapInAsmModule(func) { | 7 function WrapInAsmModule(func) { |
8 function MODULE_NAME(stdlib) { | 8 function MODULE_NAME(stdlib) { |
9 "use asm"; | 9 "use asm"; |
10 var imul = stdlib.Math.imul; | 10 var imul = stdlib.Math.imul; |
(...skipping 25 matching lines...) Expand all Loading... |
36 print("Testing " + asmfunc.name + " (wasm)..."); | 36 print("Testing " + asmfunc.name + " (wasm)..."); |
37 var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, stdlib); | 37 var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, stdlib); |
38 expect(wasm_module); | 38 expect(wasm_module); |
39 } | 39 } |
40 | 40 |
41 const imul = Math.imul; | 41 const imul = Math.imul; |
42 | 42 |
43 function u32_add(a, b) { | 43 function u32_add(a, b) { |
44 a = a | 0; | 44 a = a | 0; |
45 b = b | 0; | 45 b = b | 0; |
46 return +((a >>> 0) + (b >>> 0)); | 46 return +(((a >>> 0) + (b >>> 0)) >>> 0); |
47 } | 47 } |
48 | 48 |
49 function u32_sub(a, b) { | 49 function u32_sub(a, b) { |
50 a = a | 0; | 50 a = a | 0; |
51 b = b | 0; | 51 b = b | 0; |
52 return +((a >>> 0) - (b >>> 0)); | 52 return +(((a >>> 0) - (b >>> 0)) >>> 0); |
53 } | 53 } |
54 | 54 |
55 function u32_mul(a, b) { | 55 function u32_mul(a, b) { |
56 a = a | 0; | 56 a = a | 0; |
57 b = b | 0; | 57 b = b | 0; |
58 return +imul(a >>> 0, b >>> 0); | 58 return +imul(a >>> 0, b >>> 0); |
59 } | 59 } |
60 | 60 |
61 function u32_div(a, b) { | 61 function u32_div(a, b) { |
62 a = a | 0; | 62 a = a | 0; |
63 b = b | 0; | 63 b = b | 0; |
64 return ((a >>> 0) / (b >>> 0)) | 0; | 64 return +(((a >>> 0) / (b >>> 0)) >>> 0); |
65 } | 65 } |
66 | 66 |
67 function u32_mod(a, b) { | 67 function u32_mod(a, b) { |
68 a = a | 0; | 68 a = a | 0; |
69 b = b | 0; | 69 b = b | 0; |
70 return ((a >>> 0) % (b >>> 0)) | 0; | 70 return +(((a >>> 0) % (b >>> 0)) >>> 0); |
71 } | 71 } |
72 | 72 |
73 function u32_and(a, b) { | 73 function u32_and(a, b) { |
74 a = a | 0; | 74 a = a | 0; |
75 b = b | 0; | 75 b = b | 0; |
76 return +((a >>> 0) & (b >>> 0)); | 76 return +((a >>> 0) & (b >>> 0)); |
77 } | 77 } |
78 | 78 |
79 function u32_or(a, b) { | 79 function u32_or(a, b) { |
80 a = a | 0; | 80 a = a | 0; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 -10, -20, -30, -31, -32, -33, -100, -2000, | 181 -10, -20, -30, -31, -32, -33, -100, -2000, |
182 -30000, -400000, -5000000, | 182 -30000, -400000, -5000000, |
183 -100000000, -2000000000, | 183 -100000000, -2000000000, |
184 -2147483646, | 184 -2147483646, |
185 -2147483647, | 185 -2147483647, |
186 -2147483648, | 186 -2147483648, |
187 -2147483649, | 187 -2147483649, |
188 ]; | 188 ]; |
189 | 189 |
190 var funcs = [ | 190 var funcs = [ |
191 // TODO(bradnelson): u32_add, | 191 u32_add, |
192 // TODO(bradnelson): u32_sub, | 192 u32_sub, |
193 // TODO(titzer): u32_mul requires Math.imul | 193 u32_div, |
194 // TODO(titzer): u32_div by zero is incorrect | 194 u32_mod, |
195 // TODO(titzer): u32_mod by zero is incorrect | |
196 // TODO(titzer): u32_mul crashes turbofan in asm.js mode | 195 // TODO(titzer): u32_mul crashes turbofan in asm.js mode |
197 u32_and, | 196 u32_and, |
198 u32_or, | 197 u32_or, |
199 u32_xor, | 198 u32_xor, |
200 // TODO(titzer): u32_shl on arm | 199 // TODO(titzer): u32_shl on arm |
201 // TODO(titzer): u32_shr on arm | 200 // TODO(titzer): u32_shr on arm |
202 // TODO(titzer): u32_sar on arm | 201 // TODO(titzer): u32_sar on arm |
203 u32_eq, | 202 u32_eq, |
204 u32_ne, | 203 u32_ne, |
205 u32_lt, | 204 u32_lt, |
(...skipping 11 matching lines...) Expand all Loading... |
217 for (a of inputs) { | 216 for (a of inputs) { |
218 for (b of inputs) { | 217 for (b of inputs) { |
219 var expected = func(a, b); | 218 var expected = func(a, b); |
220 assertEquals(expected, module.main(a, b)); | 219 assertEquals(expected, module.main(a, b)); |
221 } | 220 } |
222 } | 221 } |
223 }); | 222 }); |
224 } | 223 } |
225 | 224 |
226 })(); | 225 })(); |
OLD | NEW |