1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/* Copyright (c) 2005, Tim Blechmann
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt" in this distribution. */
#if defined(__GNUC__) && (defined(_X86_) || defined(__i386__) || defined(__i586__) || defined(__i686__))
/* gcc, x86 */
#define ATOMIC_INC(X) \
asm __volatile__("lock incl (%0) \n" \
: :"r"(X) :"memory")
#define ATOMIC_DEC(X) \
asm __volatile__("lock decl (%0) \n" \
: :"r"(X) :"memory")
#elif defined(NT) && defined(_MSC_VER)
/* msvc */
#include <windows.h>
#define ATOMIC_INC(X) InterlockedIncrement(X)
#define ATOMIC_DEC(X) InterlockedDecrement(X)
#elif defined(__GNUC__) && defined(__POWERPC__)
/* ppc */
#define ATOMIC_INC(X) { \
int X##_i; \
asm __volatile__( \
"1: \n" \
"lwarx %0, 0, %2 \n" \
"addic %0, %0, 1 \n" \
"stwcx. %0, 0, %2 \n" \
"bne- 1b \n" \
:"=&r"(X##_i), "=m"(X) \
: "r" (&X), "m"(X) \
: "cc"); }
#define ATOMIC_DEC(X) { \
int X##_i; \
asm __volatile__( \
"1: \n" \
"lwarx %0, 0, %2 \n" \
"addic %0, %0, -1 \n" \
"stwcx. %0, 0, %2 \n" \
"bne- 1b \n" \
:"=&r"(X##_i), "=m"(X) \
: "r" (&X), "m"(X) \
: "cc"); }
#endif
|