Browse code

- reverted to addic instead of addi - sometimes gcc uses r0 as the second operand in addi and addi rD,r0, val is a special case, equivalent with rD=0+val and not rD=r0+val. addic does not have this problem (but sets the carry flag in XER). - some macro fixes

Andrei Pelinescu-Onciul authored on 18/05/2007 10:08:47
Showing 1 changed files
... ...
@@ -30,6 +30,10 @@
30 30
  * --------
31 31
  *  2006-03-24  created by andrei
32 32
  *  2007-05-11  added atomic_add and atomic_cmpxchg (andrei)
33
+ *  2007-05-18  reverted to addic instead of addi - sometimes gcc uses
34
+ *               r0 as the second operand in addi and  addi rD,r0, val
35
+ *               is a special case, equivalent with rD=0+val and not
36
+ *               rD=r0+val (andrei)
33 37
  */
34 38
 
35 39
 #ifndef _atomic_ppc_h
... ...
@@ -76,7 +80,8 @@
76 76
 	"1: lwarx  %0, 0, %2 \n\t" \
77 77
 	"   " op " \n\t" \
78 78
 	"   stwcx. %3, 0, %2 \n\t" \
79
-	"   bne- 1b \n\t"
79
+	"   bne- 1b \n\t" \
80
+	"2: \n\t"
80 81
 
81 82
 #ifdef __CPU_ppc64
82 83
 #define ATOMIC_ASM_OP0_long(op) \
... ...
@@ -89,7 +94,8 @@
89 89
 	"1: ldarx  %0, 0, %2 \n\t" \
90 90
 	"   " op " \n\t" \
91 91
 	"   stdcx. %3, 0, %2 \n\t" \
92
-	"   bne- 1b \n\t"
92
+	"   bne- 1b \n\t" \
93
+	"2: \n\t"
93 94
 
94 95
 #else /* __CPU_ppc */
95 96
 #define ATOMIC_ASM_OP0_long ATOMIC_ASM_OP0_int
... ...
@@ -137,7 +143,7 @@
137 137
 /* cmpxchg, %3=var, %0=*var, %4=old, %3=new  */
138 138
 #define ATOMIC_CMPXCHG_DECL(NAME, P_TYPE) \
139 139
 	inline static P_TYPE atomic_##NAME##_##P_TYPE (volatile P_TYPE *var, \
140
-															P_TYPE old \
140
+															P_TYPE old, \
141 141
 															P_TYPE new_v) \
142 142
 	{ \
143 143
 		P_TYPE ret; \
... ...
@@ -153,22 +159,22 @@
153 153
 
154 154
 
155 155
 
156
-ATOMIC_FUNC_DECL(inc,      "addi  %0, %0,  1", int, void, /* no return */ )
157
-ATOMIC_FUNC_DECL(dec,      "addi %0, %0,  -1", int, void, /* no return */ )
156
+ATOMIC_FUNC_DECL(inc,      "addic  %0, %0,  1", int, void, /* no return */ )
157
+ATOMIC_FUNC_DECL(dec,      "addic %0, %0,  -1", int, void, /* no return */ )
158 158
 ATOMIC_FUNC_DECL1(and,     "and     %0, %0, %3", int, void, /* no return */ )
159 159
 ATOMIC_FUNC_DECL1(or,      "or     %0, %0, %3", int, void, /* no return */ )
160
-ATOMIC_FUNC_DECL(inc_and_test, "addi   %0, %0, 1", int, int, (ret==0) )
161
-ATOMIC_FUNC_DECL(dec_and_test, "addi  %0, %0, -1", int, int, (ret==0) )
160
+ATOMIC_FUNC_DECL(inc_and_test, "addic   %0, %0, 1", int, int, (ret==0) )
161
+ATOMIC_FUNC_DECL(dec_and_test, "addic  %0, %0, -1", int, int, (ret==0) )
162 162
 ATOMIC_FUNC_DECL3(get_and_set, /* no extra op needed */ , int, int,  ret)
163 163
 ATOMIC_CMPXCHG_DECL(cmpxchg, int)
164 164
 ATOMIC_FUNC_DECL1(add, "add %0, %0, %3" , int, int,  ret)
165 165
 
166
-ATOMIC_FUNC_DECL(inc,      "addi  %0, %0,  1", long, void, /* no return */ )
167
-ATOMIC_FUNC_DECL(dec,      "addi %0, %0,  -1", long, void, /* no return */ )
166
+ATOMIC_FUNC_DECL(inc,      "addic  %0, %0,  1", long, void, /* no return */ )
167
+ATOMIC_FUNC_DECL(dec,      "addic %0, %0,  -1", long, void, /* no return */ )
168 168
 ATOMIC_FUNC_DECL1(and,     "and     %0, %0, %3",long, void, /* no return */ )
169 169
 ATOMIC_FUNC_DECL1(or,      "or     %0, %0, %3", long, void, /* no return */ )
170
-ATOMIC_FUNC_DECL(inc_and_test, "addi   %0, %0, 1", long, long, (ret==0) )
171
-ATOMIC_FUNC_DECL(dec_and_test, "addi  %0, %0, -1", long, long, (ret==0) )
170
+ATOMIC_FUNC_DECL(inc_and_test, "addic   %0, %0, 1", long, long, (ret==0) )
171
+ATOMIC_FUNC_DECL(dec_and_test, "addic  %0, %0, -1", long, long, (ret==0) )
172 172
 ATOMIC_FUNC_DECL3(get_and_set, /* no extra op needed */ , long, long,  ret)
173 173
 ATOMIC_CMPXCHG_DECL(cmpxchg, long)
174 174
 ATOMIC_FUNC_DECL1(add, "add %0, %0, %3" , long, long,  ret)