00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "./aligned_atomic_load_store.h"
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "./ordered_except_wr.h"
00034
00035 #include "./test_and_set_t_is_char.h"
00036
00037 #include "./standard_ao_double_t.h"
00038
00039 #if defined(AO_USE_PENTIUM4_INSTRS)
00040 AO_INLINE void
00041 AO_nop_full(void)
00042 {
00043 __asm__ __volatile__("mfence" : : : "memory");
00044 }
00045
00046 #define AO_HAVE_nop_full
00047
00048 #else
00049
00050
00051
00052
00053
00054 #endif
00055
00056
00057
00058
00059
00060 AO_INLINE AO_t
00061 AO_fetch_and_add_full (volatile AO_t *p, AO_t incr)
00062 {
00063 AO_t result;
00064
00065 __asm__ __volatile__ ("lock; xaddl %0, %1" :
00066 "=r" (result), "=m" (*p) : "0" (incr), "m" (*p)
00067 : "memory");
00068 return result;
00069 }
00070
00071 #define AO_HAVE_fetch_and_add_full
00072
00073 AO_INLINE unsigned char
00074 AO_char_fetch_and_add_full (volatile unsigned char *p, unsigned char incr)
00075 {
00076 unsigned char result;
00077
00078 __asm__ __volatile__ ("lock; xaddb %0, %1" :
00079 "=q" (result), "=m" (*p) : "0" (incr), "m" (*p)
00080 : "memory");
00081 return result;
00082 }
00083
00084 #define AO_HAVE_char_fetch_and_add_full
00085
00086 AO_INLINE unsigned short
00087 AO_short_fetch_and_add_full (volatile unsigned short *p, unsigned short incr)
00088 {
00089 unsigned short result;
00090
00091 __asm__ __volatile__ ("lock; xaddw %0, %1" :
00092 "=r" (result), "=m" (*p) : "0" (incr), "m" (*p)
00093 : "memory");
00094 return result;
00095 }
00096
00097 #define AO_HAVE_short_fetch_and_add_full
00098
00099
00100 AO_INLINE void
00101 AO_or_full (volatile AO_t *p, AO_t incr)
00102 {
00103 __asm__ __volatile__ ("lock; orl %1, %0" :
00104 "=m" (*p) : "r" (incr), "m" (*p) : "memory");
00105 }
00106
00107 #define AO_HAVE_or_full
00108
00109 AO_INLINE AO_TS_VAL_t
00110 AO_test_and_set_full(volatile AO_TS_t *addr)
00111 {
00112 unsigned char oldval;
00113
00114 __asm__ __volatile__("xchgb %0, %1"
00115 : "=q"(oldval), "=m"(*addr)
00116 : "0"(0xff), "m"(*addr) : "memory");
00117 return (AO_TS_VAL_t)oldval;
00118 }
00119
00120 #define AO_HAVE_test_and_set_full
00121
00122
00123 AO_INLINE int
00124 AO_compare_and_swap_full(volatile AO_t *addr, AO_t old, AO_t new_val)
00125 {
00126 # ifdef AO_USE_SYNC_CAS_BUILTIN
00127 return (int)__sync_bool_compare_and_swap(addr, old, new_val);
00128 # else
00129 char result;
00130 __asm__ __volatile__("lock; cmpxchgl %3, %0; setz %1"
00131 : "=m" (*addr), "=a" (result)
00132 : "m" (*addr), "r" (new_val), "a" (old) : "memory");
00133 return (int)result;
00134 # endif
00135 }
00136
00137 #define AO_HAVE_compare_and_swap_full
00138
00139
00140
00141 AO_INLINE int
00142 AO_compare_double_and_swap_double_full(volatile AO_double_t *addr,
00143 AO_t old_val1, AO_t old_val2,
00144 AO_t new_val1, AO_t new_val2)
00145 {
00146 char result;
00147 #if __PIC__
00148
00149
00150
00151 __asm__ __volatile__("pushl %%ebx;"
00152 "movl %6,%%ebx;"
00153 "lock; cmpxchg8b %0; setz %1;"
00154 "pop %%ebx;"
00155 : "=m"(*addr), "=a"(result)
00156 : "m"(*addr), "d" (old_val2), "a" (old_val1),
00157 "c" (new_val2), "m" (new_val1) : "memory");
00158 #else
00159
00160
00161
00162
00163 __asm__ __volatile__("lock; cmpxchg8b %0; setz %1;"
00164 : "=m"(*addr), "=a"(result)
00165 : "m"(*addr), "d" (old_val2), "a" (old_val1),
00166 "c" (new_val2), "b" (new_val1) : "memory");
00167 #endif
00168 return (int) result;
00169 }
00170
00171 #define AO_HAVE_compare_double_and_swap_double_full
00172
00173 #include "./ao_t_is_int.h"