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
5var stdlib = this;
6var buffer = new ArrayBuffer(64 * 1024);
7var foreign = {}
8
9
10var sext8 = (function Module(stdlib, foreign, heap) {
11  "use asm";
12  function sext8(i) {
13    i = i|0;
14    i = i << 24 >> 24;
15    return i|0;
16  }
17  return { sext8: sext8 };
18})(stdlib, foreign, buffer).sext8;
19
20assertEquals(-128, sext8(128));
21assertEquals(-1, sext8(-1));
22assertEquals(-1, sext8(255));
23assertEquals(0, sext8(0));
24assertEquals(0, sext8(256));
25assertEquals(42, sext8(42));
26assertEquals(127, sext8(127));
27
28
29var sext16 = (function Module(stdlib, foreign, heap) {
30  "use asm";
31  function sext16(i) {
32    i = i|0;
33    i = i << 16 >> 16;
34    return i|0;
35  }
36  return { sext16: sext16 };
37})(stdlib, foreign, buffer).sext16;
38
39assertEquals(-32768, sext16(32768));
40assertEquals(-1, sext16(-1));
41assertEquals(-1, sext16(65535));
42assertEquals(0, sext16(0));
43assertEquals(0, sext16(65536));
44assertEquals(128, sext16(128));
45assertEquals(32767, sext16(32767));
46