Changed all the register iteration loops to use lsbSet/msbSet functions
that use fast find-first-bit intrinsics when available. Typical loops of
the form:
for (Register r = FirstReg; r <= LastReg; r = nextReg(r))
if (predicate(r))
/* use r */
were transformed by replacing the per-iteration predicate with a single
mask calculation, then iterating through only the 1 bits in the mask:
RegisterMask set = /* calculate predicate with bitmask ops */;
for (Register r = lsReg(set); set; r = lsNextReg(set))
/* use r */
Iteration can be low-to-hi with lsReg/lsNextReg, or hi-to-low with msReg/msNextReg.
Primitives are provided for 32 and 64-bit masks. PPC and MIPS need a 64-bit
mask, for example, even on 32-bit systems.
Refactoring details:
I renamed msbSet() to msbSet32() as part of adding [msb|lsb]Set[32|64], which
affected the AccSet code trivially.
I used if (sizeof(RegisterMask) == 4) to choose between 32 and 64bit
implementations, counting on a sane compiler to strip out the provably dead
path. An alternative would be to move the definitions of lsReg() and msReg() to
NativeXXX.h, after the RegisterMask typedef, allowing backends to hardcode the
choice. Given we have six backends and one more on the way, it seemed better
to centralize the code and also avoid more ifdefs.
I moved the definitions of msbSet/lsbSet to nanojit.h, where other such helpers
already live. It didn't seem appropriate to keep adding to LIR.h since the
helpers will now be used in several places in nanojit.
RegAlloc::managed is now set in Assembler.cpp instead of each backend; six
lines of code replaced by one.
prevreg() was dead after these changes. Additionally, I hand-inlined nextreg()
in the other backends, because the usage was highly specialized -- those call
sites depended on nextreg being reg+1, (or reg+2) not some generic iteration.
I removed RegAlloc::countActive() since the only case was testing countActive()
== 0, which is equivalent to activeMask() == 0.
--HG--
extra : convert_revision : c7009f5cd83ea028b98f59e1f8830a76ba27c1dd