OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 var asm = (function Module(global, env, buffer) { | 5 (function() { |
6 "use asm"; | 6 var asm = (function Module(global, env, buffer) { |
| 7 "use asm"; |
7 | 8 |
8 var i8 = new global.Int8Array(buffer); | 9 var i8 = new global.Int8Array(buffer); |
9 var u8 = new global.Uint8Array(buffer); | 10 var u8 = new global.Uint8Array(buffer); |
10 var i16 = new global.Int16Array(buffer); | 11 var i16 = new global.Int16Array(buffer); |
11 var u16 = new global.Uint16Array(buffer); | 12 var u16 = new global.Uint16Array(buffer); |
12 var i32 = new global.Int32Array(buffer); | 13 var i32 = new global.Int32Array(buffer); |
13 var u32 = new global.Uint32Array(buffer); | 14 var u32 = new global.Uint32Array(buffer); |
14 | 15 |
15 var H = 0; | 16 var H = 0; |
16 | 17 |
17 function store_i8() { | 18 function store_i8() { |
18 H = 4294967295; | 19 H = 4294967295; |
19 i8[0 >> 0]= H; | 20 i8[0 >> 0]= H; |
20 return i8[0 >> 0]; | 21 return i8[0 >> 0]; |
21 } | 22 } |
22 | 23 |
23 function store_u8() { | 24 function store_u8() { |
24 H = 4294967295; | 25 H = 4294967295; |
25 u8[0 >> 0]= H; | 26 u8[0 >> 0]= H; |
26 return u8[0 >> 0]; | 27 return u8[0 >> 0]; |
27 } | 28 } |
28 | 29 |
29 function store_i16() { | 30 function store_i16() { |
30 H = 4294967295; | 31 H = 4294967295; |
31 i16[0 >> 0]= H; | 32 i16[0 >> 0]= H; |
32 return i16[0 >> 0]; | 33 return i16[0 >> 0]; |
33 } | 34 } |
34 | 35 |
35 function store_u16() { | 36 function store_u16() { |
36 H = 4294967295; | 37 H = 4294967295; |
37 u16[0 >> 0]= H; | 38 u16[0 >> 0]= H; |
38 return u16[0 >> 0]; | 39 return u16[0 >> 0]; |
39 } | 40 } |
40 | 41 |
41 function store_i32() { | 42 function store_i32() { |
42 H = 4294967295; | 43 H = 4294967295; |
43 i32[0 >> 0]= H; | 44 i32[0 >> 0]= H; |
44 return i32[0 >> 0]; | 45 return i32[0 >> 0]; |
45 } | 46 } |
46 | 47 |
47 function store_u32() { | 48 function store_u32() { |
48 H = 4294967295; | 49 H = 4294967295; |
49 u32[0 >> 0]= H; | 50 u32[0 >> 0]= H; |
50 return u32[0 >> 0]; | 51 return u32[0 >> 0]; |
51 } | 52 } |
52 | 53 |
53 return { store_i8: store_i8, | 54 return { store_i8: store_i8, |
54 store_u8: store_u8, | 55 store_u8: store_u8, |
55 store_i16: store_i16, | 56 store_i16: store_i16, |
56 store_u16: store_u16, | 57 store_u16: store_u16, |
57 store_i32: store_i32, | 58 store_i32: store_i32, |
58 store_u32: store_u32 }; | 59 store_u32: store_u32 }; |
59 })({ | 60 })({ |
60 "Int8Array": Int8Array, | 61 "Int8Array": Int8Array, |
61 "Uint8Array": Uint8Array, | 62 "Uint8Array": Uint8Array, |
62 "Int16Array": Int16Array, | 63 "Int16Array": Int16Array, |
63 "Uint16Array": Uint16Array, | 64 "Uint16Array": Uint16Array, |
64 "Int32Array": Int32Array, | 65 "Int32Array": Int32Array, |
65 "Uint32Array": Uint32Array | 66 "Uint32Array": Uint32Array |
66 }, {}, new ArrayBuffer(64 * 1024)); | 67 }, {}, new ArrayBuffer(64 * 1024)); |
67 | 68 |
68 assertEquals(-1, asm.store_i8()); | 69 assertEquals(-1, asm.store_i8()); |
69 assertEquals(255, asm.store_u8()); | 70 assertEquals(255, asm.store_u8()); |
70 assertEquals(-1, asm.store_i16()); | 71 assertEquals(-1, asm.store_i16()); |
71 assertEquals(65535, asm.store_u16()); | 72 assertEquals(65535, asm.store_u16()); |
72 assertEquals(-1, asm.store_i32()); | 73 assertEquals(-1, asm.store_i32()); |
73 assertEquals(4294967295, asm.store_u32()); | 74 assertEquals(4294967295, asm.store_u32()); |
| 75 })(); |
| 76 |
| 77 (function() { |
| 78 var asm = (function Module(global, env, buffer) { |
| 79 "use asm"; |
| 80 |
| 81 var i32 = new global.Int32Array(buffer); |
| 82 |
| 83 var H = 0; |
| 84 |
| 85 // This is not valid asm.js, but we should still generate correct code. |
| 86 function store_i32_from_string() { |
| 87 H = "3"; |
| 88 i32[0 >> 0]= H; |
| 89 return i32[0 >> 0]; |
| 90 } |
| 91 |
| 92 return { store_i32_from_string: store_i32_from_string }; |
| 93 })({ |
| 94 "Int32Array": Int32Array |
| 95 }, {}, new ArrayBuffer(64 * 1024)); |
| 96 |
| 97 assertEquals(3, asm.store_i32_from_string()); |
| 98 })(); |
OLD | NEW |