Skip to content

Commit

Permalink
Optimize flips between 1 and 0 (dotnet#100491)
Browse files Browse the repository at this point in the history
We can solve this with a bit flip rather than + 1 mod 2.
  • Loading branch information
AtariDreams authored and matouskozak committed Apr 30, 2024
1 parent 0d25772 commit 5b45b35
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,7 @@ const char* Compiler::compRegVarName(regNumber reg, bool displayVar, bool isFloa
// consecutive calls before printing
static int index = 0; // for circular index into the name array

index = (index + 1) % 2; // circular reuse of index
index ^= 1; // circular reuse of index
sprintf_s(nameVarReg[index], NAME_VAR_REG_BUFFER_LEN, "%s'%s'", getRegName(reg), VarNameToStr(varName));

return nameVarReg[index];
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10102,7 +10102,7 @@ const char* emitter::emitRegName(regNumber reg, emitAttr attr, bool varName) con
suffix = 'd';
goto APPEND_SUFFIX;
}
rbc = (rbc + 1) % 2;
rbc ^= 1;
rb[rbc][0] = 'e';
rb[rbc][1] = rn[1];
rb[rbc][2] = rn[2];
Expand Down Expand Up @@ -10133,7 +10133,7 @@ const char* emitter::emitRegName(regNumber reg, emitAttr attr, bool varName) con
{
suffix = 'b';
APPEND_SUFFIX:
rbc = (rbc + 1) % 2;
rbc ^= 1;
rb[rbc][0] = rn[0];
rb[rbc][1] = rn[1];
if (rn[2])
Expand All @@ -10151,7 +10151,7 @@ const char* emitter::emitRegName(regNumber reg, emitAttr attr, bool varName) con
}
else
{
rbc = (rbc + 1) % 2;
rbc ^= 1;
rb[rbc][0] = rn[1];
if (reg < 4)
{
Expand All @@ -10168,7 +10168,7 @@ const char* emitter::emitRegName(regNumber reg, emitAttr attr, bool varName) con
#endif // TARGET_AMD64

#if defined(TARGET_X86)
rbc = (rbc + 1) % 2;
rbc ^= 1;
rb[rbc][0] = rn[1];
rb[rbc][1] = 'l';
strcpy_s(&rb[rbc][2], sizeof(rb[0]) - 2, rn + 3);
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/vm/gc_unwind_x86.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1670,10 +1670,7 @@ unsigned scanArgRegTableI(PTR_CBYTE table,
{
thisPtrReg = REGI_NA;
}
if (iptrRegs & regMask)
{
iptrRegs &= ~regMask;
}
iptrRegs &= ~regMask;
}
iptr = isThis = false;
continue;
Expand Down

0 comments on commit 5b45b35

Please sign in to comment.