include/SDL_atomic.h
changeset 3186 51750b7a966f
parent 3181 030899df1af5
child 3187 e041d2c603fe
     1.1 --- a/include/SDL_atomic.h	Wed Jun 10 08:09:04 2009 +0000
     1.2 +++ b/include/SDL_atomic.h	Wed Jun 10 13:34:20 2009 +0000
     1.3 @@ -44,58 +44,44 @@
     1.4  
     1.5  #if defined(__GNUC__) && (defined(i386) || defined(__i386__)  || defined(__x86_64__))
     1.6  static __inline__ void
     1.7 -SDL_atomic_int_add(volatile int* atomic, int value)
     1.8 +SDL_atomic_int_add(volatile int *atomic, int value)
     1.9  {
    1.10 -  __asm__ __volatile__("lock;"
    1.11 -                       "addl %1, %0"
    1.12 -                       : "=m" (*atomic)
    1.13 -                       : "ir" (value),
    1.14 -                         "m" (*atomic));
    1.15 +    __asm__ __volatile__("lock;" "addl %1, %0":"=m"(*atomic)
    1.16 +                         :"ir"(value), "m"(*atomic));
    1.17  }
    1.18  
    1.19  static __inline__ int
    1.20 -SDL_atomic_int_xchg_add(volatile int* atomic, int value)
    1.21 -{                                              
    1.22 -  int rv;                                    
    1.23 -  __asm__ __volatile__("lock;"               
    1.24 -                       "xaddl %0, %1"        
    1.25 -                       : "=r" (rv),          
    1.26 -                         "=m" (*atomic)    
    1.27 -                       : "0" (value),        
    1.28 -                         "m" (*atomic));   
    1.29 -  return rv;                                        
    1.30 +SDL_atomic_int_xchg_add(volatile int *atomic, int value)
    1.31 +{
    1.32 +    int rv;
    1.33 +    __asm__ __volatile__("lock;" "xaddl %0, %1":"=r"(rv), "=m"(*atomic)
    1.34 +                         :"0"(value), "m"(*atomic));
    1.35 +    return rv;
    1.36  }
    1.37  
    1.38  static __inline__ SDL_bool
    1.39 -SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue)
    1.40 +SDL_atomic_int_cmp_xchg(volatile int *atomic, int oldvalue, int newvalue)
    1.41  {
    1.42 -  int rv;                                                      
    1.43 -  __asm__ __volatile__("lock;"                               
    1.44 -                       "cmpxchgl %2, %1"                     
    1.45 -                       : "=a" (rv),                          
    1.46 -                         "=m" (*atomic)             
    1.47 -                       : "r" (newvalue),                     
    1.48 -                         "m" (*atomic),                    
    1.49 -                         "0" (oldvalue));
    1.50 -  return (SDL_bool)(rv == oldvalue);                                          
    1.51 +    int rv;
    1.52 +    __asm__ __volatile__("lock;" "cmpxchgl %2, %1":"=a"(rv), "=m"(*atomic)
    1.53 +                         :"r"(newvalue), "m"(*atomic), "0"(oldvalue));
    1.54 +    return (SDL_bool) (rv == oldvalue);
    1.55  }
    1.56  
    1.57  static __inline__ SDL_bool
    1.58 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
    1.59 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
    1.60 +                        void *newvalue)
    1.61  {
    1.62 -  void* rv;
    1.63 -  __asm__ __volatile__("lock;"
    1.64 -# if defined(__x86_64__)                       
    1.65 -                       "cmpxchgq %q2, %1"
    1.66 +    void *rv;
    1.67 +    __asm__ __volatile__("lock;"
    1.68 +# if defined(__x86_64__)
    1.69 +                         "cmpxchgq %q2, %1"
    1.70  # else
    1.71 -                       "cmpxchgl %2, %1"
    1.72 -# endif                       
    1.73 -                       : "=a" (rv),
    1.74 -                         "=m" (*atomic)
    1.75 -                       : "r" (newvalue),
    1.76 -                         "m" (*atomic),
    1.77 -                         "0" (oldvalue));
    1.78 -  return (SDL_bool)(rv == oldvalue);
    1.79 +                         "cmpxchgl %2, %1"
    1.80 +# endif
    1.81 +                         :"=a"(rv), "=m"(*atomic)
    1.82 +                         :"r"(newvalue), "m"(*atomic), "0"(oldvalue));
    1.83 +    return (SDL_bool) (rv == oldvalue);
    1.84  }
    1.85  #elif defined(__GNUC__) && defined(__alpha__)
    1.86  # define ATOMIC_MEMORY_BARRIER (__asm__ __volatile__ ("mb" : : : "memory"))
    1.87 @@ -122,53 +108,45 @@
    1.88  
    1.89  # if (SIZEOF_VOIDP == 4)
    1.90  static __inline__ SDL_bool
    1.91 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
    1.92 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
    1.93 +                        void *newvalue)
    1.94  {
    1.95 -  int rv;
    1.96 -  void* prev;
    1.97 -  __asm__ __volatile__("   mb\n"
    1.98 -                       "1: ldl_l %0,%2\n"
    1.99 -                       "   cmpeq %0,%3,%1\n"
   1.100 -                       "   beq   $1,2f\n"
   1.101 -                       "   mov   %4,%1\n"
   1.102 -                       "   stl_c %1,%2\n"
   1.103 -                       "   beq   %1,1b\n"
   1.104 -                       "   mb\n"
   1.105 -                       "2:"
   1.106 -                       : "=&r" (prev),
   1.107 -                         "=&r" (rv)
   1.108 -                       : "m" (*atomic),
   1.109 -                         "Ir" (oldvalue),
   1.110 -                         "Ir" (newvalue)
   1.111 -                       : "memory");
   1.112 -  return (SDL_bool)(rv != 0);
   1.113 +    int rv;
   1.114 +    void *prev;
   1.115 +    __asm__ __volatile__("   mb\n"
   1.116 +                         "1: ldl_l %0,%2\n"
   1.117 +                         "   cmpeq %0,%3,%1\n"
   1.118 +                         "   beq   $1,2f\n"
   1.119 +                         "   mov   %4,%1\n"
   1.120 +                         "   stl_c %1,%2\n"
   1.121 +                         "   beq   %1,1b\n"
   1.122 +                         "   mb\n" "2:":"=&r"(prev), "=&r"(rv)
   1.123 +                         :"m"(*atomic), "Ir"(oldvalue), "Ir"(newvalue)
   1.124 +                         :"memory");
   1.125 +    return (SDL_bool) (rv != 0);
   1.126  }
   1.127  # elif (SIZEOF_VOIDP == 8)
   1.128  static __inline__ SDL_bool
   1.129 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
   1.130 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
   1.131 +                        void *newvalue)
   1.132  {
   1.133 -  int rv;
   1.134 -  void* prev;
   1.135 -  __asm__ __volatile__("   mb\n"
   1.136 -                       "1: ldq_l %0,%2\n"
   1.137 -                       "   cmpeq %0,%3,%1\n"
   1.138 -                       "   beq   %1,2f\n"
   1.139 -                       "   mov   %4,%1\n"
   1.140 -                       "   stq_c %1,%2\n"
   1.141 -                       "   beq   %1,1b\n"
   1.142 -                       "   mb\n"
   1.143 -                       "2:"
   1.144 -                       : "=&r" (prev),
   1.145 -                         "=&r" (rv)
   1.146 -                       : "m" (*atomic),
   1.147 -                         "Ir" (oldvalue),
   1.148 -                         "Ir" (newvalue)
   1.149 -                       : "memory");
   1.150 -  return (SDL_bool)(rv != 0);
   1.151 +    int rv;
   1.152 +    void *prev;
   1.153 +    __asm__ __volatile__("   mb\n"
   1.154 +                         "1: ldq_l %0,%2\n"
   1.155 +                         "   cmpeq %0,%3,%1\n"
   1.156 +                         "   beq   %1,2f\n"
   1.157 +                         "   mov   %4,%1\n"
   1.158 +                         "   stq_c %1,%2\n"
   1.159 +                         "   beq   %1,1b\n"
   1.160 +                         "   mb\n" "2:":"=&r"(prev), "=&r"(rv)
   1.161 +                         :"m"(*atomic), "Ir"(oldvalue), "Ir"(newvalue)
   1.162 +                         :"memory");
   1.163 +    return (SDL_bool) (rv != 0);
   1.164  }
   1.165  # else
   1.166 -#  error "Your system has an unsupported pointer size"  
   1.167 -# endif  /* SIZEOF_VOIDP */
   1.168 +#  error "Your system has an unsupported pointer size"
   1.169 +# endif /* SIZEOF_VOIDP */
   1.170  #elif defined(__GNUC__) && defined(__sparc__)
   1.171  # define ATOMIC_MEMORY_BARRIER                                          \
   1.172    (__asm__ __volatile__("membar #LoadLoad | #LoadStore"                 \
   1.173 @@ -185,32 +163,25 @@
   1.174  
   1.175  # if (SIZEOF_VOIDP == 4)
   1.176  static __inline__ SDL_bool
   1.177 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
   1.178 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
   1.179 +                        void *newvalue)
   1.180  {
   1.181 -  void* rv;
   1.182 -  __asm__ __volatile__("cas [%4], %2, %0"
   1.183 -                       : "=r" (rv),
   1.184 -                         "=m" (*atomic)
   1.185 -                       : "r" (oldvalue),
   1.186 -                         "m" (*atomic),
   1.187 -                         "r" (atomic),
   1.188 -                         "0" (newvalue));
   1.189 -  return (SDL_bool)(rv == oldvalue);
   1.190 +    void *rv;
   1.191 +    __asm__ __volatile__("cas [%4], %2, %0":"=r"(rv), "=m"(*atomic)
   1.192 +                         :"r"(oldvalue),
   1.193 +                         "m"(*atomic), "r"(atomic), "0"(newvalue));
   1.194 +    return (SDL_bool) (rv == oldvalue);
   1.195  }
   1.196  # elif (SIZEOF_VOIDP == 8)
   1.197  static __inline__ SDL_bool
   1.198 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
   1.199 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
   1.200 +                        void *newvalue)
   1.201  {
   1.202 -  void* rv;
   1.203 -  void** a = atomic;
   1.204 -  __asm__ __volatile__("casx [%4], %2, %0"
   1.205 -                       : "=r" (rv),
   1.206 -                         "=m" (*a)
   1.207 -                       : "r" (oldvalue),
   1.208 -                         "m" (*a),
   1.209 -                         "r" (a),
   1.210 -                         "0" (newvalue));
   1.211 -  return (SDL_bool)(rv == oldvalue);
   1.212 +    void *rv;
   1.213 +    void **a = atomic;
   1.214 +    __asm__ __volatile__("casx [%4], %2, %0":"=r"(rv), "=m"(*a)
   1.215 +                         :"r"(oldvalue), "m"(*a), "r"(a), "0"(newvalue));
   1.216 +    return (SDL_bool) (rv == oldvalue);
   1.217  }
   1.218  # else
   1.219  #  error "Your system has an unsupported pointer size"
   1.220 @@ -219,122 +190,90 @@
   1.221  # define ATOMIC_MEMORY_BARRIER \
   1.222    (__asm__ __volatile__ ("sync" : : : "memory"))
   1.223  static __inline__ void
   1.224 -SDL_atomic_int_add(volatile int* atomic, int value)
   1.225 -{                                           
   1.226 -  int rv,tmp;                                   
   1.227 -  __asm__ __volatile__("1: lwarx   %0,  0, %3\n" 
   1.228 -                       "   add     %1, %0, %4\n"
   1.229 -                       "   stwcx.  %1,  0, %3\n" 
   1.230 -                       "   bne-    1b"          
   1.231 -                       : "=&b" (rv),            
   1.232 -                         "=&r" (tmp),           
   1.233 -                         "=m" (*atomic)       
   1.234 -                       : "b" (atomic),          
   1.235 -                         "r" (value),           
   1.236 -                         "m" (*atomic)        
   1.237 -                       : "cr0",                 
   1.238 -                         "memory");             
   1.239 +SDL_atomic_int_add(volatile int *atomic, int value)
   1.240 +{
   1.241 +    int rv, tmp;
   1.242 +    __asm__ __volatile__("1: lwarx   %0,  0, %3\n"
   1.243 +                         "   add     %1, %0, %4\n"
   1.244 +                         "   stwcx.  %1,  0, %3\n"
   1.245 +                         "   bne-    1b":"=&b"(rv), "=&r"(tmp), "=m"(*atomic)
   1.246 +                         :"b"(atomic), "r"(value), "m"(*atomic)
   1.247 +                         :"cr0", "memory");
   1.248  }
   1.249  
   1.250  static __inline__ int
   1.251 -SDL_atomic_int_xchg_add(volatile int* atomic, int value)
   1.252 -{                                          
   1.253 -  int rv,tmp;                               
   1.254 -  __asm__ __volatile__("1: lwarx  %0, 0, %3\n"        
   1.255 -                       "   add    %1, %0, %4\n"       
   1.256 -                       "   stwcx. %1, 0, %3\n"        
   1.257 -                       "   bne-   1b"                 
   1.258 -                       : "=&b" (rv),                  
   1.259 -                         "=&r" (tmp),                 
   1.260 -                         "=m" (*atomic)
   1.261 -                       : "b" (atomic),                
   1.262 -                         "r" (value),                 
   1.263 -                         "m" (*atomic)
   1.264 -                       : "cr0",                       
   1.265 -                       "memory");                   
   1.266 -  return rv;                                                 
   1.267 +SDL_atomic_int_xchg_add(volatile int *atomic, int value)
   1.268 +{
   1.269 +    int rv, tmp;
   1.270 +    __asm__ __volatile__("1: lwarx  %0, 0, %3\n"
   1.271 +                         "   add    %1, %0, %4\n"
   1.272 +                         "   stwcx. %1, 0, %3\n"
   1.273 +                         "   bne-   1b":"=&b"(rv), "=&r"(tmp), "=m"(*atomic)
   1.274 +                         :"b"(atomic), "r"(value), "m"(*atomic)
   1.275 +                         :"cr0", "memory");
   1.276 +    return rv;
   1.277  }
   1.278  
   1.279  # if (SIZEOF_VOIDP == 4)
   1.280  static __inline__ SDL_bool
   1.281 -SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue)
   1.282 -{                                                        
   1.283 -  int rv;                                                 
   1.284 -  __asm__ __volatile__("   sync\n"                         
   1.285 -                       "1: lwarx   %0, 0, %1\n"           
   1.286 -                       "   subf.   %0, %2, %0\n"          
   1.287 -                       "   bne     2f\n"                  
   1.288 -                       "   stwcx.  %3, 0, %1\n"           
   1.289 -                       "   bne-    1b\n"                  
   1.290 -                       "2: isync"                         
   1.291 -                       : "=&r" (rv)                       
   1.292 -                       : "b" (atomic),                    
   1.293 -                         "r" (oldvalue),                  
   1.294 -                         "r"                              
   1.295 -                       : "cr0",                           
   1.296 -                         "memory");                         
   1.297 -  return (SDL_bool)(rv == 0);                                              
   1.298 +SDL_atomic_int_cmp_xchg(volatile int *atomic, int oldvalue, int newvalue)
   1.299 +{
   1.300 +    int rv;
   1.301 +    __asm__ __volatile__("   sync\n"
   1.302 +                         "1: lwarx   %0, 0, %1\n"
   1.303 +                         "   subf.   %0, %2, %0\n"
   1.304 +                         "   bne     2f\n"
   1.305 +                         "   stwcx.  %3, 0, %1\n"
   1.306 +                         "   bne-    1b\n" "2: isync":"=&r"(rv)
   1.307 +                         :"b"(atomic), "r"(oldvalue), "r":"cr0", "memory");
   1.308 +    return (SDL_bool) (rv == 0);
   1.309  }
   1.310  
   1.311  static __inline__ SDL_bool
   1.312 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
   1.313 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
   1.314 +                        void *newvalue)
   1.315  {
   1.316 -  void* rv;
   1.317 -  __asm__ __volatile__("sync\n"
   1.318 -                       "1: lwarx  %0,  0, %1\n"
   1.319 -                       "   subf.  %0, %2, %0\n"
   1.320 -                       "   bne    2f\n"
   1.321 -                       "   stwcx. %3,  0, %1\n"
   1.322 -                       "   bne-   1b\n"
   1.323 -                       "2: isync"
   1.324 -                       : "=&r" (rv)
   1.325 -                       : "b" (atomic),
   1.326 -                         "r" (oldvalue),
   1.327 -                         "r" (newvalue)
   1.328 -                       : "cr0",
   1.329 -                       "memory");
   1.330 -  return (SDL_bool)(rv == 0);
   1.331 +    void *rv;
   1.332 +    __asm__ __volatile__("sync\n"
   1.333 +                         "1: lwarx  %0,  0, %1\n"
   1.334 +                         "   subf.  %0, %2, %0\n"
   1.335 +                         "   bne    2f\n"
   1.336 +                         "   stwcx. %3,  0, %1\n"
   1.337 +                         "   bne-   1b\n" "2: isync":"=&r"(rv)
   1.338 +                         :"b"(atomic), "r"(oldvalue), "r"(newvalue)
   1.339 +                         :"cr0", "memory");
   1.340 +    return (SDL_bool) (rv == 0);
   1.341  }
   1.342  # elif (SIZEOF_VOIDP == 8)
   1.343  static __inline__ SDL_bool
   1.344 -SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue)
   1.345 -{                                                        
   1.346 -  int rv;                                                 
   1.347 -  __asm__ __volatile__("   sync\n"                         
   1.348 -                       "1: lwarx   %0,  0, %1\n"
   1.349 -                       "   extsw   %0, %0\n"
   1.350 -                       "   subf.   %0, %2, %0\n"          
   1.351 -                       "   bne     2f\n"                  
   1.352 -                       "   stwcx.  %3,  0, %1\n"           
   1.353 -                       "   bne-    1b\n"                  
   1.354 -                       "2: isync"                         
   1.355 -                       : "=&r" (rv)                       
   1.356 -                       : "b" (atomic),                    
   1.357 -                         "r" (oldvalue),                  
   1.358 -                         "r"                              
   1.359 -                       : "cr0",                           
   1.360 -                         "memory");                         
   1.361 -  return (SDL_bool)(rv == 0);                                              
   1.362 +SDL_atomic_int_cmp_xchg(volatile int *atomic, int oldvalue, int newvalue)
   1.363 +{
   1.364 +    int rv;
   1.365 +    __asm__ __volatile__("   sync\n"
   1.366 +                         "1: lwarx   %0,  0, %1\n"
   1.367 +                         "   extsw   %0, %0\n"
   1.368 +                         "   subf.   %0, %2, %0\n"
   1.369 +                         "   bne     2f\n"
   1.370 +                         "   stwcx.  %3,  0, %1\n"
   1.371 +                         "   bne-    1b\n" "2: isync":"=&r"(rv)
   1.372 +                         :"b"(atomic), "r"(oldvalue), "r":"cr0", "memory");
   1.373 +    return (SDL_bool) (rv == 0);
   1.374  }
   1.375  
   1.376  static __inline__ SDL_bool
   1.377 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
   1.378 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
   1.379 +                        void *newvalue)
   1.380  {
   1.381 -  void* rv;
   1.382 -  __asm__ __volatile__("sync\n"
   1.383 -                       "1: ldarx  %0,  0, %1\n"
   1.384 -                       "   subf.  %0, %2, %0\n"
   1.385 -                       "   bne    2f\n"
   1.386 -                       "   stdcx. %3,  0, %1\n"
   1.387 -                       "   bne-   1b\n"
   1.388 -                       "2: isync"
   1.389 -                       : "=&r" (rv)
   1.390 -                       : "b" (atomic),
   1.391 -                         "r" (oldvalue),
   1.392 -                         "r" (newvalue)
   1.393 -                       : "cr0",
   1.394 -                       "memory");
   1.395 -  return (SDL_bool)(rv == 0);
   1.396 +    void *rv;
   1.397 +    __asm__ __volatile__("sync\n"
   1.398 +                         "1: ldarx  %0,  0, %1\n"
   1.399 +                         "   subf.  %0, %2, %0\n"
   1.400 +                         "   bne    2f\n"
   1.401 +                         "   stdcx. %3,  0, %1\n"
   1.402 +                         "   bne-   1b\n" "2: isync":"=&r"(rv)
   1.403 +                         :"b"(atomic), "r"(oldvalue), "r"(newvalue)
   1.404 +                         :"cr0", "memory");
   1.405 +    return (SDL_bool) (rv == 0);
   1.406  }
   1.407  # else
   1.408  #  error "Your system has an unsupported pointer size"
   1.409 @@ -351,161 +290,130 @@
   1.410    (__sync_bool_compare_and_swap((long*)(atomic),(long)(oldvalue),(long)(newvalue)))
   1.411  #elif defined(__GNUC__) && defined(__LINUX__) && (defined(__mips__) || defined(__MIPS__))
   1.412  static __inline__ int
   1.413 -SDL_atomic_int_xchg_add(volatile int* atomic, int value)
   1.414 -{                                            
   1.415 -  int rv,tmp;                                 
   1.416 -  __asm__ __volatile__("1:              \n"                 
   1.417 -                       ".set  push      \n"         
   1.418 -                       ".set  mips2     \n"        
   1.419 -                       "ll    %0,%3     \n"        
   1.420 -                       "addu  %1,%4,%0  \n"     
   1.421 -                       "sc    %1,%2     \n"        
   1.422 -                       ".set  pop       \n"          
   1.423 -                       "beqz  %1,1b     \n"        
   1.424 -                       : "=&r" (rv),          
   1.425 -                         "=&r" (tmp),         
   1.426 -                         "=m" (*atomic)     
   1.427 -                       : "m" (*atomic),     
   1.428 -                         "r" (value)          
   1.429 -                       : "memory");           
   1.430 -  return rv;                                         
   1.431 +SDL_atomic_int_xchg_add(volatile int *atomic, int value)
   1.432 +{
   1.433 +    int rv, tmp;
   1.434 +    __asm__ __volatile__("1:              \n"
   1.435 +                         ".set  push      \n"
   1.436 +                         ".set  mips2     \n"
   1.437 +                         "ll    %0,%3     \n"
   1.438 +                         "addu  %1,%4,%0  \n"
   1.439 +                         "sc    %1,%2     \n"
   1.440 +                         ".set  pop       \n"
   1.441 +                         "beqz  %1,1b     \n":"=&r"(rv),
   1.442 +                         "=&r"(tmp), "=m"(*atomic)
   1.443 +                         :"m"(*atomic), "r"(value)
   1.444 +                         :"memory");
   1.445 +    return rv;
   1.446  }
   1.447  
   1.448  static __inline__ void
   1.449 -SDL_atomic_int_add(volatile int* atomic, int value)
   1.450 -{                                           
   1.451 -  int rv;                                    
   1.452 -  __asm__ __volatile__("1:               \n"                
   1.453 -                       ".set  push       \n"        
   1.454 -                       ".set  mips2      \n"       
   1.455 -                       "ll    %0,%2      \n"       
   1.456 -                       "addu  %0,%3,%0   \n"    
   1.457 -                       "sc    %0,%1      \n"       
   1.458 -                       ".set  pop        \n"         
   1.459 -                       "beqz  %0,1b      \n"       
   1.460 -                       : "=&r" (rv),         
   1.461 -                         "=m" (*atomic)    
   1.462 -                       : "m" (*atomic),    
   1.463 -                         "r" (value)         
   1.464 -                       : "memory");          
   1.465 +SDL_atomic_int_add(volatile int *atomic, int value)
   1.466 +{
   1.467 +    int rv;
   1.468 +    __asm__ __volatile__("1:               \n"
   1.469 +                         ".set  push       \n"
   1.470 +                         ".set  mips2      \n"
   1.471 +                         "ll    %0,%2      \n"
   1.472 +                         "addu  %0,%3,%0   \n"
   1.473 +                         "sc    %0,%1      \n"
   1.474 +                         ".set  pop        \n"
   1.475 +                         "beqz  %0,1b      \n":"=&r"(rv), "=m"(*atomic)
   1.476 +                         :"m"(*atomic), "r"(value)
   1.477 +                         :"memory");
   1.478  }
   1.479  
   1.480  static __inline__ SDL_bool
   1.481 -SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue)
   1.482 +SDL_atomic_int_cmp_xchg(volatile int *atomic, int oldvalue, int newvalue)
   1.483  {
   1.484 -  int rv;
   1.485 -  __asm__ __volatile__("     .set push        \n"
   1.486 -                       "     .set noat        \n"
   1.487 -                       "     .set mips3       \n"
   1.488 -                       "1:   ll   %0, %2      \n"
   1.489 -                       "     bne  %0, %z3, 2f \n"
   1.490 -                       "     .set mips0       \n"
   1.491 -                       "     move $1, %z4     \n"
   1.492 -                       "     .set mips3       \n"
   1.493 -                       "     sc   $1, %1      \n"
   1.494 -                       "     beqz $1, 1b      \n"
   1.495 -                       "     sync             \n"
   1.496 -                       "2:                    \n"
   1.497 -                       "     .set pop         \n"
   1.498 -                       : "=&r" (rv),
   1.499 -                         "=R" (*atomic)
   1.500 -                       : "R" (*atomic),
   1.501 -                         "Jr" (oldvalue),
   1.502 -                         "Jr" (newvalue)
   1.503 -                       : "memory");
   1.504 -  return (SDL_bool)rv;                  
   1.505 +    int rv;
   1.506 +    __asm__ __volatile__("     .set push        \n"
   1.507 +                         "     .set noat        \n"
   1.508 +                         "     .set mips3       \n"
   1.509 +                         "1:   ll   %0, %2      \n"
   1.510 +                         "     bne  %0, %z3, 2f \n"
   1.511 +                         "     .set mips0       \n"
   1.512 +                         "     move $1, %z4     \n"
   1.513 +                         "     .set mips3       \n"
   1.514 +                         "     sc   $1, %1      \n"
   1.515 +                         "     beqz $1, 1b      \n"
   1.516 +                         "     sync             \n"
   1.517 +                         "2:                    \n"
   1.518 +                         "     .set pop         \n":"=&r"(rv), "=R"(*atomic)
   1.519 +                         :"R"(*atomic), "Jr"(oldvalue), "Jr"(newvalue)
   1.520 +                         :"memory");
   1.521 +    return (SDL_bool) rv;
   1.522  }
   1.523  
   1.524  static __inline__ SDL_bool
   1.525 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
   1.526 -{                                                     
   1.527 -  int rv;
   1.528 -  __asm__ __volatile__("     .set push        \n"
   1.529 -                       "     .set noat        \n"
   1.530 -                       "     .set mips3       \n"
   1.531 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
   1.532 +                        void *newvalue)
   1.533 +{
   1.534 +    int rv;
   1.535 +    __asm__ __volatile__("     .set push        \n"
   1.536 +                         "     .set noat        \n" "     .set mips3       \n"
   1.537  # if defined(__mips64)
   1.538 -                       "1:   lld  %0, %2      \n"
   1.539 +                         "1:   lld  %0, %2      \n"
   1.540  # else
   1.541 -                       "1:   ll   %0, %2      \n"
   1.542 -# endif                       
   1.543 -                       "     bne  %0, %z3, 2f \n"
   1.544 -                       "     move $1, %z4     \n"
   1.545 +                         "1:   ll   %0, %2      \n"
   1.546 +# endif
   1.547 +                         "     bne  %0, %z3, 2f \n" "     move $1, %z4     \n"
   1.548  # if defined(__mips64)
   1.549 -                       "     sc   $1, %1      \n"
   1.550 +                         "     sc   $1, %1      \n"
   1.551  # else
   1.552 -                       "     scd  $1, %1      \n"
   1.553 -# endif                       
   1.554 -                       "     beqz $1, 1b      \n"
   1.555 -                       "     sync             \n"
   1.556 -                       "2:                    \n"
   1.557 -                       "     .set pop         \n"
   1.558 -                       : "=&r" (rv),
   1.559 -                         "=R" (*atomic)
   1.560 -                       : "R" (*atomic),
   1.561 -                         "Jr" (oldvalue),
   1.562 -                         "Jr" (newvalue)
   1.563 -                       : "memory");
   1.564 -  return (SDL_bool)rv;                                                  
   1.565 +                         "     scd  $1, %1      \n"
   1.566 +# endif
   1.567 +                         "     beqz $1, 1b      \n"
   1.568 +                         "     sync             \n"
   1.569 +                         "2:                    \n"
   1.570 +                         "     .set pop         \n":"=&r"(rv), "=R"(*atomic)
   1.571 +                         :"R"(*atomic), "Jr"(oldvalue), "Jr"(newvalue)
   1.572 +                         :"memory");
   1.573 +    return (SDL_bool) rv;
   1.574  }
   1.575  #elif defined(__GNUC__) && defined(__m68k__)
   1.576  static __inline__ int
   1.577 -SDL_atomic_int_xchg_add(volatile int* atomic, int value)
   1.578 -{                                          
   1.579 -  int rv = *atomic;
   1.580 -  int tmp;
   1.581 -  __asm__ __volatile__("1: move%.l %0,%1    \n"
   1.582 -                       "   add%.l  %2,%1    \n"
   1.583 -                       "   cas%.l  %0,%1,%3 \n"
   1.584 -                       "   jbne    1b       \n"
   1.585 -                       : "=d" (rv),
   1.586 -                         "=&d" (tmp)
   1.587 -                       : "d" (value),
   1.588 -                         "m" (*atomic),
   1.589 -                         "0" (rv)
   1.590 -                       : "memory");
   1.591 -  return (SDL_bool)rv;
   1.592 +SDL_atomic_int_xchg_add(volatile int *atomic, int value)
   1.593 +{
   1.594 +    int rv = *atomic;
   1.595 +    int tmp;
   1.596 +    __asm__ __volatile__("1: move%.l %0,%1    \n"
   1.597 +                         "   add%.l  %2,%1    \n"
   1.598 +                         "   cas%.l  %0,%1,%3 \n"
   1.599 +                         "   jbne    1b       \n":"=d"(rv), "=&d"(tmp)
   1.600 +                         :"d"(value), "m"(*atomic), "0"(rv)
   1.601 +                         :"memory");
   1.602 +    return (SDL_bool) rv;
   1.603  }
   1.604  
   1.605  static __inline__ void
   1.606 -SDL_atomic_int_add(volatile int* atomic, int value)
   1.607 -{                                           
   1.608 -  __asm__ __volatile__("add%.l %0,%1"        
   1.609 -                       :                     
   1.610 -                       : "id" (value),       
   1.611 -                         "m" (*atomic)
   1.612 -                       : "memory");          
   1.613 +SDL_atomic_int_add(volatile int *atomic, int value)
   1.614 +{
   1.615 +    __asm__ __volatile__("add%.l %0,%1"::"id"(value), "m"(*atomic)
   1.616 +                         :"memory");
   1.617  }
   1.618  
   1.619  static __inline__ SDL_bool
   1.620 -SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue)
   1.621 -{                                           
   1.622 -  char rv;                                   
   1.623 -  int readvalue;                             
   1.624 -  __asm__ __volatile__("cas%.l %2,%3,%1\n"   
   1.625 -                       "seq    %0"           
   1.626 -                       : "=dm" (rv),         
   1.627 -                         "=m" (*atomic),   
   1.628 -                         "=d" (readvalue)    
   1.629 -                       : "d" (newvalue),     
   1.630 -                         "m" (*atomic),    
   1.631 -                         "2" (oldvalue));    
   1.632 -    return (SDL_bool)rv;                                        
   1.633 +SDL_atomic_int_cmp_xchg(volatile int *atomic, int oldvalue, int newvalue)
   1.634 +{
   1.635 +    char rv;
   1.636 +    int readvalue;
   1.637 +    __asm__ __volatile__("cas%.l %2,%3,%1\n"
   1.638 +                         "seq    %0":"=dm"(rv), "=m"(*atomic), "=d"(readvalue)
   1.639 +                         :"d"(newvalue), "m"(*atomic), "2"(oldvalue));
   1.640 +    return (SDL_bool) rv;
   1.641  }
   1.642  
   1.643  static __inline__ SDL_bool
   1.644 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
   1.645 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
   1.646 +                        void *newvalue)
   1.647  {
   1.648 -  char rv;                                   
   1.649 -  int readvalue;                             
   1.650 -  __asm__ __volatile__("cas%.l %2,%3,%1\n"   
   1.651 -                       "seq    %0"           
   1.652 -                       : "=dm" (rv),         
   1.653 -                         "=m" (*atomic),   
   1.654 -                         "=d" (readvalue)    
   1.655 -                       : "d" (newvalue),     
   1.656 -                         "m" (*atomic),    
   1.657 -                         "2" (oldvalue));    
   1.658 -    return (SDL_bool)rv;                                        
   1.659 +    char rv;
   1.660 +    int readvalue;
   1.661 +    __asm__ __volatile__("cas%.l %2,%3,%1\n"
   1.662 +                         "seq    %0":"=dm"(rv), "=m"(*atomic), "=d"(readvalue)
   1.663 +                         :"d"(newvalue), "m"(*atomic), "2"(oldvalue));
   1.664 +    return (SDL_bool) rv;
   1.665  }
   1.666  #elif defined(__GNUC__) && defined(__s390__)
   1.667  # define ATOMIC_INT_CMP_XCHG(atomic,oldvalue,newvalue)  \
   1.668 @@ -521,30 +429,26 @@
   1.669    })
   1.670  # if (SIZEOF_VOIDP == 4)
   1.671  static __inline__ SDL_bool
   1.672 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
   1.673 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
   1.674 +                        void *newvalue)
   1.675  {
   1.676 -  void* rv = oldvalue;
   1.677 -  __asm__ __volatile__("cs %0, %2, %1"
   1.678 -                       : "+d" (rv),
   1.679 -                         "=Q" (*atomic)
   1.680 -                       : "d" (newvalue),
   1.681 -                         "m" (*atomic)
   1.682 -                       : "cc");
   1.683 -  return (SDL_bool)(rv == oldvalue);
   1.684 +    void *rv = oldvalue;
   1.685 +    __asm__ __volatile__("cs %0, %2, %1":"+d"(rv), "=Q"(*atomic)
   1.686 +                         :"d"(newvalue), "m"(*atomic)
   1.687 +                         :"cc");
   1.688 +    return (SDL_bool) (rv == oldvalue);
   1.689  }
   1.690  # elif (SIZEOF_VOIDP == 8)
   1.691  static __inline__ SDL_bool
   1.692 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
   1.693 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
   1.694 +                        void *newvalue)
   1.695  {
   1.696 -  void* rv = oldvalue;
   1.697 -  void** a = atomic;
   1.698 -  __asm__ __volatile__("csg %0, %2, %1"
   1.699 -                       : "+d" (rv),
   1.700 -                         "=Q" (*a)
   1.701 -                       : "d" ((long)(newvalue)),
   1.702 -                         "m" (*a)
   1.703 -                       : "cc");
   1.704 -  return (SDL_bool)(rv == oldvalue);
   1.705 +    void *rv = oldvalue;
   1.706 +    void **a = atomic;
   1.707 +    __asm__ __volatile__("csg %0, %2, %1":"+d"(rv), "=Q"(*a)
   1.708 +                         :"d"((long) (newvalue)), "m"(*a)
   1.709 +                         :"cc");
   1.710 +    return (SDL_bool) (rv == oldvalue);
   1.711  }
   1.712  # else
   1.713  #  error "Your system has an unsupported pointer size"
   1.714 @@ -552,31 +456,34 @@
   1.715  #elif defined(__WIN32__)
   1.716  # include <windows.h>
   1.717  static __inline__ int
   1.718 -SDL_atomic_int_xchg_add(volatile int* atomic, int value)
   1.719 +SDL_atomic_int_xchg_add(volatile int *atomic, int value)
   1.720  {
   1.721 -  return InterlockedExchangeAdd(atomic, value);
   1.722 +    return InterlockedExchangeAdd(atomic, value);
   1.723  }
   1.724  
   1.725  static __inline__ void
   1.726 -SDL_atomic_int_add(volatile int* atomic, int value)
   1.727 +SDL_atomic_int_add(volatile int *atomic, int value)
   1.728  {
   1.729 -  InterlockedExchangeAdd(atomic, value);
   1.730 +    InterlockedExchangeAdd(atomic, value);
   1.731  }
   1.732  
   1.733  # if (WINVER > 0X0400)
   1.734  static __inline__ SDL_bool
   1.735 -SDL_atmoic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue)
   1.736 +SDL_atmoic_int_cmp_xchg(volatile int *atomic, int oldvalue, int newvalue)
   1.737  {
   1.738 -   return (SDL_bool)(InterlockedCompareExchangePointer((PVOID*)atomic,
   1.739 -                                                       (PVOID)newvalue,
   1.740 -                                                       (PVOID)oldvalue) == oldvalue);
   1.741 +    return (SDL_bool) (InterlockedCompareExchangePointer((PVOID *) atomic,
   1.742 +                                                         (PVOID) newvalue,
   1.743 +                                                         (PVOID) oldvalue) ==
   1.744 +                       oldvalue);
   1.745  }
   1.746  
   1.747  
   1.748  static __inline__ SDL_bool
   1.749 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
   1.750 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
   1.751 +                        void *newvalue)
   1.752  {
   1.753 -  return (InterlockedCompareExchangePointer(atomic, newvalue, oldvalue) == oldvalue);
   1.754 +    return (InterlockedCompareExchangePointer(atomic, newvalue, oldvalue) ==
   1.755 +            oldvalue);
   1.756  }
   1.757  # else /* WINVER <= 0x0400 */
   1.758  #  if (SIZEOF_VOIDP != 4)
   1.759 @@ -584,66 +491,69 @@
   1.760  #  endif
   1.761  
   1.762  static __inline__ SDL_bool
   1.763 -SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue)
   1.764 +SDL_atomic_int_cmp_xchg(volatile int *atomic, int oldvalue, int newvalue)
   1.765  {
   1.766 -  return (InterlockedCompareExchange(atomic, newvalue, oldvalue) == oldvalue);
   1.767 +    return (InterlockedCompareExchange(atomic, newvalue, oldvalue) ==
   1.768 +            oldvalue);
   1.769  }
   1.770  
   1.771  static __inline__ SDL_bool
   1.772 -SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
   1.773 +SDL_atomic_ptr_cmp_xchg(volatile void **atomic, void *oldvalue,
   1.774 +                        void *newvalue)
   1.775  {
   1.776 -  return (InterlockedCompareExchange(atomic, newvalue, oldvalue) == oldvalue);
   1.777 +    return (InterlockedCompareExchange(atomic, newvalue, oldvalue) ==
   1.778 +            oldvalue);
   1.779  }
   1.780  # endif
   1.781  #else /* when all else fails */
   1.782  # define SDL_ATOMIC_OPS_NOT_SUPPORTED
   1.783  # warning "Atomic Ops for this platform not supported!"
   1.784  static __inline__ int
   1.785 -SDL_atomic_int_xchg_add(volatile int* atomic, int value)
   1.786 -{                                           
   1.787 -  int rv = *atomic;                          
   1.788 -  *(atomic) += value;                        
   1.789 -  return rv;                                        
   1.790 +SDL_atomic_int_xchg_add(volatile int *atomic, int value)
   1.791 +{
   1.792 +    int rv = *atomic;
   1.793 +    *(atomic) += value;
   1.794 +    return rv;
   1.795  }
   1.796  
   1.797  static __inline__ SDL_bool
   1.798 -SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue)
   1.799 +SDL_atomic_int_cmp_xchg(volatile int *atomic, int oldvalue, int newvalue)
   1.800  {
   1.801 -  return (*atomic == oldvalue) ?  
   1.802 -    ((*atomic = newvalue), SDL_TRUE) : SDL_FALSE;
   1.803 +    return (*atomic == oldvalue) ?
   1.804 +        ((*atomic = newvalue), SDL_TRUE) : SDL_FALSE;
   1.805  }
   1.806  
   1.807  static __inline__ void
   1.808 -SDL_atomic_int_add(volatile int* atomic, int value)
   1.809 +SDL_atomic_int_add(volatile int *atomic, int value)
   1.810  {
   1.811 -  *atomic += value;
   1.812 +    *atomic += value;
   1.813  }
   1.814  #endif /* arch & platforms */
   1.815 -  
   1.816 +
   1.817  #ifdef ATOMIC_INT_CMP_XCHG
   1.818  static __inline__ SDL_bool
   1.819 -SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue)
   1.820 +SDL_atomic_int_cmp_xchg(volatile int *atomic, int oldvalue, int newvalue)
   1.821  {
   1.822 -  return (SDL_bool)ATOMIC_INT_CMP_XCHG(atomic,oldvalue,newvalue);
   1.823 +    return (SDL_bool) ATOMIC_INT_CMP_XCHG(atomic, oldvalue, newvalue);
   1.824  }
   1.825  
   1.826  static __inline__ int
   1.827 -SDL_atomic_int_xchg_add(volatile int* atomic, int value)   
   1.828 -{                                                   
   1.829 -  int rv;                                            
   1.830 -  do                                                 
   1.831 -    rv = *atomic;                                
   1.832 -  while(!ATOMIC_INT_CMP_XCHG(atomic,rv,rv+value)); 
   1.833 -  return rv;                                                
   1.834 +SDL_atomic_int_xchg_add(volatile int *atomic, int value)
   1.835 +{
   1.836 +    int rv;
   1.837 +    do
   1.838 +        rv = *atomic;
   1.839 +    while (!ATOMIC_INT_CMP_XCHG(atomic, rv, rv + value));
   1.840 +    return rv;
   1.841  }
   1.842  
   1.843  static __inline__ void
   1.844 -SDL_atomic_int_add(volatile int* atomic, int value)
   1.845 +SDL_atomic_int_add(volatile int *atomic, int value)
   1.846  {
   1.847 -  int rv;
   1.848 -  do
   1.849 -    rv = *atomic;
   1.850 -  while(!ATOMIC_INT_CMP_XCHG(atomic,rv,rv+value));
   1.851 +    int rv;
   1.852 +    do
   1.853 +        rv = *atomic;
   1.854 +    while (!ATOMIC_INT_CMP_XCHG(atomic, rv, rv + value));
   1.855  }
   1.856  #endif /* ATOMIC_CMP_XCHG */
   1.857