[Patch] MIPS: Fix PR33479 Broken atomic memory primitives.

David Daney ddaney@avtrex.com
Sun Sep 23 09:28:00 GMT 2007


My initial commit of MIPS atomic memory primitives had a couple of 
problems.  The result being that the thread synchronization primitives 
in libgcj would occasionally cause all threads to block forever 
(technically not a deadlock, but with the same results).  I think I 
missed it during initial testing because the test program failed only 
intermittently on a dual CPU machine, but never on the single CPU 
machines I initially used for testing.

The main problem I think was that some insn constraints were missing 
early-clobbers.  Unfortunately a quick perusal of the assembly output of 
the failing functions didn't reveal any places where the missing 
early-clobber looked like it was causing bad code.  However I did see 
the bad code in  a separate test case, so I know that it was not just a 
hypothetical problem.  After fixing the early-clobber problem I was 
never able to get the testcase in the PR to fail, where it would fail 
frequently before.

As part of trying to figure out what was going wrong, I started this 
e-mail thread:

http://gcc.gnu.org/ml/gcc/2007-09/msg00448.html

Where it was pointed out that the primitives were missing a 'sync' and 
that they should use a Branch Likely instead of a normal branch.  I 
folded both of those suggestions into this final patch.

With this patch we now use a Branch Likely unless specifically disabled 
with -mno-branch-likely.  Also there is a 'sync' both before and after 
the atomic sequence.  It was pointed out that for some CPUs a 'sync' 
immediately followed by a 'll' is redundant, but I could see no concrete 
documentation for this so I left it in.

Testing on mipsel-linux-gnu (with dual-core SB1 cpu).

OK to commit if no regressions found?

2007-09-22  David Daney  <ddaney@avtrex.com>

    PR target/33479
    * config/mips/mips.md (sync_compare_and_swap<mode>, sync_old_add<mode>,
    sync_new_add<mode>, sync_old_<optab><mode>, sync_new_<optab><mode>,
    sync_old_nand<mode>, sync_new_nand<mode>,
    sync_lock_test_and_set<mode>): Fix '&' constraint modifiers.  Set
    mips_branch_likely.  Update length attributes.
    (sync_add<mode>, sync_sub<mode>, sync_old_sub<mode>,
    sync_new_sub<mode>, sync_<optab><mode>, sync_nand<mode>): Set
    mips_branch_likely.  Update length attributes.
    * config/mips/mips.h (GENERATE_BRANCHLIKELY_FOR_ATOMIC_OP): Define new
    predicate.
    (MIPS_COMPARE_AND_SWAP, MIPS_SYNC_OP, MIPS_SYNC_OLD_OP,
    MIPS_SYNC_NEW_OP, MIPS_SYNC_NAND, MIPS_SYNC_OLD_NAND,
    MIPS_SYNC_NEW_NAND, MIPS_SYNC_EXCHANGE): Rewrite.
    * doc/invoke.texi (-mbranch-likely): Document option interaction with
    atomic memory operations.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr33479.diff
Type: text/x-patch
Size: 12477 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070923/f3534c19/attachment.bin>


More information about the Gcc-patches mailing list