Changeset 1452e3302fd8c2b4ded895773bf38dc163b2d914

Show
Ignore:
Timestamp:
12/17/07 18:39:37 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1197916777 +0000
git-parent:

[2391f9bd8f65d48ef6034801e0d571f487231be4]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1197916777 +0000
Message:

add some x86 and x86_64 atomic support

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/utils/noit_atomic.h

    rcd1ab55 r1452e33  
    1919#include <libkern/OSAtomic.h> 
    2020typedef OSSpinLock noit_spinlock_t; 
    21 #define noit_atomic_cas OSAtomicCompareAndSwap32 
     21#define noit_atomic_cas32 OSAtomicCompareAndSwap32 
    2222#define noit_atomic_cas64 OSAtomicCompareAndSwap64 
    23 #define noit_atomic_inc OSAtomicIncrement32 
     23#define noit_atomic_inc32 OSAtomicIncrement32 
    2424#define noit_atomic_inc64 OSAtomicIncrement64 
    25 #define noit_atomic_dec OSAtomicDecrement32 
     25#define noit_atomic_dec32 OSAtomicDecrement32 
    2626#define noit_atomic_dec64 OSAtomicDecrement64 
    2727#define noit_spinlock_lock OSSpinLockLock 
    2828#define noit_spinlock_unlock OSSpinLockUnlock 
    2929#define noit_spinlock_trylock OSSpinLockTry 
     30#elif defined(__GNUC__) 
     31 
     32typedef u_int32_t noit_atomic32_t 
     33typedef u_int64_t noit_atomic64_t 
     34 
     35#if (SIZEOF_VOID_P == 4) 
     36#define noit_atomic_casptr(a,b,c) noit_atomic_cas32((a),(void *)(b),(void *)(c)) 
     37#elif (SIZEOF_VOID_P == 8) 
     38#define noit_atomic_casptr(a,b,c) noit_atomic_cas64((a),(void *)(b),(void *)(c)) 
     39#else 
     40#error unsupported pointer width 
     41#endif 
     42 
     43static inline noit_atomic32_t 
     44noit_atomic_cas32(volatile noit_atomic32_t *ptr 
     45                  volatile noit_atomic32_t rpl, 
     46                  volatile noit_atomic32_t curr) { 
     47  noit_atomic32_t prev; 
     48  __asm__ volatile ( 
     49      "lock; cmpxchgl %1, %2" 
     50    : "=a" (prev) 
     51    : "r"  (rpl), "m" (*(ptr)), "0" (curr) 
     52    : "memory"); 
     53  return prev; 
     54} 
     55 
     56#ifdef __x86_64__ 
     57static inline noit_atomic64_t 
     58noit_atomic_cas64(volatile noit_atomic64_t *ptr 
     59                  volatile noit_atomic64_t rpl, 
     60                  volatile noit_atomic64_t curr) { 
     61  noit_atomic64_t prev; 
     62  __asm__ volatile ( 
     63      "lock; cmpxchgq %1, %2" 
     64    : "=a" (prev) 
     65    : "r"  (rpl), "m" (*(ptr)), "0" (curr) 
     66    : "memory"); 
     67  return prev; 
     68} 
     69#else 
     70static inline noit_atomic64_t 
     71noit_atomic_cas64(volatile noit_atomic64_t *ptr 
     72                  volatile noit_atomic64_t rpl, 
     73                  volatile noit_atomic64_t curr) { 
     74  noit_atomic64_t prev; 
     75  __asm__ volatile ( 
     76      "pushl %%ebx;" 
     77      "mov 4+%1,%%ecx;" 
     78      "mov %1,%%ebx;" 
     79      "lock;" 
     80      "cmpxchg8b (%3);" 
     81      "popl %%ebx" 
     82    : "=A" (prev) 
     83    : "m" (rpl), "A" (curr), "r" (ptr) 
     84    : "%ebx", "%ecx", "memory"); 
     85  return prev; 
     86}; 
     87#endif 
     88 
    3089#else 
    3190#error Please stub out the atomics section for your platform