| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 EmptyTest() { | 7 function EmptyTest() { |
| 8 "use asm"; | 8 "use asm"; |
| 9 function caller() { | 9 function caller() { |
| 10 empty(); | 10 empty(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 return (a + c + 1)|0; | 28 return (a + c + 1)|0; |
| 29 } | 29 } |
| 30 | 30 |
| 31 function caller() { | 31 function caller() { |
| 32 return sum(77,22) | 0; | 32 return sum(77,22) | 0; |
| 33 } | 33 } |
| 34 | 34 |
| 35 return {caller: caller}; | 35 return {caller: caller}; |
| 36 } | 36 } |
| 37 | 37 |
| 38 assertEquals(101, WASM.asmCompileRun(IntTest.toString())); | 38 assertEquals(101, _WASMEXP_.asmCompileRun(IntTest.toString())); |
| 39 | 39 |
| 40 function Float64Test() { | 40 function Float64Test() { |
| 41 "use asm"; | 41 "use asm"; |
| 42 function sum(a, b) { | 42 function sum(a, b) { |
| 43 a = +a; | 43 a = +a; |
| 44 b = +b; | 44 b = +b; |
| 45 return +(a + b); | 45 return +(a + b); |
| 46 } | 46 } |
| 47 | 47 |
| 48 function caller() { | 48 function caller() { |
| 49 var a = +sum(70.1,10.2); | 49 var a = +sum(70.1,10.2); |
| 50 var ret = 0|0; | 50 var ret = 0|0; |
| 51 if (a == 80.3) { | 51 if (a == 80.3) { |
| 52 ret = 1|0; | 52 ret = 1|0; |
| 53 } else { | 53 } else { |
| 54 ret = 0|0; | 54 ret = 0|0; |
| 55 } | 55 } |
| 56 return ret|0; | 56 return ret|0; |
| 57 } | 57 } |
| 58 | 58 |
| 59 return {caller: caller}; | 59 return {caller: caller}; |
| 60 } | 60 } |
| 61 | 61 |
| 62 assertEquals(1, WASM.asmCompileRun(Float64Test.toString())); | 62 assertEquals(1, _WASMEXP_.asmCompileRun(Float64Test.toString())); |
| 63 | 63 |
| 64 function BadModule() { | 64 function BadModule() { |
| 65 "use asm"; | 65 "use asm"; |
| 66 function caller(a, b) { | 66 function caller(a, b) { |
| 67 a = a|0; | 67 a = a|0; |
| 68 b = b+0; | 68 b = b+0; |
| 69 var c = (b + 1)|0 | 69 var c = (b + 1)|0 |
| 70 return (a + c + 1)|0; | 70 return (a + c + 1)|0; |
| 71 } | 71 } |
| 72 | 72 |
| 73 function caller() { | 73 function caller() { |
| 74 return call(1, 2)|0; | 74 return call(1, 2)|0; |
| 75 } | 75 } |
| 76 | 76 |
| 77 return {caller: caller}; | 77 return {caller: caller}; |
| 78 } | 78 } |
| 79 | 79 |
| 80 assertThrows(function() { | 80 assertThrows(function() { |
| 81 WASM.asmCompileRun(BadModule.toString()) | 81 _WASMEXP_.asmCompileRun(BadModule.toString()) |
| 82 }); | 82 }); |
| 83 | 83 |
| 84 function TestReturnInBlock() { | 84 function TestReturnInBlock() { |
| 85 "use asm"; | 85 "use asm"; |
| 86 | 86 |
| 87 function caller() { | 87 function caller() { |
| 88 if(1) { | 88 if(1) { |
| 89 { | 89 { |
| 90 { | 90 { |
| 91 return 1; | 91 return 1; |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 return 0; | 95 return 0; |
| 96 } | 96 } |
| 97 | 97 |
| 98 return {caller: caller}; | 98 return {caller: caller}; |
| 99 } | 99 } |
| 100 | 100 |
| 101 assertEquals(1, WASM.asmCompileRun(TestReturnInBlock.toString())); | 101 assertEquals(1, _WASMEXP_.asmCompileRun(TestReturnInBlock.toString())); |
| 102 | 102 |
| 103 function TestWhileSimple() { | 103 function TestWhileSimple() { |
| 104 "use asm"; | 104 "use asm"; |
| 105 | 105 |
| 106 function caller() { | 106 function caller() { |
| 107 var x = 0; | 107 var x = 0; |
| 108 while(x < 5) { | 108 while(x < 5) { |
| 109 x = (x + 1)|0; | 109 x = (x + 1)|0; |
| 110 } | 110 } |
| 111 return x|0; | 111 return x|0; |
| 112 } | 112 } |
| 113 | 113 |
| 114 return {caller: caller}; | 114 return {caller: caller}; |
| 115 } | 115 } |
| 116 | 116 |
| 117 assertEquals(5, WASM.asmCompileRun(TestWhileSimple.toString())); | 117 assertEquals(5, _WASMEXP_.asmCompileRun(TestWhileSimple.toString())); |
| 118 | 118 |
| 119 function TestWhileWithoutBraces() { | 119 function TestWhileWithoutBraces() { |
| 120 "use asm"; | 120 "use asm"; |
| 121 | 121 |
| 122 function caller() { | 122 function caller() { |
| 123 var x = 0; | 123 var x = 0; |
| 124 while(x <= 3) | 124 while(x <= 3) |
| 125 x = (x + 1)|0; | 125 x = (x + 1)|0; |
| 126 return x|0; | 126 return x|0; |
| 127 } | 127 } |
| 128 | 128 |
| 129 return {caller: caller}; | 129 return {caller: caller}; |
| 130 } | 130 } |
| 131 | 131 |
| 132 assertEquals(4, WASM.asmCompileRun(TestWhileWithoutBraces.toString())); | 132 assertEquals(4, _WASMEXP_.asmCompileRun(TestWhileWithoutBraces.toString())); |
| 133 | 133 |
| 134 function TestReturnInWhile() { | 134 function TestReturnInWhile() { |
| 135 "use asm"; | 135 "use asm"; |
| 136 | 136 |
| 137 function caller() { | 137 function caller() { |
| 138 var x = 0; | 138 var x = 0; |
| 139 while(x < 10) { | 139 while(x < 10) { |
| 140 x = (x + 6)|0; | 140 x = (x + 6)|0; |
| 141 return x|0; | 141 return x|0; |
| 142 } | 142 } |
| 143 return x|0; | 143 return x|0; |
| 144 } | 144 } |
| 145 | 145 |
| 146 return {caller: caller}; | 146 return {caller: caller}; |
| 147 } | 147 } |
| 148 | 148 |
| 149 assertEquals(6, WASM.asmCompileRun(TestReturnInWhile.toString())); | 149 assertEquals(6, _WASMEXP_.asmCompileRun(TestReturnInWhile.toString())); |
| 150 | 150 |
| 151 function TestReturnInWhileWithoutBraces() { | 151 function TestReturnInWhileWithoutBraces() { |
| 152 "use asm"; | 152 "use asm"; |
| 153 | 153 |
| 154 function caller() { | 154 function caller() { |
| 155 var x = 0; | 155 var x = 0; |
| 156 while(x < 5) | 156 while(x < 5) |
| 157 return 7; | 157 return 7; |
| 158 return x|0; | 158 return x|0; |
| 159 } | 159 } |
| 160 | 160 |
| 161 return {caller: caller}; | 161 return {caller: caller}; |
| 162 } | 162 } |
| 163 | 163 |
| 164 assertEquals(7, WASM.asmCompileRun(TestReturnInWhileWithoutBraces.toString())); | 164 assertEquals(7, _WASMEXP_.asmCompileRun(TestReturnInWhileWithoutBraces.toString(
))); |
| 165 | 165 |
| 166 function TestBreakInWhile() { | 166 function TestBreakInWhile() { |
| 167 "use asm"; | 167 "use asm"; |
| 168 | 168 |
| 169 function caller() { | 169 function caller() { |
| 170 while(1) { | 170 while(1) { |
| 171 break; | 171 break; |
| 172 } | 172 } |
| 173 return 8; | 173 return 8; |
| 174 } | 174 } |
| 175 | 175 |
| 176 return {caller: caller}; | 176 return {caller: caller}; |
| 177 } | 177 } |
| 178 | 178 |
| 179 assertEquals(8, WASM.asmCompileRun(TestBreakInWhile.toString())); | 179 assertEquals(8, _WASMEXP_.asmCompileRun(TestBreakInWhile.toString())); |
| 180 | 180 |
| 181 function TestBreakInNestedWhile() { | 181 function TestBreakInNestedWhile() { |
| 182 "use asm"; | 182 "use asm"; |
| 183 | 183 |
| 184 function caller() { | 184 function caller() { |
| 185 var x = 1.0; | 185 var x = 1.0; |
| 186 while(x < 1.5) { | 186 while(x < 1.5) { |
| 187 while(1) | 187 while(1) |
| 188 break; | 188 break; |
| 189 x = +(x + 0.25); | 189 x = +(x + 0.25); |
| 190 } | 190 } |
| 191 var ret = 0; | 191 var ret = 0; |
| 192 if (x == 1.5) { | 192 if (x == 1.5) { |
| 193 ret = 9; | 193 ret = 9; |
| 194 } | 194 } |
| 195 return ret|0; | 195 return ret|0; |
| 196 } | 196 } |
| 197 | 197 |
| 198 return {caller: caller}; | 198 return {caller: caller}; |
| 199 } | 199 } |
| 200 | 200 |
| 201 assertEquals(9, WASM.asmCompileRun(TestBreakInNestedWhile.toString())); | 201 assertEquals(9, _WASMEXP_.asmCompileRun(TestBreakInNestedWhile.toString())); |
| 202 | 202 |
| 203 function TestBreakInBlock() { | 203 function TestBreakInBlock() { |
| 204 "use asm"; | 204 "use asm"; |
| 205 | 205 |
| 206 function caller() { | 206 function caller() { |
| 207 var x = 0; | 207 var x = 0; |
| 208 abc: { | 208 abc: { |
| 209 x = 10; | 209 x = 10; |
| 210 if (x == 10) { | 210 if (x == 10) { |
| 211 break abc; | 211 break abc; |
| 212 } | 212 } |
| 213 x = 20; | 213 x = 20; |
| 214 } | 214 } |
| 215 return x|0; | 215 return x|0; |
| 216 } | 216 } |
| 217 | 217 |
| 218 return {caller: caller}; | 218 return {caller: caller}; |
| 219 } | 219 } |
| 220 | 220 |
| 221 assertEquals(10, WASM.asmCompileRun(TestBreakInBlock.toString())); | 221 assertEquals(10, _WASMEXP_.asmCompileRun(TestBreakInBlock.toString())); |
| 222 | 222 |
| 223 function TestBreakInNamedWhile() { | 223 function TestBreakInNamedWhile() { |
| 224 "use asm"; | 224 "use asm"; |
| 225 | 225 |
| 226 function caller() { | 226 function caller() { |
| 227 var x = 0; | 227 var x = 0; |
| 228 outer: while (1) { | 228 outer: while (1) { |
| 229 x = (x + 1)|0; | 229 x = (x + 1)|0; |
| 230 while (x == 11) { | 230 while (x == 11) { |
| 231 break outer; | 231 break outer; |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 return x|0; | 234 return x|0; |
| 235 } | 235 } |
| 236 | 236 |
| 237 return {caller: caller}; | 237 return {caller: caller}; |
| 238 } | 238 } |
| 239 | 239 |
| 240 assertEquals(11, WASM.asmCompileRun(TestBreakInNamedWhile.toString())); | 240 assertEquals(11, _WASMEXP_.asmCompileRun(TestBreakInNamedWhile.toString())); |
| 241 | 241 |
| 242 function TestContinue() { | 242 function TestContinue() { |
| 243 "use asm"; | 243 "use asm"; |
| 244 | 244 |
| 245 function caller() { | 245 function caller() { |
| 246 var x = 5; | 246 var x = 5; |
| 247 var ret = 0; | 247 var ret = 0; |
| 248 while (x >= 0) { | 248 while (x >= 0) { |
| 249 x = (x - 1)|0; | 249 x = (x - 1)|0; |
| 250 if (x == 2) { | 250 if (x == 2) { |
| 251 continue; | 251 continue; |
| 252 } | 252 } |
| 253 ret = (ret - 1)|0; | 253 ret = (ret - 1)|0; |
| 254 } | 254 } |
| 255 return ret|0; | 255 return ret|0; |
| 256 } | 256 } |
| 257 | 257 |
| 258 return {caller: caller}; | 258 return {caller: caller}; |
| 259 } | 259 } |
| 260 | 260 |
| 261 assertEquals(-5, WASM.asmCompileRun(TestContinue.toString())); | 261 assertEquals(-5, _WASMEXP_.asmCompileRun(TestContinue.toString())); |
| 262 | 262 |
| 263 function TestContinueInNamedWhile() { | 263 function TestContinueInNamedWhile() { |
| 264 "use asm"; | 264 "use asm"; |
| 265 | 265 |
| 266 function caller() { | 266 function caller() { |
| 267 var x = 5; | 267 var x = 5; |
| 268 var y = 0; | 268 var y = 0; |
| 269 var ret = 0; | 269 var ret = 0; |
| 270 outer: while (x > 0) { | 270 outer: while (x > 0) { |
| 271 x = (x - 1)|0; | 271 x = (x - 1)|0; |
| 272 y = 0; | 272 y = 0; |
| 273 while (y < 5) { | 273 while (y < 5) { |
| 274 if (x == 3) { | 274 if (x == 3) { |
| 275 continue outer; | 275 continue outer; |
| 276 } | 276 } |
| 277 ret = (ret + 1)|0; | 277 ret = (ret + 1)|0; |
| 278 y = (y + 1)|0; | 278 y = (y + 1)|0; |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 return ret|0; | 281 return ret|0; |
| 282 } | 282 } |
| 283 | 283 |
| 284 return {caller: caller}; | 284 return {caller: caller}; |
| 285 } | 285 } |
| 286 | 286 |
| 287 assertEquals(20, WASM.asmCompileRun(TestContinueInNamedWhile.toString())); | 287 assertEquals(20, _WASMEXP_.asmCompileRun(TestContinueInNamedWhile.toString())); |
| 288 | 288 |
| 289 function TestNot() { | 289 function TestNot() { |
| 290 "use asm"; | 290 "use asm"; |
| 291 | 291 |
| 292 function caller() { | 292 function caller() { |
| 293 var a = !(2 > 3); | 293 var a = !(2 > 3); |
| 294 return a | 0; | 294 return a | 0; |
| 295 } | 295 } |
| 296 | 296 |
| 297 return {caller:caller}; | 297 return {caller:caller}; |
| 298 } | 298 } |
| 299 | 299 |
| 300 assertEquals(1, WASM.asmCompileRun(TestNot.toString())); | 300 assertEquals(1, _WASMEXP_.asmCompileRun(TestNot.toString())); |
| 301 | 301 |
| 302 function TestNotEquals() { | 302 function TestNotEquals() { |
| 303 "use asm"; | 303 "use asm"; |
| 304 | 304 |
| 305 function caller() { | 305 function caller() { |
| 306 var a = 3; | 306 var a = 3; |
| 307 if (a != 2) { | 307 if (a != 2) { |
| 308 return 21; | 308 return 21; |
| 309 } | 309 } |
| 310 return 0; | 310 return 0; |
| 311 } | 311 } |
| 312 | 312 |
| 313 return {caller:caller}; | 313 return {caller:caller}; |
| 314 } | 314 } |
| 315 | 315 |
| 316 assertEquals(21, WASM.asmCompileRun(TestNotEquals.toString())); | 316 assertEquals(21, _WASMEXP_.asmCompileRun(TestNotEquals.toString())); |
| 317 | 317 |
| 318 function TestUnsignedComparison() { | 318 function TestUnsignedComparison() { |
| 319 "use asm"; | 319 "use asm"; |
| 320 | 320 |
| 321 function caller() { | 321 function caller() { |
| 322 var a = 0xffffffff; | 322 var a = 0xffffffff; |
| 323 if ((a>>>0) > (0>>>0)) { | 323 if ((a>>>0) > (0>>>0)) { |
| 324 return 22; | 324 return 22; |
| 325 } | 325 } |
| 326 return 0; | 326 return 0; |
| 327 } | 327 } |
| 328 | 328 |
| 329 return {caller:caller}; | 329 return {caller:caller}; |
| 330 } | 330 } |
| 331 | 331 |
| 332 assertEquals(22, WASM.asmCompileRun(TestUnsignedComparison.toString())); | 332 assertEquals(22, _WASMEXP_.asmCompileRun(TestUnsignedComparison.toString())); |
| 333 | 333 |
| 334 function TestMixedAdd() { | 334 function TestMixedAdd() { |
| 335 "use asm"; | 335 "use asm"; |
| 336 | 336 |
| 337 function caller() { | 337 function caller() { |
| 338 var a = 0x80000000; | 338 var a = 0x80000000; |
| 339 var b = 0x7fffffff; | 339 var b = 0x7fffffff; |
| 340 var c = 0; | 340 var c = 0; |
| 341 c = ((a>>>0) + b)|0; | 341 c = ((a>>>0) + b)|0; |
| 342 if ((c >>> 0) > (0>>>0)) { | 342 if ((c >>> 0) > (0>>>0)) { |
| 343 if (c < 0) { | 343 if (c < 0) { |
| 344 return 23; | 344 return 23; |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 return 0; | 347 return 0; |
| 348 } | 348 } |
| 349 | 349 |
| 350 return {caller:caller}; | 350 return {caller:caller}; |
| 351 } | 351 } |
| 352 | 352 |
| 353 assertEquals(23, WASM.asmCompileRun(TestMixedAdd.toString())); | 353 assertEquals(23, _WASMEXP_.asmCompileRun(TestMixedAdd.toString())); |
| 354 | 354 |
| 355 function TestInt32HeapAccess(stdlib, foreign, buffer) { | 355 function TestInt32HeapAccess(stdlib, foreign, buffer) { |
| 356 "use asm"; | 356 "use asm"; |
| 357 | 357 |
| 358 var m = new stdlib.Int32Array(buffer); | 358 var m = new stdlib.Int32Array(buffer); |
| 359 function caller() { | 359 function caller() { |
| 360 var i = 4; | 360 var i = 4; |
| 361 | 361 |
| 362 m[0] = (i + 1) | 0; | 362 m[0] = (i + 1) | 0; |
| 363 m[i >> 2] = ((m[0]|0) + 1) | 0; | 363 m[i >> 2] = ((m[0]|0) + 1) | 0; |
| 364 m[2] = ((m[i >> 2]|0) + 1) | 0; | 364 m[2] = ((m[i >> 2]|0) + 1) | 0; |
| 365 return m[2] | 0; | 365 return m[2] | 0; |
| 366 } | 366 } |
| 367 | 367 |
| 368 return {caller: caller}; | 368 return {caller: caller}; |
| 369 } | 369 } |
| 370 | 370 |
| 371 assertEquals(7, WASM.asmCompileRun(TestInt32HeapAccess.toString())); | 371 assertEquals(7, _WASMEXP_.asmCompileRun(TestInt32HeapAccess.toString())); |
| 372 | 372 |
| 373 function TestHeapAccessIntTypes() { | 373 function TestHeapAccessIntTypes() { |
| 374 var types = [ | 374 var types = [ |
| 375 ['Int8Array', '>> 0'], | 375 ['Int8Array', '>> 0'], |
| 376 ['Uint8Array', '>> 0'], | 376 ['Uint8Array', '>> 0'], |
| 377 ['Int16Array', '>> 1'], | 377 ['Int16Array', '>> 1'], |
| 378 ['Uint16Array', '>> 1'], | 378 ['Uint16Array', '>> 1'], |
| 379 ['Int32Array', '>> 2'], | 379 ['Int32Array', '>> 2'], |
| 380 ['Uint32Array', '>> 2'], | 380 ['Uint32Array', '>> 2'], |
| 381 ]; | 381 ]; |
| 382 for (var i = 0; i < types.length; i++) { | 382 for (var i = 0; i < types.length; i++) { |
| 383 var code = TestInt32HeapAccess.toString(); | 383 var code = TestInt32HeapAccess.toString(); |
| 384 code = code.replace('Int32Array', types[i][0]); | 384 code = code.replace('Int32Array', types[i][0]); |
| 385 code = code.replace(/>> 2/g, types[i][1]); | 385 code = code.replace(/>> 2/g, types[i][1]); |
| 386 assertEquals(7, WASM.asmCompileRun(code)); | 386 assertEquals(7, _WASMEXP_.asmCompileRun(code)); |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 | 389 |
| 390 TestHeapAccessIntTypes(); | 390 TestHeapAccessIntTypes(); |
| 391 | 391 |
| 392 function TestFloatHeapAccess(stdlib, foreign, buffer) { | 392 function TestFloatHeapAccess(stdlib, foreign, buffer) { |
| 393 "use asm"; | 393 "use asm"; |
| 394 | 394 |
| 395 var f32 = new stdlib.Float32Array(buffer); | 395 var f32 = new stdlib.Float32Array(buffer); |
| 396 var f64 = new stdlib.Float64Array(buffer); | 396 var f64 = new stdlib.Float64Array(buffer); |
| 397 var fround = stdlib.Math.fround; | 397 var fround = stdlib.Math.fround; |
| 398 function caller() { | 398 function caller() { |
| 399 var i = 8; | 399 var i = 8; |
| 400 var j = 8; | 400 var j = 8; |
| 401 var v = 6.0; | 401 var v = 6.0; |
| 402 | 402 |
| 403 // TODO(bradnelson): Add float32 when asm-wasm supports it. | 403 // TODO(bradnelson): Add float32 when asm-wasm supports it. |
| 404 f64[2] = v + 1.0; | 404 f64[2] = v + 1.0; |
| 405 f64[i >> 3] = +f64[2] + 1.0; | 405 f64[i >> 3] = +f64[2] + 1.0; |
| 406 f64[j >> 3] = +f64[j >> 3] + 1.0; | 406 f64[j >> 3] = +f64[j >> 3] + 1.0; |
| 407 i = +f64[i >> 3] == 9.0; | 407 i = +f64[i >> 3] == 9.0; |
| 408 return i|0; | 408 return i|0; |
| 409 } | 409 } |
| 410 | 410 |
| 411 return {caller: caller}; | 411 return {caller: caller}; |
| 412 } | 412 } |
| 413 | 413 |
| 414 assertEquals(1, WASM.asmCompileRun(TestFloatHeapAccess.toString())); | 414 assertEquals(1, _WASMEXP_.asmCompileRun(TestFloatHeapAccess.toString())); |
| 415 | 415 |
| 416 function TestConvertI32() { | 416 function TestConvertI32() { |
| 417 "use asm"; | 417 "use asm"; |
| 418 | 418 |
| 419 function caller() { | 419 function caller() { |
| 420 var a = 1.5; | 420 var a = 1.5; |
| 421 if ((~~(a + a)) == 3) { | 421 if ((~~(a + a)) == 3) { |
| 422 return 24; | 422 return 24; |
| 423 } | 423 } |
| 424 return 0; | 424 return 0; |
| 425 } | 425 } |
| 426 | 426 |
| 427 return {caller:caller}; | 427 return {caller:caller}; |
| 428 } | 428 } |
| 429 | 429 |
| 430 assertEquals(24, WASM.asmCompileRun(TestConvertI32.toString())); | 430 assertEquals(24, _WASMEXP_.asmCompileRun(TestConvertI32.toString())); |
| 431 | 431 |
| 432 function TestConvertF64FromInt() { | 432 function TestConvertF64FromInt() { |
| 433 "use asm"; | 433 "use asm"; |
| 434 | 434 |
| 435 function caller() { | 435 function caller() { |
| 436 var a = 1; | 436 var a = 1; |
| 437 if ((+(a + a)) > 1.5) { | 437 if ((+(a + a)) > 1.5) { |
| 438 return 25; | 438 return 25; |
| 439 } | 439 } |
| 440 return 0; | 440 return 0; |
| 441 } | 441 } |
| 442 | 442 |
| 443 return {caller:caller}; | 443 return {caller:caller}; |
| 444 } | 444 } |
| 445 | 445 |
| 446 assertEquals(25, WASM.asmCompileRun(TestConvertF64FromInt.toString())); | 446 assertEquals(25, _WASMEXP_.asmCompileRun(TestConvertF64FromInt.toString())); |
| 447 | 447 |
| 448 function TestConvertF64FromUnsigned() { | 448 function TestConvertF64FromUnsigned() { |
| 449 "use asm"; | 449 "use asm"; |
| 450 | 450 |
| 451 function caller() { | 451 function caller() { |
| 452 var a = 0xffffffff; | 452 var a = 0xffffffff; |
| 453 if ((+(a>>>0)) > 0.0) { | 453 if ((+(a>>>0)) > 0.0) { |
| 454 if((+a) < 0.0) { | 454 if((+a) < 0.0) { |
| 455 return 26; | 455 return 26; |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 return 0; | 458 return 0; |
| 459 } | 459 } |
| 460 | 460 |
| 461 return {caller:caller}; | 461 return {caller:caller}; |
| 462 } | 462 } |
| 463 | 463 |
| 464 assertEquals(26, WASM.asmCompileRun(TestConvertF64FromUnsigned.toString())); | 464 assertEquals(26, _WASMEXP_.asmCompileRun(TestConvertF64FromUnsigned.toString()))
; |
| 465 | 465 |
| 466 function TestModInt() { | 466 function TestModInt() { |
| 467 "use asm"; | 467 "use asm"; |
| 468 | 468 |
| 469 function caller() { | 469 function caller() { |
| 470 var a = -83; | 470 var a = -83; |
| 471 var b = 28; | 471 var b = 28; |
| 472 return ((a|0)%(b|0))|0; | 472 return ((a|0)%(b|0))|0; |
| 473 } | 473 } |
| 474 | 474 |
| 475 return {caller:caller}; | 475 return {caller:caller}; |
| 476 } | 476 } |
| 477 | 477 |
| 478 assertEquals(-27, WASM.asmCompileRun(TestModInt.toString())); | 478 assertEquals(-27, _WASMEXP_.asmCompileRun(TestModInt.toString())); |
| 479 | 479 |
| 480 function TestModUnsignedInt() { | 480 function TestModUnsignedInt() { |
| 481 "use asm"; | 481 "use asm"; |
| 482 | 482 |
| 483 function caller() { | 483 function caller() { |
| 484 var a = 0x80000000; //2147483648 | 484 var a = 0x80000000; //2147483648 |
| 485 var b = 10; | 485 var b = 10; |
| 486 return ((a>>>0)%(b>>>0))|0; | 486 return ((a>>>0)%(b>>>0))|0; |
| 487 } | 487 } |
| 488 | 488 |
| 489 return {caller:caller}; | 489 return {caller:caller}; |
| 490 } | 490 } |
| 491 | 491 |
| 492 assertEquals(8, WASM.asmCompileRun(TestModUnsignedInt.toString())); | 492 assertEquals(8, _WASMEXP_.asmCompileRun(TestModUnsignedInt.toString())); |
| 493 | 493 |
| 494 function TestModDouble() { | 494 function TestModDouble() { |
| 495 "use asm"; | 495 "use asm"; |
| 496 | 496 |
| 497 function caller() { | 497 function caller() { |
| 498 var a = 5.25; | 498 var a = 5.25; |
| 499 var b = 2.5; | 499 var b = 2.5; |
| 500 if (a%b == 0.25) { | 500 if (a%b == 0.25) { |
| 501 return 28; | 501 return 28; |
| 502 } | 502 } |
| 503 return 0; | 503 return 0; |
| 504 } | 504 } |
| 505 | 505 |
| 506 return {caller:caller}; | 506 return {caller:caller}; |
| 507 } | 507 } |
| 508 | 508 |
| 509 assertEquals(28, WASM.asmCompileRun(TestModDouble.toString())); | 509 assertEquals(28, _WASMEXP_.asmCompileRun(TestModDouble.toString())); |
| 510 | 510 |
| 511 /* | 511 /* |
| 512 TODO: Fix parsing of negative doubles | 512 TODO: Fix parsing of negative doubles |
| 513 Fix code to use trunc instead of casts | 513 Fix code to use trunc instead of casts |
| 514 function TestModDoubleNegative() { | 514 function TestModDoubleNegative() { |
| 515 "use asm"; | 515 "use asm"; |
| 516 | 516 |
| 517 function caller() { | 517 function caller() { |
| 518 var a = -34359738368.25; | 518 var a = -34359738368.25; |
| 519 var b = 2.5; | 519 var b = 2.5; |
| 520 if (a%b == -0.75) { | 520 if (a%b == -0.75) { |
| 521 return 28; | 521 return 28; |
| 522 } | 522 } |
| 523 return 0; | 523 return 0; |
| 524 } | 524 } |
| 525 | 525 |
| 526 return {caller:caller}; | 526 return {caller:caller}; |
| 527 } | 527 } |
| 528 | 528 |
| 529 assertEquals(28, WASM.asmCompileRun(TestModDoubleNegative.toString())); | 529 assertEquals(28, _WASMEXP_.asmCompileRun(TestModDoubleNegative.toString())); |
| 530 */ | 530 */ |
| 531 | 531 |
| 532 function TestNamedFunctions() { | 532 function TestNamedFunctions() { |
| 533 "use asm"; | 533 "use asm"; |
| 534 | 534 |
| 535 var a = 0.0; | 535 var a = 0.0; |
| 536 var b = 0.0; | 536 var b = 0.0; |
| 537 | 537 |
| 538 function add() { | 538 function add() { |
| 539 return +(a + b); | 539 return +(a + b); |
| 540 } | 540 } |
| 541 | 541 |
| 542 function init() { | 542 function init() { |
| 543 a = 43.25; | 543 a = 43.25; |
| 544 b = 34.25; | 544 b = 34.25; |
| 545 } | 545 } |
| 546 | 546 |
| 547 return {init:init, | 547 return {init:init, |
| 548 add:add}; | 548 add:add}; |
| 549 } | 549 } |
| 550 | 550 |
| 551 var module = WASM.instantiateModuleFromAsm(TestNamedFunctions.toString()); | 551 var module = _WASMEXP_.instantiateModuleFromAsm(TestNamedFunctions.toString()); |
| 552 module.init(); | 552 module.init(); |
| 553 assertEquals(77.5, module.add()); | 553 assertEquals(77.5, module.add()); |
| 554 | 554 |
| 555 function TestGlobalsWithInit() { | 555 function TestGlobalsWithInit() { |
| 556 "use asm"; | 556 "use asm"; |
| 557 | 557 |
| 558 var a = 43.25; | 558 var a = 43.25; |
| 559 var b = 34.25; | 559 var b = 34.25; |
| 560 | 560 |
| 561 function add() { | 561 function add() { |
| 562 return +(a + b); | 562 return +(a + b); |
| 563 } | 563 } |
| 564 | 564 |
| 565 return {add:add}; | 565 return {add:add}; |
| 566 } | 566 } |
| 567 | 567 |
| 568 var module = WASM.instantiateModuleFromAsm(TestGlobalsWithInit.toString()); | 568 var module = _WASMEXP_.instantiateModuleFromAsm(TestGlobalsWithInit.toString()); |
| 569 module.__init__(); | 569 module.__init__(); |
| 570 assertEquals(77.5, module.add()); | 570 assertEquals(77.5, module.add()); |
| 571 | 571 |
| 572 function TestForLoop() { | 572 function TestForLoop() { |
| 573 "use asm" | 573 "use asm" |
| 574 | 574 |
| 575 function caller() { | 575 function caller() { |
| 576 var ret = 0; | 576 var ret = 0; |
| 577 var i = 0; | 577 var i = 0; |
| 578 for (i = 2; i <= 10; i = (i+1)|0) { | 578 for (i = 2; i <= 10; i = (i+1)|0) { |
| 579 ret = (ret + i) | 0; | 579 ret = (ret + i) | 0; |
| 580 } | 580 } |
| 581 return ret|0; | 581 return ret|0; |
| 582 } | 582 } |
| 583 | 583 |
| 584 return {caller:caller}; | 584 return {caller:caller}; |
| 585 } | 585 } |
| 586 | 586 |
| 587 assertEquals(54, WASM.asmCompileRun(TestForLoop.toString())); | 587 assertEquals(54, _WASMEXP_.asmCompileRun(TestForLoop.toString())); |
| 588 | 588 |
| 589 function TestForLoopWithoutInit() { | 589 function TestForLoopWithoutInit() { |
| 590 "use asm" | 590 "use asm" |
| 591 | 591 |
| 592 function caller() { | 592 function caller() { |
| 593 var ret = 0; | 593 var ret = 0; |
| 594 var i = 0; | 594 var i = 0; |
| 595 for (; i < 10; i = (i+1)|0) { | 595 for (; i < 10; i = (i+1)|0) { |
| 596 ret = (ret + 10) | 0; | 596 ret = (ret + 10) | 0; |
| 597 } | 597 } |
| 598 return ret|0; | 598 return ret|0; |
| 599 } | 599 } |
| 600 | 600 |
| 601 return {caller:caller}; | 601 return {caller:caller}; |
| 602 } | 602 } |
| 603 | 603 |
| 604 assertEquals(100, WASM.asmCompileRun(TestForLoopWithoutInit.toString())); | 604 assertEquals(100, _WASMEXP_.asmCompileRun(TestForLoopWithoutInit.toString())); |
| 605 | 605 |
| 606 function TestForLoopWithoutCondition() { | 606 function TestForLoopWithoutCondition() { |
| 607 "use asm" | 607 "use asm" |
| 608 | 608 |
| 609 function caller() { | 609 function caller() { |
| 610 var ret = 0; | 610 var ret = 0; |
| 611 var i = 0; | 611 var i = 0; |
| 612 for (i=1;; i = (i+1)|0) { | 612 for (i=1;; i = (i+1)|0) { |
| 613 ret = (ret + i) | 0; | 613 ret = (ret + i) | 0; |
| 614 if (i == 11) { | 614 if (i == 11) { |
| 615 break; | 615 break; |
| 616 } | 616 } |
| 617 } | 617 } |
| 618 return ret|0; | 618 return ret|0; |
| 619 } | 619 } |
| 620 | 620 |
| 621 return {caller:caller}; | 621 return {caller:caller}; |
| 622 } | 622 } |
| 623 | 623 |
| 624 assertEquals(66, WASM.asmCompileRun(TestForLoopWithoutCondition.toString())); | 624 assertEquals(66, _WASMEXP_.asmCompileRun(TestForLoopWithoutCondition.toString())
); |
| 625 | 625 |
| 626 function TestForLoopWithoutNext() { | 626 function TestForLoopWithoutNext() { |
| 627 "use asm" | 627 "use asm" |
| 628 | 628 |
| 629 function caller() { | 629 function caller() { |
| 630 var i = 0; | 630 var i = 0; |
| 631 for (i=1; i < 41;) { | 631 for (i=1; i < 41;) { |
| 632 i = (i + 1) | 0; | 632 i = (i + 1) | 0; |
| 633 } | 633 } |
| 634 return i|0; | 634 return i|0; |
| 635 } | 635 } |
| 636 | 636 |
| 637 return {caller:caller}; | 637 return {caller:caller}; |
| 638 } | 638 } |
| 639 | 639 |
| 640 assertEquals(41, WASM.asmCompileRun(TestForLoopWithoutNext.toString())); | 640 assertEquals(41, _WASMEXP_.asmCompileRun(TestForLoopWithoutNext.toString())); |
| 641 | 641 |
| 642 function TestForLoopWithoutBody() { | 642 function TestForLoopWithoutBody() { |
| 643 "use asm" | 643 "use asm" |
| 644 | 644 |
| 645 function caller() { | 645 function caller() { |
| 646 var i = 0; | 646 var i = 0; |
| 647 for (i=1; i < 45 ; i = (i+1)|0) { | 647 for (i=1; i < 45 ; i = (i+1)|0) { |
| 648 } | 648 } |
| 649 return i|0; | 649 return i|0; |
| 650 } | 650 } |
| 651 | 651 |
| 652 return {caller:caller}; | 652 return {caller:caller}; |
| 653 } | 653 } |
| 654 | 654 |
| 655 assertEquals(45, WASM.asmCompileRun(TestForLoopWithoutBody.toString())); | 655 assertEquals(45, _WASMEXP_.asmCompileRun(TestForLoopWithoutBody.toString())); |
| 656 | 656 |
| 657 function TestDoWhile() { | 657 function TestDoWhile() { |
| 658 "use asm" | 658 "use asm" |
| 659 | 659 |
| 660 function caller() { | 660 function caller() { |
| 661 var i = 0; | 661 var i = 0; |
| 662 var ret = 21; | 662 var ret = 21; |
| 663 do { | 663 do { |
| 664 ret = (ret + ret)|0; | 664 ret = (ret + ret)|0; |
| 665 i = (i + 1)|0; | 665 i = (i + 1)|0; |
| 666 } while (i < 2); | 666 } while (i < 2); |
| 667 return ret|0; | 667 return ret|0; |
| 668 } | 668 } |
| 669 | 669 |
| 670 return {caller:caller}; | 670 return {caller:caller}; |
| 671 } | 671 } |
| 672 | 672 |
| 673 assertEquals(84, WASM.asmCompileRun(TestDoWhile.toString())); | 673 assertEquals(84, _WASMEXP_.asmCompileRun(TestDoWhile.toString())); |
| 674 | 674 |
| 675 function TestConditional() { | 675 function TestConditional() { |
| 676 "use asm" | 676 "use asm" |
| 677 | 677 |
| 678 function caller() { | 678 function caller() { |
| 679 var x = 1; | 679 var x = 1; |
| 680 return ((x > 0) ? 41 : 71)|0; | 680 return ((x > 0) ? 41 : 71)|0; |
| 681 } | 681 } |
| 682 | 682 |
| 683 return {caller:caller}; | 683 return {caller:caller}; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 } | 750 } |
| 751 default: return 0; | 751 default: return 0; |
| 752 } | 752 } |
| 753 return 0; | 753 return 0; |
| 754 } | 754 } |
| 755 | 755 |
| 756 return {caller:caller}; | 756 return {caller:caller}; |
| 757 } | 757 } |
| 758 | 758 |
| 759 assertEquals(43, WASM.asmCompileRun(TestNestedSwitch.toString())); | 759 assertEquals(43, WASM.asmCompileRun(TestNestedSwitch.toString())); |
| OLD | NEW |