Closed Bug 483962 Opened 15 years ago Closed 15 years ago

Remove ARM-specific code from jstracer.cpp.

Categories

(Core :: JavaScript Engine, defect)

ARM
All
defect
Not set
trivial

Tracking

()

VERIFIED FIXED

People

(Reporter: jbramley, Assigned: jbramley)

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file, 5 obsolete files)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.7) Gecko/2009030422 Ubuntu/8.04 (hardy) Firefox/3.0.7
Build Identifier: http://hg.mozilla.org/tracemonkey/file/809a092500db

The file "js/src/jstracer.cpp" appears to be mostly generally architecture-independent, but some patch-up code exists to make shift operations work as expected on ARM*. In Tamarin, this was fixed by inserting an extra native instruction in NativeARM.cpp, and this method is more consistent with the way that Trace Monkey works.

This patch _may_ improve performance a tiny amount as it removes an LIR instruction for every shift operation that is performed, but in practice it won't have any noticeable effect. This is a tidy-up bug.

* JavaScript's shift instruction uses only the bottom 5 bits of the shift operand, and x86 does the same (I believe). On ARM, however, the whole bottom byte of the shift operand is used, and so an extra AND instruction is required to match the specified JavaScript behaviour.

Reproducible: Always
Hardware: Other → ARM
Patch added. Also adds ANDri to NativeARM.h to allow rX = rY & imm. Passes all tests that passed previously.
Attached patch Repaired patch. (obsolete) — Splinter Review
Sorry, I did the diff backwards. New patch attached.
Attachment #367989 - Attachment is obsolete: true
Attachment #367990 - Flags: review?(vladimir)
Status: UNCONFIRMED → NEW
Ever confirmed: true
Comment on attachment 367990 [details] [diff] [review]
Repaired patch.

I think that this part is right, but I think you also need to modify the SHLi/SARi/SHRi macros to add the &0x1f to the immediate value.. otherwise if the rhs value is a constant, we'll get a bogus instruction being generated since they don't mask.

But I think some more stuff will need to be changed -- the start of asm_arith sets forceReg to true if rhs->constval() is not a U8.. but that doesn't need to be true for shifts, since we'll mask it anyway.
Attachment #367990 - Flags: review?(vladimir) → review-
Oh, sounds like we need to add another test to trace-tests to catch this, if nothing broke... I think a shift with a value > 31 but less than 255 should cause brokenness.
(In reply to comment #3)
> (From update of attachment 367990 [details] [diff] [review])
> I think that this part is right, but I think you also need to modify the
> SHLi/SARi/SHRi macros to add the &0x1f to the immediate value.. otherwise if
> the rhs value is a constant, we'll get a bogus instruction being generated
> since they don't mask.

Good point. I added them in NativeARM.cpp but they'd be much better in the macros themselves.

I will produce an updated patch shortly.

> But I think some more stuff will need to be changed -- the start of asm_arith
> sets forceReg to true if rhs->constval() is not a U8.. but that doesn't need to
> be true for shifts, since we'll mask it anyway.

Ah yes. I hadn't spotted that. This is a simple fix so I'll add it to the patch.
* Move the ARM-specific extra AND instruction to NativeARM.cpp.
* Never force register assignment for shift instructions as they're all masked to 0x1f anyway, and will always fit in an ARM immediate value.
* Modified SHLi, SARi and SHRi such that they always mask the immediate value, to avoid the possibility of creating invalid or unexpected instructions.
* Added ANDri, to allow _l = _r AND _imm.
* Added tests to trace-tests.js to detect errors in the shift operation.
Assignee: general → Jacob.Bramley
Attachment #367990 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #368256 - Flags: review?(vladimir)
Comment on attachment 368256 [details] [diff] [review]
Move extra AND instruction to NativeARM.cpp and add some trace tests to test it.

Looks good, one nit:

>--- a/js/src/nanojit/NativeARM.cpp
>+++ b/js/src/nanojit/NativeARM.cpp
>@@ -1300,8 +1300,11 @@
>     // outside of +/-255 (for AND) r outside of
>     // 0..255 for others.
>     if (!forceReg) {
>-        if (rhs->isconst() && !isU8(rhs->constval()))
>-            forceReg = true;
>+        // Shift operations are masked with 0x1f anyway, so there's no need to
>+        // force register assignment in these cases.
>+        if ((op != LIR_lsh) && (op != LIR_rsh) && (op != LIR_ush))
>+            if (rhs->isconst() && !isU8(rhs->constval()))
>+                forceReg = true;

Can you combine these two if statements into one?  Just chain the &&'s.

If you fix that up, can you upload a new patch and poke someone on #jsapi to check in (or I can do it in the next few days)?
Attachment #368256 - Flags: review?(vladimir) → review+
* Style changes made as requested.
 * Re-synchronized with the TM tree as the previous patch did not apply cleanly.
Attachment #368256 - Attachment is obsolete: true
Needs checkin on tracemonkey.
Keywords: checkin-needed
Attached patch Re-synchronization with tree. (obsolete) — Splinter Review
Attachment #369054 - Attachment is obsolete: true
sigh, this rotted again. :(

I didn't know these patches were floating around. I'll get this checked in immediately if you unbitrot it.
Attachment #371859 - Attachment is obsolete: true
http://hg.mozilla.org/tracemonkey/rev/56634a652940
Keywords: checkin-needed
Whiteboard: fixed-in-tracemonkey
Great test-cases (for non-ARM platforms, too). Thanks!
http://hg.mozilla.org/mozilla-central/rev/56634a652940
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
js1_8_1/trace/trace-test.js	
http://hg.mozilla.org/tracemonkey/rev/61892f57b46a
Flags: in-testsuite+
cvsroot/mozilla/js/tests/js1_8_1/trace/trace-test.js,v  <--  trace-test.js
new revision: 1.14; previous revision: 1.13

/cvsroot/mozilla/js/tests/shell.js,v  <--  shell.js
testShiftLeft|testShiftRightLogical|testShiftRightArithmetic
v 1.9.3
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: