Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Checkpoint
  • Loading branch information
kg committed Dec 4, 2025
commit f12c3cc343199efbcf9b6581694f4de8dfbe0112
21 changes: 21 additions & 0 deletions src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,8 +1516,11 @@ void emitter::dispIns(instrDesc* id)
#if EMIT_TRACK_STACK_DEPTH
assert((int)emitCurStackLvl >= 0);
#endif
// FIXME: This is broken for Wasm and I can't figure out why.
#ifndef TARGET_WASM
size_t sz = emitSizeOfInsDsc(id);
assert(id->idDebugOnlyInfo()->idSize == sz);
#endif // TARGET_WASM
#endif // DEBUG

#if EMITTER_STATS
Expand Down Expand Up @@ -10141,6 +10144,24 @@ cnsval_ssize_t emitter::emitGetInsSC(const instrDesc* id)
}
}

#ifdef TARGET_WASM
uint64_t emitter::emitGetInsBits(const instrDesc* id)
{
switch (idInsFmt())
{
case IF_I32:
case IF_I64:
case IF_F32:
case IF_F64:
instrDescWasmConstant *idWC = reinterpret_cast<instrDescWasmConstant *>(id);
return idWC->bits;
default:
unreachable();
return 0;
}
}
#endif

#ifdef TARGET_ARM

BYTE* emitter::emitGetInsRelocValue(instrDesc* id)
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2465,6 +2465,11 @@ class emitter
#endif // TARGET_XARCH

NOT_ARM(static) cnsval_ssize_t emitGetInsSC(const instrDesc* id);

#ifdef TARGET_WASM
uint64_t emitGetInsBits(const instrDesc* id);
#endif // TARGET_WASM

unsigned emitInsCount;

/************************************************************************/
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/emitfmtswasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ IF_DEF(BLOCK, IS_NONE, NONE) // <opcode> <0x40>
IF_DEF(LABEL, IS_NONE, NONE) // <ULEB128 immediate>
IF_DEF(ULEB128, IS_NONE, NONE) // <opcode> <ULEB128 immediate>
IF_DEF(LEB128, IS_NONE, NONE) // <opcode> <LEB128 immediate (signed)>
// The following four formats use instrDescWasmConstant to store 32-64 bits of constant into the output
IF_DEF(I32, IS_NONE, NONE) // <opcode> <LEB128 immediate (signed)>
IF_DEF(I64, IS_NONE, NONE) // <opcode> <LEB128 immediate (signed)>
IF_DEF(F32, IS_NONE, NONE) // <opcode> <f32 immediate>
IF_DEF(F64, IS_NONE, NONE) // <opcode> <f64 immediate>
IF_DEF(MEMARG, IS_NONE, NONE) // <opcode> <memarg> (<align> <offset>)
Expand Down
17 changes: 17 additions & 0 deletions src/coreclr/jit/emitwasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,23 @@ void emitter::emitDispIns(
}
break;

case IF_LEB128:
{
target_ssize_t imm = emitGetInsSC(id);
printf(" %i", imm);
}
break;

case IF_F32:
case IF_F64:
case IF_I32:
case IF_I64:
{
uint64_t bits = emitGetInsBits(id);
printf(" " PRUx64, bits);
}
break;

case IF_MEMARG:
{
// TODO-WASM: decide what our strategy for alignment hints is and display these accordingly.
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5179,7 +5179,7 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
GenTreeIntConCommon* con = tree->AsIntConCommon();
ssize_t imm = con->IconValue();
costEx = 1;
costSz = (int)(tree->IsUnsigned() ? SizeOfULEB128(imm) : SizeOfLEB128(imm));
costSz = 1 + (int)(tree->IsUnsigned() ? SizeOfULEB128(imm) : SizeOfLEB128(imm));
goto COMMON_CNS;
}
#else
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/instrswasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ INST(f32_load, "f32.load", 0, IF_MEMARG, 0x2A)
INST(f64_load, "f64.load", 0, IF_MEMARG, 0x2B)
// 5.4.7 Numeric Instructions
// Constants
INST(i32_const, "i32.const", 0, IF_LEB128, 0x41)
INST(i64_const, "i64.const", 0, IF_LEB128, 0x42)
INST(i32_const, "i32.const", 0, IF_I32, 0x41)
INST(i64_const, "i64.const", 0, IF_I64, 0x42)
INST(f32_const, "f32.const", 0, IF_F32, 0x43)
INST(f64_const, "f64.const", 0, IF_F64, 0x44)
// Integer comparisons
Expand Down