Debian Codegraph @

js/src/jit-test/tests/wasm/float.js

raw
1 wasmFullPass('(module (func (result f32) (f32.const -1)) (export "run" (func 0)))', -1);
2 wasmFullPass('(module (func (result f32) (f32.const 1)) (export "run" (func 0)))', 1);
3 wasmFullPass('(module (func (result f64) (f64.const -2)) (export "run" (func 0)))', -2);
4 wasmFullPass('(module (func (result f64) (f64.const 2)) (export "run" (func 0)))', 2);
5 wasmFullPass('(module (func (result f64) (f64.const 4294967296)) (export "run" (func 0)))', 4294967296);
6 wasmFullPass('(module (func (result f32) (f32.const 1.5)) (export "run" (func 0)))', 1.5);
7 wasmFullPass('(module (func (result f64) (f64.const 2.5)) (export "run" (func 0)))', 2.5);
8 wasmFullPass('(module (func (result f64) (f64.const 10e2)) (export "run" (func 0)))', 10e2);
9 wasmFullPass('(module (func (result f32) (f32.const 10e2)) (export "run" (func 0)))', 10e2);
10 wasmFullPass('(module (func (result f64) (f64.const -0x8000000000000000)) (export "run" (func 0)))', -0x8000000000000000);
11 wasmFullPass('(module (func (result f64) (f64.const -9223372036854775808)) (export "run" (func 0)))', -9223372036854775808);
12 wasmFullPass('(module (func (result f64) (f64.const 1797693134862315708145274e284)) (export "run" (func 0)))', 1797693134862315708145274e284);
13
14 function testUnary(type, opcode, op, expect) {
15 wasmFullPass('(module (func (param ' + type + ') (result ' + type + ') (' + type + '.' + opcode + ' (local.get 0))) (export "run" (func 0)))',
16 expect,
17 {},
18 op);
19 }
20
21 function testBinary(type, opcode, lhs, rhs, expect) {
22 wasmFullPass('(module (func (param ' + type + ') (param ' + type + ') (result ' + type + ') (' + type + '.' + opcode + ' (local.get 0) (local.get 1))) (export "run" (func 0)))',
23 expect,
24 {},
25 lhs, rhs);
26 }
27
28 function testComparison(type, opcode, lhs, rhs, expect) {
29 wasmFullPass('(module (func (param ' + type + ') (param ' + type + ') (result i32) (' + type + '.' + opcode + ' (local.get 0) (local.get 1))) (export "run" (func 0)))',
30 expect,
31 {},
32 lhs, rhs);
33 }
34
35 testUnary('f32', 'abs', -40, 40);
36 testUnary('f32', 'neg', 40, -40);
37 testUnary('f32', 'floor', 40.9, 40);
38 testUnary('f32', 'ceil', 40.1, 41);
39 testUnary('f32', 'nearest', -41.5, -42);
40 testUnary('f32', 'trunc', -41.5, -41);
41 testUnary('f32', 'sqrt', 40, 6.324555397033691);
42
43 testBinary('f32', 'add', 40, 2, 42);
44 testBinary('f32', 'sub', 40, 2, 38);
45 testBinary('f32', 'mul', 40, 2, 80);
46 testBinary('f32', 'div', 40, 3, 13.333333015441895);
47 testBinary('f32', 'min', 40, 2, 2);
48 testBinary('f32', 'max', 40, 2, 40);
49 testBinary('f32', 'copysign', 40, -2, -40);
50
51 testComparison('f32', 'eq', 40, 40, 1);
52 testComparison('f32', 'ne', 40, 40, 0);
53 testComparison('f32', 'lt', 40, 40, 0);
54 testComparison('f32', 'le', 40, 40, 1);
55 testComparison('f32', 'gt', 40, 40, 0);
56 testComparison('f32', 'ge', 40, 40, 1);
57
58 testUnary('f64', 'abs', -40, 40);
59 testUnary('f64', 'neg', 40, -40);
60 testUnary('f64', 'floor', 40.9, 40);
61 testUnary('f64', 'ceil', 40.1, 41);
62 testUnary('f64', 'nearest', -41.5, -42);
63 testUnary('f64', 'trunc', -41.5, -41);
64 testUnary('f64', 'sqrt', 40, 6.324555320336759);
65
66 testBinary('f64', 'add', 40, 2, 42);
67 testBinary('f64', 'sub', 40, 2, 38);
68 testBinary('f64', 'mul', 40, 2, 80);
69 testBinary('f64', 'div', 40, 3, 13.333333333333334);
70 testBinary('f64', 'min', 40, 2, 2);
71 testBinary('f64', 'max', 40, 2, 40);
72 testBinary('f64', 'copysign', 40, -2, -40);
73
74 testComparison('f64', 'eq', 40, 40, 1);
75 testComparison('f64', 'ne', 40, 40, 0);
76 testComparison('f64', 'lt', 40, 40, 0);
77 testComparison('f64', 'le', 40, 40, 1);
78 testComparison('f64', 'gt', 40, 40, 0);
79 testComparison('f64', 'ge', 40, 40, 1);
80
81 wasmFailValidateText('(module (func (param i32) (result f32) (f32.sqrt (local.get 0))))', mismatchError("i32", "f32"));
82 wasmFailValidateText('(module (func (param f32) (result i32) (f32.sqrt (local.get 0))))', mismatchError("f32", "i32"));
83 wasmFailValidateText('(module (func (param i32) (result i32) (f32.sqrt (local.get 0))))', mismatchError("i32", "f32"));
84 wasmFailValidateText('(module (func (param i32) (result f64) (f64.sqrt (local.get 0))))', mismatchError("i32", "f64"));
85 wasmFailValidateText('(module (func (param f64) (result i32) (f64.sqrt (local.get 0))))', mismatchError("f64", "i32"));
86 wasmFailValidateText('(module (func (param i32) (result i32) (f64.sqrt (local.get 0))))', mismatchError("i32", "f64"));
87 wasmFailValidateText('(module (func (f32.sqrt (nop))))', /(popping value from empty stack)|(type mismatch: expected f32 but nothing on stack)/);
88
89 wasmFailValidateText('(module (func (param i32) (param f32) (result f32) (f32.add (local.get 0) (local.get 1))))', mismatchError("i32", "f32"));
90 wasmFailValidateText('(module (func (param f32) (param i32) (result f32) (f32.add (local.get 0) (local.get 1))))', mismatchError("i32", "f32"));
91 wasmFailValidateText('(module (func (param f32) (param f32) (result i32) (f32.add (local.get 0) (local.get 1))))', mismatchError("f32", "i32"));
92 wasmFailValidateText('(module (func (param i32) (param i32) (result i32) (f32.add (local.get 0) (local.get 1))))', mismatchError("i32", "f32"));
93 wasmFailValidateText('(module (func (param i32) (param f64) (result f64) (f64.add (local.get 0) (local.get 1))))', mismatchError("i32", "f64"));
94 wasmFailValidateText('(module (func (param f64) (param i32) (result f64) (f64.add (local.get 0) (local.get 1))))', mismatchError("i32", "f64"));
95 wasmFailValidateText('(module (func (param f64) (param f64) (result i32) (f64.add (local.get 0) (local.get 1))))', mismatchError("f64", "i32"));
96 wasmFailValidateText('(module (func (param i32) (param i32) (result i32) (f64.add (local.get 0) (local.get 1))))', mismatchError("i32", "f64"));
97
98 wasmFailValidateText('(module (func (param i32) (param f32) (result f32) (f32.eq (local.get 0) (local.get 1))))', mismatchError("i32", "f32"));
99 wasmFailValidateText('(module (func (param f32) (param i32) (result f32) (f32.eq (local.get 0) (local.get 1))))', mismatchError("i32", "f32"));
100 wasmFailValidateText('(module (func (param f32) (param f32) (result f32) (f32.eq (local.get 0) (local.get 1))))', mismatchError("i32", "f32"));
101 wasmFailValidateText('(module (func (param i32) (param f64) (result f64) (f64.eq (local.get 0) (local.get 1))))', mismatchError("i32", "f64"));
102 wasmFailValidateText('(module (func (param f64) (param i32) (result f64) (f64.eq (local.get 0) (local.get 1))))', mismatchError("i32", "f64"));
103 wasmFailValidateText('(module (func (param f64) (param f64) (result f64) (f64.eq (local.get 0) (local.get 1))))', mismatchError("i32", "f64"));