Skip to content

Commit 9e05d33

Browse files
authored
[wasm] Enable jiterpreter traces; fix floating point compares (#81417)
This PR enables jiterpreter traces and fixes a bug in the implementation of floating point compares / floating point branches.
1 parent 00c60e4 commit 9e05d33

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

src/mono/mono/mini/interp/jiterpreter.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,14 @@ mono_jiterp_conv_ovf (void *dest, void *src, int opcode) {
438438
return 0;
439439
}
440440

441+
#define JITERP_CNE_UN_R4 (0xFFFF + 0)
442+
#define JITERP_CGE_UN_R4 (0xFFFF + 1)
443+
#define JITERP_CLE_UN_R4 (0xFFFF + 2)
444+
#define JITERP_CNE_UN_R8 (0xFFFF + 3)
445+
#define JITERP_CGE_UN_R8 (0xFFFF + 4)
446+
#define JITERP_CLE_UN_R8 (0xFFFF + 5)
447+
448+
441449
#define JITERP_RELOP(opcode, type, op, noorder) \
442450
case opcode: \
443451
{ \
@@ -455,10 +463,14 @@ mono_jiterp_relop_fp (double lhs, double rhs, int opcode) {
455463
JITERP_RELOP(MINT_CEQ_R8, double, ==, 0);
456464
JITERP_RELOP(MINT_CNE_R4, float, !=, 1);
457465
JITERP_RELOP(MINT_CNE_R8, double, !=, 1);
466+
JITERP_RELOP(JITERP_CNE_UN_R4, float, !=, 1);
467+
JITERP_RELOP(JITERP_CNE_UN_R8, double, !=, 1);
458468
JITERP_RELOP(MINT_CGT_R4, float, >, 0);
459469
JITERP_RELOP(MINT_CGT_R8, double, >, 0);
460470
JITERP_RELOP(MINT_CGE_R4, float, >=, 0);
461471
JITERP_RELOP(MINT_CGE_R8, double, >=, 0);
472+
JITERP_RELOP(JITERP_CGE_UN_R4, float, >=, 1);
473+
JITERP_RELOP(JITERP_CGE_UN_R8, double, >=, 1);
462474
JITERP_RELOP(MINT_CGT_UN_R4, float, >, 1);
463475
JITERP_RELOP(MINT_CGT_UN_R8, double, >, 1);
464476
JITERP_RELOP(MINT_CLT_R4, float, <, 0);
@@ -467,6 +479,8 @@ mono_jiterp_relop_fp (double lhs, double rhs, int opcode) {
467479
JITERP_RELOP(MINT_CLT_UN_R8, double, <, 1);
468480
JITERP_RELOP(MINT_CLE_R4, float, <=, 0);
469481
JITERP_RELOP(MINT_CLE_R8, double, <=, 0);
482+
JITERP_RELOP(JITERP_CLE_UN_R4, float, <=, 1);
483+
JITERP_RELOP(JITERP_CLE_UN_R8, double, <=, 1);
470484

471485
default:
472486
g_assert_not_reached();

src/mono/mono/utils/options-def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ DEFINE_BOOL(aot_lazy_assembly_load, "aot-lazy-assembly-load", FALSE, "Load assem
6767
// and wasm modules between threads. before these can be enabled we need to implement all that
6868
#ifdef DISABLE_THREADS
6969
// traces_enabled controls whether the jiterpreter will JIT individual interpreter opcode traces
70-
DEFINE_BOOL(jiterpreter_traces_enabled, "jiterpreter-traces-enabled", FALSE, "JIT interpreter opcode traces into WASM")
70+
DEFINE_BOOL(jiterpreter_traces_enabled, "jiterpreter-traces-enabled", TRUE, "JIT interpreter opcode traces into WASM")
7171
// interp_entry_enabled controls whether specialized interp_entry wrappers will be jitted
7272
DEFINE_BOOL(jiterpreter_interp_entry_enabled, "jiterpreter-interp-entry-enabled", TRUE, "JIT specialized WASM interp_entry wrappers")
7373
// jit_call_enabled controls whether do_jit_call will use specialized trampolines for hot call sites

src/mono/wasm/runtime/jiterpreter.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ struct InterpMethod {
128128
void **data_items;
129129
*/
130130

131+
const enum JiterpSpecialOpcode {
132+
CNE_UN_R4 = 0xFFFF + 0,
133+
CGE_UN_R4 = 0xFFFF + 1,
134+
CLE_UN_R4 = 0xFFFF + 2,
135+
CNE_UN_R8 = 0xFFFF + 3,
136+
CGE_UN_R8 = 0xFFFF + 4,
137+
CLE_UN_R8 = 0xFFFF + 5,
138+
}
139+
131140
const enum BailoutReason {
132141
Unknown,
133142
InterpreterTiering,
@@ -1673,7 +1682,6 @@ function emit_fieldop (
16731682
case MintOpcode.MINT_LDSFLD_I4:
16741683
// default
16751684
break;
1676-
// FIXME: These cause grisu3 to break?
16771685
case MintOpcode.MINT_STFLD_R4:
16781686
case MintOpcode.MINT_STSFLD_R4:
16791687
case MintOpcode.MINT_LDFLD_R4:
@@ -1901,6 +1909,12 @@ const intrinsicFpBinops : { [opcode: number] : WasmOpcode } = {
19011909
[MintOpcode.MINT_CLT_UN_R8]: WasmOpcode.nop,
19021910
[MintOpcode.MINT_CLE_R4]: WasmOpcode.f64_promote_f32,
19031911
[MintOpcode.MINT_CLE_R8]: WasmOpcode.nop,
1912+
[JiterpSpecialOpcode.CGE_UN_R4]: WasmOpcode.f64_promote_f32,
1913+
[JiterpSpecialOpcode.CLE_UN_R4]: WasmOpcode.f64_promote_f32,
1914+
[JiterpSpecialOpcode.CNE_UN_R4]: WasmOpcode.f64_promote_f32,
1915+
[JiterpSpecialOpcode.CGE_UN_R8]: WasmOpcode.nop,
1916+
[JiterpSpecialOpcode.CLE_UN_R8]: WasmOpcode.nop,
1917+
[JiterpSpecialOpcode.CNE_UN_R8]: WasmOpcode.nop,
19041918
};
19051919

19061920
const binopTable : { [opcode: number]: OpRec3 | OpRec4 | undefined } = {
@@ -2021,7 +2035,8 @@ const relopbranchTable : { [opcode: number]: [comparisonOpcode: MintOpcode, imme
20212035
[MintOpcode.MINT_BLE_UN_I8_S]: MintOpcode.MINT_CLE_UN_I8,
20222036

20232037
[MintOpcode.MINT_BEQ_I8_IMM_SP]: [MintOpcode.MINT_CEQ_I8, WasmOpcode.i64_const, true],
2024-
[MintOpcode.MINT_BNE_UN_I8_IMM_SP]: [MintOpcode.MINT_CNE_I8, WasmOpcode.i64_const, true],
2038+
// FIXME: Missing compare opcode
2039+
// [MintOpcode.MINT_BNE_UN_I8_IMM_SP]: [MintOpcode.MINT_CNE_UN_I8, WasmOpcode.i64_const, true],
20252040
[MintOpcode.MINT_BGT_I8_IMM_SP]: [MintOpcode.MINT_CGT_I8, WasmOpcode.i64_const, true],
20262041
[MintOpcode.MINT_BGT_UN_I8_IMM_SP]: [MintOpcode.MINT_CGT_UN_I8, WasmOpcode.i64_const, true],
20272042
[MintOpcode.MINT_BLT_I8_IMM_SP]: [MintOpcode.MINT_CLT_I8, WasmOpcode.i64_const, true],
@@ -2032,30 +2047,26 @@ const relopbranchTable : { [opcode: number]: [comparisonOpcode: MintOpcode, imme
20322047
[MintOpcode.MINT_BLE_UN_I8_IMM_SP]: [MintOpcode.MINT_CLE_UN_I8, WasmOpcode.i64_const, true],
20332048

20342049
[MintOpcode.MINT_BEQ_R4_S]: MintOpcode.MINT_CEQ_R4,
2035-
[MintOpcode.MINT_BNE_UN_R4_S]: MintOpcode.MINT_CNE_R4,
2050+
[MintOpcode.MINT_BNE_UN_R4_S]: <any>JiterpSpecialOpcode.CNE_UN_R4,
20362051
[MintOpcode.MINT_BGT_R4_S]: MintOpcode.MINT_CGT_R4,
20372052
[MintOpcode.MINT_BGT_UN_R4_S]: MintOpcode.MINT_CGT_UN_R4,
20382053
[MintOpcode.MINT_BLT_R4_S]: MintOpcode.MINT_CLT_R4,
20392054
[MintOpcode.MINT_BLT_UN_R4_S]: MintOpcode.MINT_CLT_UN_R4,
20402055
[MintOpcode.MINT_BGE_R4_S]: MintOpcode.MINT_CGE_R4,
2041-
// FIXME: No compare opcode for this
2042-
[MintOpcode.MINT_BGE_UN_R4_S]: MintOpcode.MINT_CGE_R4,
2056+
[MintOpcode.MINT_BGE_UN_R4_S]: <any>JiterpSpecialOpcode.CGE_UN_R4,
20432057
[MintOpcode.MINT_BLE_R4_S]: MintOpcode.MINT_CLE_R4,
2044-
// FIXME: No compare opcode for this
2045-
[MintOpcode.MINT_BLE_UN_R4_S]: MintOpcode.MINT_CLE_R4,
2058+
[MintOpcode.MINT_BLE_UN_R4_S]: <any>JiterpSpecialOpcode.CLE_UN_R4,
20462059

20472060
[MintOpcode.MINT_BEQ_R8_S]: MintOpcode.MINT_CEQ_R8,
2048-
[MintOpcode.MINT_BNE_UN_R8_S]: MintOpcode.MINT_CNE_R8,
2061+
[MintOpcode.MINT_BNE_UN_R8_S]: <any>JiterpSpecialOpcode.CNE_UN_R8,
20492062
[MintOpcode.MINT_BGT_R8_S]: MintOpcode.MINT_CGT_R8,
20502063
[MintOpcode.MINT_BGT_UN_R8_S]: MintOpcode.MINT_CGT_UN_R8,
20512064
[MintOpcode.MINT_BLT_R8_S]: MintOpcode.MINT_CLT_R8,
20522065
[MintOpcode.MINT_BLT_UN_R8_S]: MintOpcode.MINT_CLT_UN_R8,
20532066
[MintOpcode.MINT_BGE_R8_S]: MintOpcode.MINT_CGE_R8,
2054-
// FIXME: No compare opcode for this
2055-
[MintOpcode.MINT_BGE_UN_R8_S]: MintOpcode.MINT_CGE_R8,
2067+
[MintOpcode.MINT_BGE_UN_R8_S]: <any>JiterpSpecialOpcode.CGE_UN_R8,
20562068
[MintOpcode.MINT_BLE_R8_S]: MintOpcode.MINT_CLE_R8,
2057-
// FIXME: No compare opcode for this
2058-
[MintOpcode.MINT_BLE_UN_R8_S]: MintOpcode.MINT_CLE_R8,
2069+
[MintOpcode.MINT_BLE_UN_R8_S]: <any>JiterpSpecialOpcode.CLE_UN_R8,
20592070
};
20602071

20612072
function emit_binop (builder: WasmBuilder, ip: MintOpcodePtr, opcode: MintOpcode) : boolean {
@@ -2466,14 +2477,14 @@ function emit_relop_branch (builder: WasmBuilder, ip: MintOpcodePtr, opcode: Min
24662477
const operandLoadOp = relopInfo
24672478
? relopInfo[1]
24682479
: (
2469-
intrinsicFpBinop == WasmOpcode.nop
2480+
intrinsicFpBinop === WasmOpcode.nop
24702481
? WasmOpcode.f64_load
24712482
: WasmOpcode.f32_load
24722483
);
24732484

24742485
append_ldloc(builder, getArgU16(ip, 1), operandLoadOp);
24752486
// Promote f32 lhs to f64 if necessary
2476-
if (!relopInfo && (intrinsicFpBinop != WasmOpcode.nop))
2487+
if (!relopInfo && (intrinsicFpBinop !== WasmOpcode.nop))
24772488
builder.appendU8(intrinsicFpBinop);
24782489

24792490
// Compare with immediate

0 commit comments

Comments
 (0)