Ignore:
Timestamp:
Dec 7, 2011, 6:09:14 PM (13 years ago)
Author:
[email protected]
Message:

Compare and Swap should be enabled on ARMv7
https://bugs.webkit.org/show_bug.cgi?id=74023

Reviewed by Geoff Garen.

Implemented weakCompareAndSwap in terms of LDREX/STREX and enabled PARALLEL_GC.
It gives the expected speed-up on multi-core ARMv7 devices.

  • wtf/Atomics.h:

(WTF::weakCompareAndSwap):

  • wtf/Platform.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/wtf/Atomics.h

    r99374 r102295  
    6161
    6262#include "Platform.h"
     63#include "StdLibExtras.h"
    6364#include "UnusedParam.h"
    6465
     
    120121inline bool weakCompareAndSwap(unsigned* location, unsigned expected, unsigned newValue)
    121122{
    122     // FIXME: Implement COMPARE_AND_SWAP on other architectures and compilers. Currently
    123     // it only works on X86 or X86_64 with a GCC-style compiler.
    124123#if ENABLE(COMPARE_AND_SWAP)
    125124    bool result;
     125#if CPU(X86) || CPU(X86_64)
    126126    asm volatile(
    127127        "lock; cmpxchgl %3, %2\n\t"
     
    131131        : "memory"
    132132        );
     133#elif CPU(ARM_THUMB2)
     134    unsigned tmp;
     135    asm volatile(
     136        "movw %1, #1\n\t"
     137        "ldrex %2, %0\n\t"
     138        "cmp %3, %2\n\t"
     139        "bne.n 0f\n\t"
     140        "strex %1, %4, %0\n\t"
     141        "0:"
     142        : "+m"(*location), "=&r"(result), "=&r"(tmp)
     143        : "r"(expected), "r"(newValue)
     144        : "memory");
     145    result = !result;
     146#else
     147#error "Bad architecture for compare and swap."
     148#endif
    133149    return result;
    134150#else
     
    143159inline bool weakCompareAndSwap(void*volatile* location, void* expected, void* newValue)
    144160{
    145     // FIXME: Implement COMPARE_AND_SWAP on other architectures and compilers. Currently
    146     // it only works on X86 or X86_64 with a GCC-style compiler.
    147161#if ENABLE(COMPARE_AND_SWAP)
     162#if CPU(X86_64)
    148163    bool result;
    149164    asm volatile(
    150 #if CPU(X86_64)
    151165        "lock; cmpxchgq %3, %2\n\t"
    152 #else
    153         "lock; cmpxchgl %3, %2\n\t"
    154 #endif
    155166        "sete %1"
    156167        : "+a"(expected), "=q"(result), "+m"(*location)
     
    159170        );
    160171    return result;
     172#else
     173    return weakCompareAndSwap(bitwise_cast<unsigned*>(location), bitwise_cast<unsigned>(expected), bitwise_cast<unsigned>(newValue));
     174#endif
    161175#else // ENABLE(COMPARE_AND_SWAP)
    162176    UNUSED_PARAM(location);
Note: See TracChangeset for help on using the changeset viewer.