Debian Codegraph @

js/src/jit-test/tests/warp/float16-as-float32-specialization-for-math-f16round.js

raw
1 function float32(i) {
2 // Unbox to Int32.
3 i = i|0;
4
5 // Float32 addition.
6 let x = Math.fround(i + 0.1);
7
8 // Float32 square root.
9 let y = Math.fround(Math.sqrt(x));
10
11 // Return as Float16.
12 return Math.f16round(y);
13 }
14
15 function float64(i) {
16 // Unbox to Int32.
17 i = i|0;
18
19 // Float32 addition.
20 let x = Math.fround(i + 0.1);
21
22 // Float64 square root.
23 let y = Math.sqrt(x);
24
25 // Return as Float16.
26 return Math.f16round(y);
27 }
28
29 function toBaseline(f) {
30 let source = f.toString();
31 assertEq(source.at(-1), "}");
32
33 // Add with-statement to disable Ion compilation.
34 source = source.slice(0, -1) + "; with ({}); }";
35
36 return Function(`return ${source};`)();
37 }
38
39 // Different results are expected for these inputs:
40 //
41 // Input Float64-SQRT Float32-SQRT
42 // -----------------------------------
43 // 1527 39.09375 39.0625
44 // 16464 128.375 128.25
45 // 18581 136.375 136.25
46 // 20826 144.375 144.25
47 // 23199 152.375 152.25
48 // 25700 160.375 160.25
49 // 28329 168.375 168.25
50 // 31086 176.375 176.25
51 //
52 // Limit execution to 1550 to avoid spending too much time on this single test.
53 //
54 // 1550 iterations should still be enough to allow tiering up to Ion, at least
55 // under eager compilation settings.
56 const LIMIT = 1550;
57
58 let float32_baseline = toBaseline(float32);
59 let float64_baseline = toBaseline(float64);
60
61 let n = 0;
62 for (let i = 0; i < LIMIT; ++i) {
63 let x = float32(i);
64 assertEq(x, float32_baseline(i));
65
66 let y = float64(i);
67 assertEq(y, float64_baseline(i));
68
69 if (x !== y) {
70 n++;
71 }
72 }
73 assertEq(n, 1);