WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
131146
ARMv7 compare32() should not use TST to do CMP's job
https://bugs.webkit.org/show_bug.cgi?id=131146
Summary
ARMv7 compare32() should not use TST to do CMP's job
Mark Lam
Reported
2014-04-02 21:00:38 PDT
The ARMv7 implementation of "compare32(RegisterID left, TrustedImm32 right)" was being cute and was using "tst reg, reg" to implement "cmp reg, #0". Unfortunately, the tst instruction doesn't set the Overflow (V) flag and this results in random results depending on whether there was a preceeding instruction that did set the Overflow (V) flag. This results in seemingly random manifestations of wrongful behavior that are hard to diagnose. Here's the specific instruction stream I was anaylzing: // initial values: // r3 = 0xa1a1a1a1 // r4 = 0x786bcc7a // r10 = 0xa1a1a1a1 0x66d1b5bc: mov r0, r4 // r0 = 0x786bcc7a 0x66d1b5be: subs r0, r0, r3 // r0 = 0x786bcc7a - 0xa1a1a1a1 = 0xd6ca2ad9, and sets the V flag 0x66d1b5c0: mov r2, r10 // r2 = 0xa1a1a1a1 // Check if r2 < 0: 0x66d1b5c2: tst r2, r2 // Sets the N flag and leaves the V flag 0x66d1b5c4: blt 0x66d1b7dc // "lt" checks if "N != V". Hence, no branch because both N and V are set. 0x66d1b5c8: ldr r9, [r7, #-8] 0x66d1b5cc: mov r8, r9 // r8 = 0x12015037 // Check if r8 < 0: 0x66d1b5ce: tst r8, r8 // Clears the N flag but leaves the V flag set. 0x66d1b5d2: blt 0x66d1b7fe // "lt" checks if "N != V". N is 0. V is 1. Hence, we branch. That second blt is where I see the branch taken when I don't expect it to. The value in r8 (0x12015037) is obviously not less than 0, and the branch should not be taken. The first blt is also wrong. It didn't take the branch when it should have. The value in r2 (0xa1a1a1a1) is obviously less than 0, and the branch should have been taken. The fix is to use "cmp reg, #0" instead of "tst reg, reg" when we actually want to compare to 0.
Attachments
the patch.
(2.34 KB, patch)
2014-04-02 21:09 PDT
,
Mark Lam
ggaren
: review+
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Mark Lam
Comment 1
2014-04-02 21:01:11 PDT
<
rdar://problem/16064304
>
Mark Lam
Comment 2
2014-04-02 21:09:26 PDT
Created
attachment 228459
[details]
the patch.
Geoffrey Garen
Comment 3
2014-04-02 23:06:17 PDT
Comment on
attachment 228459
[details]
the patch. r=me You should mention the test that covers this in your ChangeLog.
Mark Lam
Comment 4
2014-04-03 07:39:15 PDT
Thanks for the review. Landed in
r166716
: <
http://trac.webkit.org/r166716
>.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug