Mercurial > sdl-ios-xcode
annotate include/SDL_atomic.h @ 3188:102b7880543a
Whoops, didn't mean to commit unfinished patch
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 10 Jun 2009 13:46:54 +0000 |
parents | e041d2c603fe |
children | 3e1bf2b8bd81 |
rev | line source |
---|---|
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
1 /* |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
4 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
9 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
14 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
18 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
19 Sam Lantinga |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
20 slouken@libsdl.org |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
21 */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
22 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
23 /** |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
24 * \file SDL_atomic.h |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
25 * |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
26 * Atomic int and pointer magic |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
27 */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
28 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
29 #ifndef _SDL_atomic_h_ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
30 #define _SDL_atomic_h_ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
31 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
32 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
33 #include "SDL_stdinc.h" |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
34 #include "SDL_platform.h" |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
35 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
36 #include "begin_code.h" |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
37 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
38 /* Set up for C function definitions, even when using C++ */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
39 #ifdef __cplusplus |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
40 /* *INDENT-OFF* */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
41 extern "C" { |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
42 /* *INDENT-ON* */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
43 #endif |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
44 |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
45 /* indent is really bad at handling assembly */ |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
46 /* *INDENT-OFF* */ |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
47 |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
48 #if defined(__GNUC__) && (defined(i386) || defined(__i386__) || defined(__x86_64__)) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
49 static __inline__ void |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
50 SDL_atomic_int_add(volatile int* atomic, int value) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
51 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
52 __asm__ __volatile__("lock;" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
53 "addl %1, %0" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
54 : "=m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
55 : "ir" (value), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
56 "m" (*atomic)); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
57 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
58 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
59 static __inline__ int |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
60 SDL_atomic_int_xchg_add(volatile int* atomic, int value) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
61 { |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
62 int rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
63 __asm__ __volatile__("lock;" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
64 "xaddl %0, %1" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
65 : "=r" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
66 "=m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
67 : "0" (value), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
68 "m" (*atomic)); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
69 return rv; |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
70 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
71 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
72 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
73 SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
74 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
75 int rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
76 __asm__ __volatile__("lock;" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
77 "cmpxchgl %2, %1" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
78 : "=a" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
79 "=m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
80 : "r" (newvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
81 "m" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
82 "0" (oldvalue)); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
83 return (SDL_bool)(rv == oldvalue); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
84 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
85 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
86 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
87 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
88 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
89 void* rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
90 __asm__ __volatile__("lock;" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
91 # if defined(__x86_64__) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
92 "cmpxchgq %q2, %1" |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
93 # else |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
94 "cmpxchgl %2, %1" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
95 # endif |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
96 : "=a" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
97 "=m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
98 : "r" (newvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
99 "m" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
100 "0" (oldvalue)); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
101 return (SDL_bool)(rv == oldvalue); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
102 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
103 #elif defined(__GNUC__) && defined(__alpha__) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
104 # define ATOMIC_MEMORY_BARRIER (__asm__ __volatile__ ("mb" : : : "memory")) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
105 # define ATOMIC_INT_CMP_XCHG(atomic,value) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
106 ({ \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
107 int rv,prev; \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
108 __asm__ __volatile__(" mb\n" \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
109 "1: ldl_l %0,%2\n" \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
110 " cmpeq %0,%3,%1\n" \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
111 " beq %1,2f\n" \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
112 " mov %4,%1\n" \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
113 " stl_c %1,%2\n" \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
114 " beq %1,1b\n" \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
115 " mb\n" \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
116 "2:" \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
117 : "=&r" (prev), \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
118 "=&r" (rv) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
119 : "m" (*(atomic)), \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
120 "Ir" (oldvalue), \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
121 "Ir" (newvalue) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
122 : "memory"); \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
123 (rv != 0); \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
124 }) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
125 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
126 # if (SIZEOF_VOIDP == 4) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
127 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
128 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
129 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
130 int rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
131 void* prev; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
132 __asm__ __volatile__(" mb\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
133 "1: ldl_l %0,%2\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
134 " cmpeq %0,%3,%1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
135 " beq $1,2f\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
136 " mov %4,%1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
137 " stl_c %1,%2\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
138 " beq %1,1b\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
139 " mb\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
140 "2:" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
141 : "=&r" (prev), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
142 "=&r" (rv) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
143 : "m" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
144 "Ir" (oldvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
145 "Ir" (newvalue) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
146 : "memory"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
147 return (SDL_bool)(rv != 0); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
148 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
149 # elif (SIZEOF_VOIDP == 8) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
150 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
151 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
152 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
153 int rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
154 void* prev; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
155 __asm__ __volatile__(" mb\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
156 "1: ldq_l %0,%2\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
157 " cmpeq %0,%3,%1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
158 " beq %1,2f\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
159 " mov %4,%1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
160 " stq_c %1,%2\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
161 " beq %1,1b\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
162 " mb\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
163 "2:" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
164 : "=&r" (prev), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
165 "=&r" (rv) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
166 : "m" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
167 "Ir" (oldvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
168 "Ir" (newvalue) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
169 : "memory"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
170 return (SDL_bool)(rv != 0); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
171 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
172 # else |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
173 # error "Your system has an unsupported pointer size" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
174 # endif /* SIZEOF_VOIDP */ |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
175 #elif defined(__GNUC__) && defined(__sparc__) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
176 # define ATOMIC_MEMORY_BARRIER \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
177 (__asm__ __volatile__("membar #LoadLoad | #LoadStore" \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
178 " | #StoreLoad | #StoreStore" : : : "memory")) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
179 # define ATOMIC_INT_CMP_XCHG(atomic,oldvalue,newvalue) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
180 ({ \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
181 int rv; \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
182 __asm__ __volatile__("cas [%4], %2, %0" \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
183 : "=r" (rv), "=m" (*(atomic)) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
184 : "r" (oldvalue), "m" (*(atomic)), \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
185 "r" (atomic), "0" (newvalue)); \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
186 rv == oldvalue; \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
187 }) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
188 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
189 # if (SIZEOF_VOIDP == 4) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
190 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
191 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
192 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
193 void* rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
194 __asm__ __volatile__("cas [%4], %2, %0" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
195 : "=r" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
196 "=m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
197 : "r" (oldvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
198 "m" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
199 "r" (atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
200 "0" (newvalue)); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
201 return (SDL_bool)(rv == oldvalue); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
202 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
203 # elif (SIZEOF_VOIDP == 8) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
204 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
205 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
206 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
207 void* rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
208 void** a = atomic; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
209 __asm__ __volatile__("casx [%4], %2, %0" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
210 : "=r" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
211 "=m" (*a) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
212 : "r" (oldvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
213 "m" (*a), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
214 "r" (a), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
215 "0" (newvalue)); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
216 return (SDL_bool)(rv == oldvalue); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
217 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
218 # else |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
219 # error "Your system has an unsupported pointer size" |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
220 # endif /* SIZEOF_VOIDP */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
221 #elif defined(__GNUC__) && (defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__) || defined(_M_PPC)) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
222 # define ATOMIC_MEMORY_BARRIER \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
223 (__asm__ __volatile__ ("sync" : : : "memory")) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
224 static __inline__ void |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
225 SDL_atomic_int_add(volatile int* atomic, int value) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
226 { |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
227 int rv,tmp; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
228 __asm__ __volatile__("1: lwarx %0, 0, %3\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
229 " add %1, %0, %4\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
230 " stwcx. %1, 0, %3\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
231 " bne- 1b" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
232 : "=&b" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
233 "=&r" (tmp), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
234 "=m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
235 : "b" (atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
236 "r" (value), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
237 "m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
238 : "cr0", |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
239 "memory"); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
240 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
241 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
242 static __inline__ int |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
243 SDL_atomic_int_xchg_add(volatile int* atomic, int value) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
244 { |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
245 int rv,tmp; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
246 __asm__ __volatile__("1: lwarx %0, 0, %3\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
247 " add %1, %0, %4\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
248 " stwcx. %1, 0, %3\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
249 " bne- 1b" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
250 : "=&b" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
251 "=&r" (tmp), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
252 "=m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
253 : "b" (atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
254 "r" (value), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
255 "m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
256 : "cr0", |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
257 "memory"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
258 return rv; |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
259 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
260 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
261 # if (SIZEOF_VOIDP == 4) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
262 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
263 SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
264 { |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
265 int rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
266 __asm__ __volatile__(" sync\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
267 "1: lwarx %0, 0, %1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
268 " subf. %0, %2, %0\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
269 " bne 2f\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
270 " stwcx. %3, 0, %1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
271 " bne- 1b\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
272 "2: isync" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
273 : "=&r" (rv) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
274 : "b" (atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
275 "r" (oldvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
276 "r" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
277 : "cr0", |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
278 "memory"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
279 return (SDL_bool)(rv == 0); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
280 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
281 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
282 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
283 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
284 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
285 void* rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
286 __asm__ __volatile__("sync\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
287 "1: lwarx %0, 0, %1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
288 " subf. %0, %2, %0\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
289 " bne 2f\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
290 " stwcx. %3, 0, %1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
291 " bne- 1b\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
292 "2: isync" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
293 : "=&r" (rv) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
294 : "b" (atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
295 "r" (oldvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
296 "r" (newvalue) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
297 : "cr0", |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
298 "memory"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
299 return (SDL_bool)(rv == 0); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
300 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
301 # elif (SIZEOF_VOIDP == 8) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
302 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
303 SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
304 { |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
305 int rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
306 __asm__ __volatile__(" sync\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
307 "1: lwarx %0, 0, %1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
308 " extsw %0, %0\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
309 " subf. %0, %2, %0\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
310 " bne 2f\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
311 " stwcx. %3, 0, %1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
312 " bne- 1b\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
313 "2: isync" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
314 : "=&r" (rv) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
315 : "b" (atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
316 "r" (oldvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
317 "r" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
318 : "cr0", |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
319 "memory"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
320 return (SDL_bool)(rv == 0); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
321 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
322 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
323 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
324 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
325 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
326 void* rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
327 __asm__ __volatile__("sync\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
328 "1: ldarx %0, 0, %1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
329 " subf. %0, %2, %0\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
330 " bne 2f\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
331 " stdcx. %3, 0, %1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
332 " bne- 1b\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
333 "2: isync" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
334 : "=&r" (rv) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
335 : "b" (atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
336 "r" (oldvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
337 "r" (newvalue) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
338 : "cr0", |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
339 "memory"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
340 return (SDL_bool)(rv == 0); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
341 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
342 # else |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
343 # error "Your system has an unsupported pointer size" |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
344 # endif /* SIZEOF_VOIDP */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
345 #elif defined(__GNUC__) && (defined(__IA64__) || defined(__ia64__)) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
346 # define ATOMIC_MEMORY_BARRIER (__sync_synchronize()) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
347 # define SDL_atomic_int_xchg_add(atomic, value) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
348 (__sync_fetch_and_add((atomic),(value))) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
349 # define SDL_atomic_int_add(atomic, value) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
350 ((void)__sync_fetch_and_add((atomic),(value))) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
351 # define SDL_atomic_int_cmp_xchg(atomic,oldvalue,newvalue) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
352 (__sync_bool_compare_and_swap((atomic),(oldvalue),(newvalue))) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
353 # define SDL_atomic_ptr_cmp_xchg(atomic,oldvalue,newvalue) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
354 (__sync_bool_compare_and_swap((long*)(atomic),(long)(oldvalue),(long)(newvalue))) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
355 #elif defined(__GNUC__) && defined(__LINUX__) && (defined(__mips__) || defined(__MIPS__)) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
356 static __inline__ int |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
357 SDL_atomic_int_xchg_add(volatile int* atomic, int value) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
358 { |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
359 int rv,tmp; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
360 __asm__ __volatile__("1: \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
361 ".set push \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
362 ".set mips2 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
363 "ll %0,%3 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
364 "addu %1,%4,%0 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
365 "sc %1,%2 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
366 ".set pop \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
367 "beqz %1,1b \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
368 : "=&r" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
369 "=&r" (tmp), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
370 "=m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
371 : "m" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
372 "r" (value) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
373 : "memory"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
374 return rv; |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
375 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
376 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
377 static __inline__ void |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
378 SDL_atomic_int_add(volatile int* atomic, int value) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
379 { |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
380 int rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
381 __asm__ __volatile__("1: \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
382 ".set push \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
383 ".set mips2 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
384 "ll %0,%2 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
385 "addu %0,%3,%0 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
386 "sc %0,%1 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
387 ".set pop \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
388 "beqz %0,1b \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
389 : "=&r" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
390 "=m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
391 : "m" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
392 "r" (value) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
393 : "memory"); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
394 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
395 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
396 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
397 SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
398 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
399 int rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
400 __asm__ __volatile__(" .set push \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
401 " .set noat \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
402 " .set mips3 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
403 "1: ll %0, %2 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
404 " bne %0, %z3, 2f \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
405 " .set mips0 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
406 " move $1, %z4 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
407 " .set mips3 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
408 " sc $1, %1 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
409 " beqz $1, 1b \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
410 " sync \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
411 "2: \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
412 " .set pop \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
413 : "=&r" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
414 "=R" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
415 : "R" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
416 "Jr" (oldvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
417 "Jr" (newvalue) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
418 : "memory"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
419 return (SDL_bool)rv; |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
420 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
421 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
422 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
423 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
424 { |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
425 int rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
426 __asm__ __volatile__(" .set push \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
427 " .set noat \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
428 " .set mips3 \n" |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
429 # if defined(__mips64) |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
430 "1: lld %0, %2 \n" |
3186 | 431 # else |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
432 "1: ll %0, %2 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
433 # endif |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
434 " bne %0, %z3, 2f \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
435 " move $1, %z4 \n" |
3186 | 436 # if defined(__mips64) |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
437 " sc $1, %1 \n" |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
438 # else |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
439 " scd $1, %1 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
440 # endif |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
441 " beqz $1, 1b \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
442 " sync \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
443 "2: \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
444 " .set pop \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
445 : "=&r" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
446 "=R" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
447 : "R" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
448 "Jr" (oldvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
449 "Jr" (newvalue) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
450 : "memory"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
451 return (SDL_bool)rv; |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
452 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
453 #elif defined(__GNUC__) && defined(__m68k__) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
454 static __inline__ int |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
455 SDL_atomic_int_xchg_add(volatile int* atomic, int value) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
456 { |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
457 int rv = *atomic; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
458 int tmp; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
459 __asm__ __volatile__("1: move%.l %0,%1 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
460 " add%.l %2,%1 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
461 " cas%.l %0,%1,%3 \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
462 " jbne 1b \n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
463 : "=d" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
464 "=&d" (tmp) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
465 : "d" (value), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
466 "m" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
467 "0" (rv) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
468 : "memory"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
469 return (SDL_bool)rv; |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
470 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
471 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
472 static __inline__ void |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
473 SDL_atomic_int_add(volatile int* atomic, int value) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
474 { |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
475 __asm__ __volatile__("add%.l %0,%1" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
476 : |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
477 : "id" (value), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
478 "m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
479 : "memory"); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
480 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
481 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
482 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
483 SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
484 { |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
485 char rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
486 int readvalue; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
487 __asm__ __volatile__("cas%.l %2,%3,%1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
488 "seq %0" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
489 : "=dm" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
490 "=m" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
491 "=d" (readvalue) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
492 : "d" (newvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
493 "m" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
494 "2" (oldvalue)); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
495 return (SDL_bool)rv; |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
496 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
497 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
498 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
499 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
500 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
501 char rv; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
502 int readvalue; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
503 __asm__ __volatile__("cas%.l %2,%3,%1\n" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
504 "seq %0" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
505 : "=dm" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
506 "=m" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
507 "=d" (readvalue) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
508 : "d" (newvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
509 "m" (*atomic), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
510 "2" (oldvalue)); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
511 return (SDL_bool)rv; |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
512 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
513 #elif defined(__GNUC__) && defined(__s390__) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
514 # define ATOMIC_INT_CMP_XCHG(atomic,oldvalue,newvalue) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
515 ({ \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
516 int rv = oldvalue; \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
517 __asm__ __volatile__("cs %0, %2, %1" \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
518 : "+d" (rv), \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
519 "=Q" (*(atomic)) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
520 : "d" (newvalue), \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
521 "m" (*(atomic)) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
522 : "cc"); \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
523 rv == oldvalue; \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
524 }) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
525 # if (SIZEOF_VOIDP == 4) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
526 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
527 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
528 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
529 void* rv = oldvalue; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
530 __asm__ __volatile__("cs %0, %2, %1" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
531 : "+d" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
532 "=Q" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
533 : "d" (newvalue), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
534 "m" (*atomic) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
535 : "cc"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
536 return (SDL_bool)(rv == oldvalue); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
537 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
538 # elif (SIZEOF_VOIDP == 8) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
539 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
540 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
541 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
542 void* rv = oldvalue; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
543 void** a = atomic; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
544 __asm__ __volatile__("csg %0, %2, %1" |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
545 : "+d" (rv), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
546 "=Q" (*a) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
547 : "d" ((long)(newvalue)), |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
548 "m" (*a) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
549 : "cc"); |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
550 return (SDL_bool)(rv == oldvalue); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
551 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
552 # else |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
553 # error "Your system has an unsupported pointer size" |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
554 # endif /* SIZEOF_VOIDP */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
555 #elif defined(__WIN32__) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
556 # include <windows.h> |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
557 static __inline__ int |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
558 SDL_atomic_int_xchg_add(volatile int* atomic, int value) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
559 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
560 return InterlockedExchangeAdd(atomic, value); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
561 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
562 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
563 static __inline__ void |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
564 SDL_atomic_int_add(volatile int* atomic, int value) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
565 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
566 InterlockedExchangeAdd(atomic, value); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
567 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
568 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
569 # if (WINVER > 0X0400) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
570 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
571 SDL_atmoic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
572 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
573 return (SDL_bool)(InterlockedCompareExchangePointer((PVOID*)atomic, |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
574 (PVOID)newvalue, |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
575 (PVOID)oldvalue) == oldvalue); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
576 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
577 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
578 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
579 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
580 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
581 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
582 return (InterlockedCompareExchangePointer(atomic, newvalue, oldvalue) == oldvalue); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
583 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
584 # else /* WINVER <= 0x0400 */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
585 # if (SIZEOF_VOIDP != 4) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
586 # error "InterlockedCompareExchangePointer needed" |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
587 # endif |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
588 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
589 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
590 SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
591 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
592 return (InterlockedCompareExchange(atomic, newvalue, oldvalue) == oldvalue); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
593 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
594 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
595 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
596 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
597 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
598 return (InterlockedCompareExchange(atomic, newvalue, oldvalue) == oldvalue); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
599 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
600 # endif |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
601 #else /* when all else fails */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
602 # define SDL_ATOMIC_OPS_NOT_SUPPORTED |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
603 # warning "Atomic Ops for this platform not supported!" |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
604 static __inline__ int |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
605 SDL_atomic_int_xchg_add(volatile int* atomic, int value) |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
606 { |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
607 int rv = *atomic; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
608 *(atomic) += value; |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
609 return rv; |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
610 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
611 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
612 static __inline__ SDL_bool |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
613 SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
614 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
615 return (*atomic == oldvalue) ? |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
616 ((*atomic = newvalue), SDL_TRUE) : SDL_FALSE; |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
617 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
618 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
619 static __inline__ void |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
620 SDL_atomic_int_add(volatile int* atomic, int value) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
621 { |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
622 *atomic += value; |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
623 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
624 #endif /* arch & platforms */ |
3187
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
625 |
e041d2c603fe
indent is really bad at handling assembly
Sam Lantinga <slouken@libsdl.org>
parents:
3186
diff
changeset
|
626 /* *INDENT-ON* */ |
3186 | 627 |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
628 #ifdef ATOMIC_INT_CMP_XCHG |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
629 static __inline__ SDL_bool |
3186 | 630 SDL_atomic_int_cmp_xchg(volatile int *atomic, int oldvalue, int newvalue) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
631 { |
3186 | 632 return (SDL_bool) ATOMIC_INT_CMP_XCHG(atomic, oldvalue, newvalue); |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
633 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
634 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
635 static __inline__ int |
3186 | 636 SDL_atomic_int_xchg_add(volatile int *atomic, int value) |
637 { | |
638 int rv; | |
639 do | |
640 rv = *atomic; | |
641 while (!ATOMIC_INT_CMP_XCHG(atomic, rv, rv + value)); | |
642 return rv; | |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
643 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
644 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
645 static __inline__ void |
3186 | 646 SDL_atomic_int_add(volatile int *atomic, int value) |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
647 { |
3186 | 648 int rv; |
649 do | |
650 rv = *atomic; | |
651 while (!ATOMIC_INT_CMP_XCHG(atomic, rv, rv + value)); | |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
652 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
653 #endif /* ATOMIC_CMP_XCHG */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
654 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
655 #ifdef ATOMIC_MEMORY_BARRIER |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
656 # define SDL_atomic_int_get(atomic) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
657 (ATOMIC_MEMORY_BARRIER,*(atomic)) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
658 # define SDL_atomic_int_set(atomic,value) \ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
659 (*(atomic)=value,ATOMIC_MEMORY_BARRIER) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
660 #else |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
661 # define SDL_atomic_int_get(atomic) (*(atomic)) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
662 # define SDL_atomic_int_set(atomic, newvalue) ((void)(*(atomic) = (newvalue))) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
663 #endif /* MEMORY_BARRIER_NEEDED */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
664 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
665 #define SDL_atomic_int_inc(atomic) (SDL_atomic_int_add((atomic),1)) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
666 #define SDL_atomic_int_dec_test(atomic) (SDL_atomic_int_xchg_add((atomic),-1) == 1) |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
667 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
668 /* Ends C function definitions when using C++ */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
669 #ifdef __cplusplus |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
670 /* *INDENT-OFF* */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
671 } |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
672 /* *INDENT-ON* */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
673 #endif |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
674 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
675 #include "close_code.h" |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
676 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
677 #endif /* _SDL_atomic_h_ */ |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
678 |
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
679 /* vi: set ts=4 sw=4 expandtab: */ |