Skip to content

Commit fb752f2

Browse files
authored
Hotfix ieee754 double parsing (#73)
* Update example * Hotfix ieee754 double parsing
1 parent f2e2757 commit fb752f2

6 files changed

Lines changed: 111 additions & 6 deletions

File tree

src/messaging/Parsers.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,24 @@ export function breakpointHitParser(text: string): Breakpoint {
6161
function stacking(objects: {value: any, type: any}[]): WASM.Value[] {
6262
const stacked: WASM.Value[] = [];
6363
for (const object of objects) {
64-
let value: number = object.value;
6564
const type: WASM.Type = WASM.typing.get(object.type.toLowerCase()) ?? WASM.Type.unknown;
66-
if (type === WASM.Type.f32 || type === WASM.Type.f64) {
67-
const buff = Buffer.from(Number(object.value.toString(16)).toString(16), 'hex');
68-
value = ieee754.read(buff, 0, false, type === WASM.Type.f32 ? 23 : 52, buff.length);
65+
let buff;
66+
switch (type) {
67+
case WASM.Type.i32:
68+
case WASM.Type.i64:
69+
stacked.push({value: Number(object.value), type: type});
70+
break;
71+
case WASM.Type.f32:
72+
buff = Buffer.from(Number(object.value.toString(16)).toString(16), 'hex');
73+
stacked.push({value: ieee754.read(buff, 0, false, 23, buff.length), type: type});
74+
break;
75+
case WASM.Type.f64:
76+
buff = Buffer.from(BigInt(object.value.toString(16)).toString(16), 'hex');
77+
stacked.push({value: ieee754.read(buff, 0, false, 52, buff.length), type: type});
78+
break;
79+
case WASM.Type.unknown:
80+
break;
6981
}
70-
stacked.push({value: value, type: type});
7182
}
7283
return stacked;
7384
}

tests/examples/const_133.wast

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(module (func (export "f") (result f32) (f32.const -0x4000.004000001p-64)))

tests/examples/const_160.wast

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(module (func (export "f") (result f32) (f32.const +8.8817857851880284253e-16)))

tests/examples/example.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,54 @@ steps.push(new Invoker('8u_good3', [WASM.i32(0)], WASM.i32(98)));
3333
// ✔ ((invoke "func-unwind-by-br"))
3434
steps.push(new Invoker('func-unwind-by-br', [], undefined));
3535

36+
// ✔ ((invoke "float_exprs_46"))
37+
steps.push(new Invoker('', [], undefined));
38+
39+
40+
3641
spec.test({
3742
title: `Test with address_0.wast`,
3843
program: 'tests/examples/address.wast',
3944
dependencies: [],
4045
steps: steps
4146
});
4247

48+
49+
const floats = framework.suite('Test float parsing'); // must be called first
50+
floats.testee('emulator[:8130]', new EmulatorSpecification(8130));
51+
floats.test({
52+
title: `Test with float_exprs_46.wast`,
53+
program: 'tests/examples/const_160.wast',
54+
dependencies: [],
55+
steps: [
56+
new Invoker('f', [], WASM.f32(8.88178631458362e-16))
57+
]
58+
});
59+
60+
const threethree = framework.suite('Test float parsing'); // must be called first
61+
threethree.testee('emulator[:8180]', new EmulatorSpecification(8180));
62+
threethree.test({
63+
title: `Test with float_exprs_46.wast`,
64+
program: 'tests/examples/const_133.wast',
65+
dependencies: [],
66+
steps: [
67+
new Invoker('f', [], WASM.f32(-8.881785255792436e-16))
68+
]
69+
});
70+
71+
72+
// ✔ ((invoke "copysign" (f64.const -nan) (f64.const -0x0p+0)) (f64.const -nan))
73+
const copysign = framework.suite('Test float parsing'); // must be called first
74+
copysign.testee('emulator[:8190]', new EmulatorSpecification(8190));
75+
copysign.test({
76+
title: `Test copysign`,
77+
program: 'tests/examples/f64_bitwise.wast',
78+
dependencies: [],
79+
steps: [
80+
new Invoker('copysign', [WASM.f64(-NaN), WASM.f32(-0)], WASM.f64(-NaN))
81+
]
82+
});
83+
4384
const debug = framework.suite('Test Debugger interface');
4485
debug.testee('emulator[:8150]', new EmulatorSpecification(8150));
4586

@@ -116,4 +157,4 @@ reverse.test({
116157
})
117158

118159
framework.reporter.verbosity(Verbosity.debug);
119-
framework.analyse([spec, debug]);
160+
framework.analyse([spec, debug, threethree, copysign]);

tests/examples/f64_bitwise.wast

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
(module
3+
(func (export "abs") (param $x f64) (result f64) (f64.abs (local.get $x)))
4+
(func (export "neg") (param $x f64) (result f64) (f64.neg (local.get $x)))
5+
(func (export "copysign") (param $x f64) (param $y f64) (result f64) (f64.copysign (local.get $x) (local.get $y)))
6+
)
7+

tests/examples/float_exprs_46.wast

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
(module
2+
(func (export "f32.no_fold_lt_if_to_abs") (param $x f32) (result f32)
3+
(if (result f32) (f32.lt (local.get $x) (f32.const 0.0))
4+
(then (f32.neg (local.get $x))) (else (local.get $x))
5+
)
6+
)
7+
(func (export "f32.no_fold_le_if_to_abs") (param $x f32) (result f32)
8+
(if (result f32) (f32.le (local.get $x) (f32.const -0.0))
9+
(then (f32.neg (local.get $x))) (else (local.get $x))
10+
)
11+
)
12+
(func (export "f32.no_fold_gt_if_to_abs") (param $x f32) (result f32)
13+
(if (result f32) (f32.gt (local.get $x) (f32.const -0.0))
14+
(then (local.get $x)) (else (f32.neg (local.get $x)))
15+
)
16+
)
17+
(func (export "f32.no_fold_ge_if_to_abs") (param $x f32) (result f32)
18+
(if (result f32) (f32.ge (local.get $x) (f32.const 0.0))
19+
(then (local.get $x)) (else (f32.neg (local.get $x)))
20+
)
21+
)
22+
23+
(func (export "f64.no_fold_lt_if_to_abs") (param $x f64) (result f64)
24+
(if (result f64) (f64.lt (local.get $x) (f64.const 0.0))
25+
(then (f64.neg (local.get $x))) (else (local.get $x))
26+
)
27+
)
28+
(func (export "f64.no_fold_le_if_to_abs") (param $x f64) (result f64)
29+
(if (result f64) (f64.le (local.get $x) (f64.const -0.0))
30+
(then (f64.neg (local.get $x))) (else (local.get $x))
31+
)
32+
)
33+
(func (export "f64.no_fold_gt_if_to_abs") (param $x f64) (result f64)
34+
(if (result f64) (f64.gt (local.get $x) (f64.const -0.0))
35+
(then (local.get $x)) (else (f64.neg (local.get $x)))
36+
)
37+
)
38+
(func (export "f64.no_fold_ge_if_to_abs") (param $x f64) (result f64)
39+
(if (result f64) (f64.ge (local.get $x) (f64.const 0.0))
40+
(then (local.get $x)) (else (f64.neg (local.get $x)))
41+
)
42+
)
43+
)
44+

0 commit comments

Comments
 (0)