Skip to content

Commit 593009b

Browse files
author
Grzegorz Czarnecki
committed
Bugfix
1 parent 4dffd80 commit 593009b

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

src/coreclr/jit/emit.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -993,15 +993,15 @@ class emitter
993993
#elif defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
994994
struct
995995
{
996-
unsigned int iiaEncodedInstr; // instruction's binary encoding.
997996
regNumber _idReg3 : REGNUM_BITS;
998997
regNumber _idReg4 : REGNUM_BITS;
998+
unsigned int iiaEncodedInstr; // instruction's binary encoding.
999999
};
10001000

10011001
struct
10021002
{
1003-
int iiaJmpOffset; // temporary saving the offset of jmp or data.
10041003
emitLclVarAddr iiaLclVar;
1004+
int iiaJmpOffset; // temporary saving the offset of jmp or data.
10051005
};
10061006

10071007
void iiaSetInstrEncode(unsigned int encode)

src/coreclr/jit/emitriscv64.cpp

+31-20
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,9 @@ void emitter::emitIns_R_R(
659659
void emitter::emitIns_R_R_I(
660660
instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, ssize_t imm, insOpts opt /* = INS_OPTS_NONE */)
661661
{
662-
code_t code = emitInsCode(ins);
662+
code_t code = emitInsCode(ins);
663+
instrDesc* id = emitNewInstr(attr);
664+
663665
if ((INS_addi <= ins && INS_srai >= ins) || (INS_addiw <= ins && INS_sraiw >= ins) ||
664666
(INS_lb <= ins && INS_lhu >= ins) || INS_ld == ins || INS_lw == ins || INS_jalr == ins || INS_fld == ins ||
665667
INS_flw == ins)
@@ -688,6 +690,8 @@ void emitter::emitIns_R_R_I(
688690
code |= ((imm >> 1) & 0xf) << 8;
689691
code |= ((imm >> 5) & 0x3f) << 25;
690692
code |= ((imm >> 12) & 0x1) << 31;
693+
// TODO-RISCV64: Move jump logic to emitIns_J
694+
id->idAddr()->iiaSetInstrCount(imm / sizeof(code_t));
691695
}
692696
else if (ins == INS_csrrs || ins == INS_csrrw || ins == INS_csrrc)
693697
{
@@ -702,7 +706,6 @@ void emitter::emitIns_R_R_I(
702706
{
703707
NYI_RISCV64("illegal ins within emitIns_R_R_I!");
704708
}
705-
instrDesc* id = emitNewInstr(attr);
706709

707710
id->idIns(ins);
708711
id->idReg1(reg1);
@@ -2124,22 +2127,22 @@ void emitter::emitOutputInstrJumpDistanceHelper(const insGroup* ig,
21242127
UNATIVE_OFFSET& dstOffs,
21252128
const BYTE*& dstAddr) const
21262129
{
2127-
// TODO-RISCV64-BUG: iiaEncodedInstrCount is not set by the riscv impl making distinguishing the jumps to label and
2128-
// an instruction-count based jumps impossible
2129-
if (jmp->idAddr()->iiaHasInstrCount())
2130-
{
2131-
assert(ig != nullptr);
2132-
int instrCount = jmp->idAddr()->iiaGetInstrCount();
2133-
unsigned insNum = emitFindInsNum(ig, jmp);
2134-
if (instrCount < 0)
2135-
{
2136-
// Backward branches using instruction count must be within the same instruction group.
2137-
assert(insNum + 1 >= static_cast<unsigned>(-instrCount));
2138-
}
2139-
dstOffs = ig->igOffs + emitFindOffset(ig, (insNum + 1 + instrCount));
2140-
dstAddr = emitOffsetToPtr(dstOffs);
2141-
return;
2142-
}
2130+
// TODO-RISCV64: Currently the iiaEncodedInstrCount is not set by any of the emitIns_* methods
2131+
assert(!jmp->idAddr()->iiaHasInstrCount());
2132+
// if (jmp->idAddr()->iiaHasInstrCount())
2133+
// {
2134+
// assert(ig != nullptr);
2135+
// int instrCount = jmp->idAddr()->iiaGetInstrCount();
2136+
// unsigned insNum = emitFindInsNum(ig, jmp);
2137+
// if (instrCount < 0)
2138+
// {
2139+
// // Backward branches using instruction count must be within the same instruction group.
2140+
// assert(insNum + 1 >= static_cast<unsigned>(-instrCount));
2141+
// }
2142+
// dstOffs = ig->igOffs + emitFindOffset(ig, insNum + 1 + instrCount);
2143+
// dstAddr = emitOffsetToPtr(dstOffs);
2144+
// return;
2145+
// }
21432146
dstOffs = jmp->idAddr()->iiaIGlabel->igOffs;
21442147
dstAddr = emitOffsetToPtr(dstOffs);
21452148
}
@@ -2997,10 +3000,18 @@ void emitter::emitDispBranchOffset(const instrDesc* id, const insGroup* ig) cons
29973000
printf("pc%s%d instructions", signFn(instrCount), instrCount);
29983001
return;
29993002
}
3000-
unsigned insNum = emitFindInsNum(ig, id);
3003+
unsigned insNum = emitFindInsNum(ig, id);
3004+
3005+
if (ig->igInsCnt >= insNum + 1 + instrCount)
3006+
{
3007+
// TODO-RISCV64-BUG: This should be a labeled offset but does not contain a label
3008+
printf("pc%s%d instructions", signFn(instrCount), instrCount);
3009+
return;
3010+
}
3011+
30013012
UNATIVE_OFFSET srcOffs = ig->igOffs + emitFindOffset(ig, insNum + 1);
30023013
UNATIVE_OFFSET dstOffs = ig->igOffs + emitFindOffset(ig, insNum + 1 + instrCount);
3003-
ssize_t relOffs = static_cast<ssize_t>(emitOffsetToPtr(dstOffs) - emitOffsetToPtr(dstOffs));
3014+
ssize_t relOffs = static_cast<ssize_t>(emitOffsetToPtr(dstOffs) - emitOffsetToPtr(srcOffs));
30043015
printf("pc%s%d (%d instructions)", signFn(relOffs), static_cast<int>(relOffs), instrCount);
30053016
}
30063017

0 commit comments

Comments
 (0)