Skip to content

Commit 333fb71

Browse files
authored
Optimize flips between 1 and 0 (#100491)
We can solve this with a bit flip rather than + 1 mod 2.
1 parent 55c9040 commit 333fb71

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/coreclr/jit/compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ const char* Compiler::compRegVarName(regNumber reg, bool displayVar, bool isFloa
21932193
// consecutive calls before printing
21942194
static int index = 0; // for circular index into the name array
21952195

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

21992199
return nameVarReg[index];

src/coreclr/jit/emitxarch.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10102,7 +10102,7 @@ const char* emitter::emitRegName(regNumber reg, emitAttr attr, bool varName) con
1010210102
suffix = 'd';
1010310103
goto APPEND_SUFFIX;
1010410104
}
10105-
rbc = (rbc + 1) % 2;
10105+
rbc ^= 1;
1010610106
rb[rbc][0] = 'e';
1010710107
rb[rbc][1] = rn[1];
1010810108
rb[rbc][2] = rn[2];
@@ -10133,7 +10133,7 @@ const char* emitter::emitRegName(regNumber reg, emitAttr attr, bool varName) con
1013310133
{
1013410134
suffix = 'b';
1013510135
APPEND_SUFFIX:
10136-
rbc = (rbc + 1) % 2;
10136+
rbc ^= 1;
1013710137
rb[rbc][0] = rn[0];
1013810138
rb[rbc][1] = rn[1];
1013910139
if (rn[2])
@@ -10151,7 +10151,7 @@ const char* emitter::emitRegName(regNumber reg, emitAttr attr, bool varName) con
1015110151
}
1015210152
else
1015310153
{
10154-
rbc = (rbc + 1) % 2;
10154+
rbc ^= 1;
1015510155
rb[rbc][0] = rn[1];
1015610156
if (reg < 4)
1015710157
{
@@ -10168,7 +10168,7 @@ const char* emitter::emitRegName(regNumber reg, emitAttr attr, bool varName) con
1016810168
#endif // TARGET_AMD64
1016910169

1017010170
#if defined(TARGET_X86)
10171-
rbc = (rbc + 1) % 2;
10171+
rbc ^= 1;
1017210172
rb[rbc][0] = rn[1];
1017310173
rb[rbc][1] = 'l';
1017410174
strcpy_s(&rb[rbc][2], sizeof(rb[0]) - 2, rn + 3);

src/coreclr/vm/gc_unwind_x86.inl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,10 +1670,7 @@ unsigned scanArgRegTableI(PTR_CBYTE table,
16701670
{
16711671
thisPtrReg = REGI_NA;
16721672
}
1673-
if (iptrRegs & regMask)
1674-
{
1675-
iptrRegs &= ~regMask;
1676-
}
1673+
iptrRegs &= ~regMask;
16771674
}
16781675
iptr = isThis = false;
16791676
continue;

0 commit comments

Comments
 (0)