summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/asm/call-stdlib.js
blob: 5d883f324a4f0c55e24c744a16c8272f32c7ac1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax --validate-asm

// This file contains test cases that are particularly interesting because they
// omit the usual call-site coercion of function calls that target well-known
// stdlib functions.

(function SuccessStdlibWithoutAnnotation() {
  function Module(stdlib, imports, heap) {
    "use asm";
    var imul = stdlib.Math.imul;
    function f(a, b) {
      a = a | 0;
      b = b | 0;
      var r = 0;
      r = imul(a, b);
      return r | 0;
    }
    return { f:f };
  }
  var m = Module(this);
  assertTrue(%IsAsmWasmCode(Module));
  assertEquals(966, m.f(23, 42));
  assertEquals(-0x0fffffff, m.f(0x7ffffff, 0x7ffffff));
})();

(function SuccessStdlibWithoutAnnotationThenRound() {
  function Module(stdlib, imports, heap) {
    "use asm";
    var fround = stdlib.Math.fround;
    var imul = stdlib.Math.imul;
    function f(a, b) {
      a = a | 0;
      b = b | 0;
      var r = fround(0);
      r = fround(imul(a, b));
      return fround(r);
    }
    return { f:f };
  }
  var m = Module(this);
  assertTrue(%IsAsmWasmCode(Module));
  assertEquals(966, m.f(23, 42));
  assertEquals(-0x0fffffff - 1, m.f(0x7ffffff, 0x7ffffff));
})();

(function FailureStdlibWithoutAnnotationMismatch() {
  function Module(stdlib, imports, heap) {
    "use asm";
    var fround = stdlib.Math.fround;
    var imul = stdlib.Math.imul;
    function f(a, b) {
      a = a | 0;
      b = b | 0;
      var r = fround(0);
      r = imul(a, b);
      return r | 0;
    }
    return { f:f };
  }
  var m = Module(this);
  assertFalse(%IsAsmWasmCode(Module));
  assertEquals(966, m.f(23, 42));
  assertEquals(-0x0fffffff, m.f(0x7ffffff, 0x7ffffff));
})();

(function SuccessStdlibWithoutAnnotationUsedInReturn() {
  function Module(stdlib, imports, heap) {
    "use asm";
    var imul = stdlib.Math.imul;
    function f(a, b) {
      a = a | 0;
      b = b | 0;
      return imul(a, b);
    }
    return { f:f };
  }
  var m = Module(this);
  assertTrue(%IsAsmWasmCode(Module));
  assertEquals(966, m.f(23, 42));
  assertEquals(-0x0fffffff, m.f(0x7ffffff, 0x7ffffff));
})();