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 function Module(stdlib, foreign, heap) { | 5 function Module(stdlib, foreign, heap) { |
6 "use asm"; | 6 "use asm"; |
7 var MEM16 = new stdlib.Int16Array(heap); | 7 var MEM16 = new stdlib.Int16Array(heap); |
8 function load(i) { | 8 function load(i) { |
9 i = i|0; | 9 i = i|0; |
10 i = MEM16[i >> 1] | 0; | 10 i = MEM16[i >> 1] | 0; |
11 return i; | 11 return i; |
12 } | 12 } |
| 13 function loadm1() { |
| 14 return MEM16[-1] | 0; |
| 15 } |
13 function store(i, v) { | 16 function store(i, v) { |
14 i = i|0; | 17 i = i|0; |
15 v = v|0; | 18 v = v|0; |
16 MEM16[i >> 1] = v; | 19 MEM16[i >> 1] = v; |
17 } | 20 } |
18 return { load: load, store: store }; | 21 function storem1(v) { |
| 22 v = v|0; |
| 23 MEM16[-1] = v; |
| 24 } |
| 25 return {load: load, loadm1: loadm1, store: store, storem1: storem1}; |
19 } | 26 } |
20 | 27 |
21 var m = Module(this, {}, new ArrayBuffer(2)); | 28 var m = Module(this, {}, new ArrayBuffer(2)); |
22 | 29 |
| 30 m.store(-1000, 4); |
| 31 assertEquals(0, m.load(-1000)); |
| 32 assertEquals(0, m.loadm1()); |
| 33 m.storem1(1); |
| 34 assertEquals(0, m.loadm1()); |
23 m.store(0, 32767); | 35 m.store(0, 32767); |
24 for (var i = 1; i < 64; ++i) { | 36 for (var i = 1; i < 64; ++i) { |
25 m.store(i * 2 * 32 * 1024, i); | 37 m.store(i * 2 * 32 * 1024, i); |
26 } | 38 } |
27 assertEquals(32767, m.load(0)); | 39 assertEquals(32767, m.load(0)); |
28 for (var i = 1; i < 64; ++i) { | 40 for (var i = 1; i < 64; ++i) { |
29 assertEquals(0, m.load(i * 2 * 32 * 1024)); | 41 assertEquals(0, m.load(i * 2 * 32 * 1024)); |
30 } | 42 } |
OLD | NEW |