Skip to content

Commit

Permalink
Show address offsets in hex (#73816)
Browse files Browse the repository at this point in the history
* Show address offsets in hex

* fix the rebase errors

* Add support for arm
  • Loading branch information
kunalspathak committed Aug 15, 2022
1 parent 8d725bf commit 0a2b4eb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
33 changes: 27 additions & 6 deletions src/coreclr/jit/emitarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6770,16 +6770,37 @@ void emitter::emitDispInst(instruction ins, insFlags flags)
*
* Display an immediate value
*/
void emitter::emitDispImm(int imm, bool addComma, bool alwaysHex /* =false */)
void emitter::emitDispImm(int imm, bool addComma, bool alwaysHex /* =false */, bool isAddrOffset /*= false*/)
{
if (!alwaysHex && (imm > -1000) && (imm < 1000))
{
printf("%d", imm);
}
else if ((imm > 0) ||
(imm == -imm) || // -0x80000000 == 0x80000000. So we don't want to add an extra "-" at the beginning.
(emitComp->opts.disDiffable && (imm == (int)0xD1FFAB1E))) // Don't display this as negative
printf("0x%02x", imm);
else // val <= -1000
printf("-0x%02x", -imm);
{
if (isAddrOffset)
{
printf("%02XH", imm);
}
else
{
printf("0x%02x", imm);
}
}
else
{
// val <= -1000
if (isAddrOffset)
{
printf("-%02XH", -imm);
}
else
{
printf("-0x%02x", -imm);
}
}

if (addComma)
printf(", ");
Expand Down Expand Up @@ -6953,7 +6974,7 @@ void emitter::emitDispAddrRI(regNumber reg, int imm, emitAttr attr)
printf("+");
#endif
}
emitDispImm(imm, false, regIsSPorFP);
emitDispImm(imm, false, true, true);
}
printf("]");
emitDispGC(attr);
Expand Down Expand Up @@ -7029,7 +7050,7 @@ void emitter::emitDispAddrPUW(regNumber reg, int imm, insOpts opt, emitAttr attr
printf("+");
#endif
}
emitDispImm(imm, false, regIsSPorFP);
emitDispImm(imm, false, true, true);
}
printf("]");

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/emitarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ unsigned emitOutput_Thumb2Instr(BYTE* dst, code_t code);
/************************************************************************/

void emitDispInst(instruction ins, insFlags flags);
void emitDispImm(int imm, bool addComma, bool alwaysHex = false);
void emitDispImm(int imm, bool addComma, bool alwaysHex = false, bool isAddrOffset = false);
void emitDispReloc(BYTE* addr);
void emitDispCond(int cond);
void emitDispShiftOpts(insOpts opt);
Expand Down
25 changes: 18 additions & 7 deletions src/coreclr/jit/emitarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11790,9 +11790,13 @@ void emitter::emitDispInst(instruction ins)
*
* Display an immediate value
*/
void emitter::emitDispImm(ssize_t imm, bool addComma, bool alwaysHex /* =false */)
void emitter::emitDispImm(ssize_t imm, bool addComma, bool alwaysHex /* =false */, bool isAddrOffset /* =false */)
{
if (strictArmAsm)
if (isAddrOffset)
{
alwaysHex = true;
}
else if (strictArmAsm)
{
printf("#");
}
Expand Down Expand Up @@ -11821,11 +11825,18 @@ void emitter::emitDispImm(ssize_t imm, bool addComma, bool alwaysHex /* =false *

if ((imm & 0xFFFFFFFF00000000LL) != 0)
{
printf("0x%llx", imm);
if (isAddrOffset)
{
printf("%llXH", imm);
}
else
{
printf("0x%llx", imm);
}
}
else
{
printf("0x%02x", (unsigned)imm);
printf("%02XH", (unsigned)imm);
}
}

Expand Down Expand Up @@ -12253,7 +12264,7 @@ void emitter::emitDispAddrRI(regNumber reg, insOpts opt, ssize_t imm)
if (!insOptsPostIndex(opt) && (imm != 0))
{
printf(",");
emitDispImm(imm, false);
emitDispImm(imm, false, true, true);
}
printf("]");

Expand All @@ -12264,7 +12275,7 @@ void emitter::emitDispAddrRI(regNumber reg, insOpts opt, ssize_t imm)
else if (insOptsPostIndex(opt))
{
printf(",");
emitDispImm(imm, false);
emitDispImm(imm, false, true, true);
}
}
else // !strictArmAsm
Expand Down Expand Up @@ -12298,7 +12309,7 @@ void emitter::emitDispAddrRI(regNumber reg, insOpts opt, ssize_t imm)
{
printf("%c", operStr[1]);
}
emitDispImm(imm, false);
emitDispImm(imm, false, true, true);
printf("]");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/emitarm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void emitDispInsHelp(
void emitDispLargeJmp(
instrDesc* id, bool isNew, bool doffs, bool asmfm, unsigned offset, BYTE* pCode, size_t sz, insGroup* ig);
void emitDispInst(instruction ins);
void emitDispImm(ssize_t imm, bool addComma, bool alwaysHex = false);
void emitDispImm(ssize_t imm, bool addComma, bool alwaysHex = false, bool isAddrOffset = false);
void emitDispFloatZero();
void emitDispFloatImm(ssize_t imm8);
void emitDispImmOptsLSL12(ssize_t imm, insOpts opt);
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8710,7 +8710,7 @@ void emitter::emitDispAddrMode(instrDesc* id, bool noDetail)
}
else if (disp < 1000)
{
printf("%d", (unsigned)disp);
printf("%02XH", (unsigned)disp);
}
else if (disp <= 0xFFFF)
{
Expand All @@ -8729,7 +8729,7 @@ void emitter::emitDispAddrMode(instrDesc* id, bool noDetail)
}
else if (disp > -1000)
{
printf("-%d", (unsigned)-disp);
printf("-%02XH", (unsigned)-disp);
}
else if (disp >= -0xFFFF)
{
Expand Down

0 comments on commit 0a2b4eb

Please sign in to comment.