Home | History | Annotate | Download | only in compiler
      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
      3 // found in the LICENSE file.
      4 
      5 (function() {
      6   var asm = (function Module(global, env, buffer) {
      7     "use asm";
      8 
      9     var i8 = new global.Int8Array(buffer);
     10     var u8 = new global.Uint8Array(buffer);
     11     var i16 = new global.Int16Array(buffer);
     12     var u16 = new global.Uint16Array(buffer);
     13     var i32 = new global.Int32Array(buffer);
     14     var u32 = new global.Uint32Array(buffer);
     15 
     16     var H = 0;
     17 
     18     function store_i8() {
     19       H = 4294967295;
     20       i8[0 >> 0]= H;
     21       return i8[0 >> 0];
     22     }
     23 
     24     function store_u8() {
     25       H = 4294967295;
     26       u8[0 >> 0]= H;
     27       return u8[0 >> 0];
     28     }
     29 
     30     function store_i16() {
     31       H = 4294967295;
     32       i16[0 >> 0]= H;
     33       return i16[0 >> 0];
     34     }
     35 
     36     function store_u16() {
     37       H = 4294967295;
     38       u16[0 >> 0]= H;
     39       return u16[0 >> 0];
     40     }
     41 
     42     function store_i32() {
     43       H = 4294967295;
     44       i32[0 >> 0]= H;
     45       return i32[0 >> 0];
     46     }
     47 
     48     function store_u32() {
     49       H = 4294967295;
     50       u32[0 >> 0]= H;
     51       return u32[0 >> 0];
     52     }
     53 
     54     return { store_i8: store_i8,
     55              store_u8: store_u8,
     56              store_i16: store_i16,
     57              store_u16: store_u16,
     58              store_i32: store_i32,
     59              store_u32: store_u32 };
     60   })({
     61     "Int8Array": Int8Array,
     62     "Uint8Array": Uint8Array,
     63     "Int16Array": Int16Array,
     64     "Uint16Array": Uint16Array,
     65     "Int32Array": Int32Array,
     66     "Uint32Array": Uint32Array
     67   }, {}, new ArrayBuffer(64 * 1024));
     68 
     69   assertEquals(-1, asm.store_i8());
     70   assertEquals(255, asm.store_u8());
     71   assertEquals(-1, asm.store_i16());
     72   assertEquals(65535, asm.store_u16());
     73   assertEquals(-1, asm.store_i32());
     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 })();
     99