Closed Bug 1421993 Opened 8 years ago Closed 8 years ago

Wasm baseline: Clean up scratch register management further

Categories

(Core :: JavaScript Engine: JIT, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
mozilla59
Tracking Status
firefox59 --- fixed

People

(Reporter: lth, Assigned: lth)

References

Details

Attachments

(2 files)

Scratch registers were cleaned up some in bug 1419025, but while working on the ARM64 port I found a way to clean them up further via a simple subclassing scheme. This also simplifies the initialization of scratch registers some (see bug 1419034 comment 7).
Comment on attachment 8934090 [details] Bug 1421993 - rabaldr, abstract platform-specific registers and clean up ifdefs. https://reviewboard.mozilla.org/r/205042/#review210616 SHIPIT! Are there/do we expect some platforms to be JS_64BIT while not being JS_PUNBOX64?
Attachment #8934090 - Flags: review?(bbouvier) → review+
Comment on attachment 8934089 [details] Bug 1421993 - rabaldr, simplify scratch register management. https://reviewboard.mozilla.org/r/205040/#review210610 I like the idea, but I don't like #define for statically known values. Also one new macro is never defined, unless I missed something? I'd like to have another look please, otherwise the patch looks good. ::: js/src/wasm/WasmBaselineCompile.cpp:152 (Diff revision 1) > > +#if defined(JS_CODEGEN_ARM64) || defined(JS_CODEGEN_NONE) || \ > + defined(JS_CODEGEN_MIPS32) || defined(JS_CODEGEN_MIPS64) > +# define RABALDR_SCRATCH_I32 Register::Invalid() > +# define RABALDR_SCRATCH_F32 InvalidFloatReg > +# define RABALDR_SCRATCH_F64 InvalidFloatReg Instead of defines, can you make them all `static const Register/FloatRegister` or `constexpr`, please? (I see these are used for testing in `ifdef` below, but this should be a separate defined key with no value, like the CALLOUT macro markers, I think) ::: js/src/wasm/WasmBaselineCompile.cpp:193 (Diff revision 1) > + > +// The compiler will not use both the F32 and F64 scratch registers at the same > +// time and they can alias (without necessarily being equal, of course). Try to > +// ensure that the configuration is sane if so. > + > +#if defined(RABALDR_SCRATCH_F32_ALIASES_F64) This doesn't seem to be defined anywhere? It should be on ARM32 at least. ::: js/src/wasm/WasmBaselineCompile.cpp:500 (Diff revision 1) > + MOZ_ASSERT(availFPU.has(RABALDR_SCRATCH_F32)); > +# endif > + if (RABALDR_SCRATCH_F64 != RegF64::Invalid()) > + availFPU.take(RABALDR_SCRATCH_F64); > +# if defined(RABALDR_SCRATCH_F32_ALIASES_F64) > + MOZ_ASSERT(!availFPU.has(RABALDR_SCRATCH_F32)); I think this assertion will blow up when RABALDR_SCRATCH_F64 is an invalid register. ::: js/src/wasm/WasmBaselineCompile.cpp:510 (Diff revision 1) > allGPR = availGPR; > allFPU = availFPU; > #endif > } > > + enum class Scratch { maybe ScratchKind, or ScratchRegisterKind? or even ScratchRegisterType? ::: js/src/wasm/WasmBaselineCompile.cpp:517 (Diff revision 1) > + F32 = 2, > + F64 = 4 > + }; > + > #ifdef DEBUG > - bool scratchRegisterTaken() const { > + bool scratchRegisterTaken(Scratch s) const { nit: can you prefix with `is`, since this method returns a bool, please?
Attachment #8934089 - Flags: review?(bbouvier)
(In reply to Benjamin Bouvier [:bbouvier] from comment #3) > Comment on attachment 8934090 [details] > Bug 1421993 - Abstract platform-specific registers, cleanup ifdefs. > > https://reviewboard.mozilla.org/r/205042/#review210616 > > SHIPIT! Are there/do we expect some platforms to be JS_64BIT while not being > JS_PUNBOX64? That's a question I've been asking myself too. Technically JS_PUNBOX64 relates to the "reg" vs "high"/"low" registers in a Register64. And JS_PUNBOX64 almost certainly implies JS_64BIT, but that does not give us much. You could imagine a 32-bit architecture with a provision for "extended" 64-bit registers, in fact the "x32" architecture that sometimes comes up in discussions would be that (essentially, running 32-bit code on x64 to have access to more registers and other goodies, https://en.wikipedia.org/wiki/X32_ABI). This 32-bit architecture would have different Register64 layout and would not be !JS_PUNBOX64, but it would also be !JS_64BIT. Were we to support it we would only need to look at the bits of code that are !JS_PUNBOX64. Indeed most 64-bit CPUs I know have good support for 32-bit code and could use a similar scheme for data compactness. Even if x32 seems to have mostly died it's not particularly far-fetched. One could argue Wasm is one such scheme :)
Comment on attachment 8934089 [details] Bug 1421993 - rabaldr, simplify scratch register management. https://reviewboard.mozilla.org/r/205040/#review211432 ::: js/src/wasm/WasmBaselineCompile.cpp:193 (Diff revision 1) > + > +// The compiler will not use both the F32 and F64 scratch registers at the same > +// time and they can alias (without necessarily being equal, of course). Try to > +// ensure that the configuration is sane if so. > + > +#if defined(RABALDR_SCRATCH_F32_ALIASES_F64) This construct actually comes in from the ARM64 WIP and it's a little tricky. This define is only meant to be defined if the *private* scratch registers are defined and alias; it has no bearing on the standard scratch registers (which we use on x86, x64, and ARM32). I have removed this thing since it's not currently in use, it's easy to add it back later and we know it can be done. Speaking of ARM32, while it is true that the standard float scratch registers alias here, it is far from obvious. The reason is that the float32 scratch register defn on ARM references a double register 'd30' that does not have a single component, so that's silly. But: other parts of the code seem to assume this should be 's30', which would be right, and the 'd30' register has a bit value that does not actually fit in the code_ field of a VFPRegister but would silently coerce to the value of 's30'... I guess I'll investigate and file a followup bug. ::: js/src/wasm/WasmBaselineCompile.cpp:500 (Diff revision 1) > + MOZ_ASSERT(availFPU.has(RABALDR_SCRATCH_F32)); > +# endif > + if (RABALDR_SCRATCH_F64 != RegF64::Invalid()) > + availFPU.take(RABALDR_SCRATCH_F64); > +# if defined(RABALDR_SCRATCH_F32_ALIASES_F64) > + MOZ_ASSERT(!availFPU.has(RABALDR_SCRATCH_F32)); Issue went away because the handling of aliases was removed, for now. ::: js/src/wasm/WasmBaselineCompile.cpp:510 (Diff revision 1) > allGPR = availGPR; > allFPU = availFPU; > #endif > } > > + enum class Scratch { Oy, verbose. I guess "ScratchKind" is manageable. ::: js/src/wasm/WasmBaselineCompile.cpp:517 (Diff revision 1) > + F32 = 2, > + F64 = 4 > + }; > + > #ifdef DEBUG > - bool scratchRegisterTaken() const { > + bool scratchRegisterTaken(Scratch s) const { Yes.
Comment on attachment 8934089 [details] Bug 1421993 - rabaldr, simplify scratch register management. https://reviewboard.mozilla.org/r/205040/#review211452 Thanks! ::: js/src/wasm/WasmBaselineCompile.cpp:195 (Diff revision 2) > # define RABALDR_INT_DIV_I64_CALLOUT > # define RABALDR_I64_TO_FLOAT_CALLOUT > # define RABALDR_FLOAT_TO_I64_CALLOUT > #endif > > + nit: blank line
Attachment #8934089 - Flags: review?(bbouvier) → review+
Pushed by lhansen@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/b9aa0390c430 rabaldr, simplify scratch register management. r=bbouvier https://hg.mozilla.org/integration/mozilla-inbound/rev/e49d8769f50a rabaldr, abstract platform-specific registers and clean up ifdefs. r=bbouvier
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla59
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: