Apache HTTPD
ppc.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "apr_arch_atomic.h"
18
19#ifdef USE_ATOMICS_PPC
20
21#ifdef PPC405_ERRATA
22# define PPC405_ERR77_SYNC " sync\n"
23#else
24# define PPC405_ERR77_SYNC
25#endif
26
28{
29#if defined(USE_ATOMICS_GENERIC64)
31#else
32 return APR_SUCCESS;
33#endif
34}
35
37{
39 asm volatile (" sync\n" /* full barrier */
40 " lwz %0,%1\n" /* load */
41 " cmpw 7,%0,%0\n" /* compare (always equal) */
42 " bne- 7,$+4\n" /* goto next in any case */
43 " isync" /* acquire barrier (bc+isync) */
44 : "=r"(val)
45 : "m"(*mem)
46 : "cc", "memory");
47 return val;
48}
49
51{
52 asm volatile (" sync\n" /* full barrier */
53 " stw %1,%0" /* store */
54 : "=m"(*mem)
55 : "r"(val)
56 : "memory");
57}
58
60{
61 apr_uint32_t prev, temp;
62
63 asm volatile (" sync\n" /* full barrier */
64 "1:\n" /* lost reservation */
65 " lwarx %0,0,%3\n" /* load and reserve */
66 " add %1,%0,%4\n" /* add val and prev */
67 PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
68 " stwcx. %1,0,%3\n" /* store if still reserved */
69 " bne- 1b\n" /* loop if lost */
70 " isync\n" /* acquire barrier (bc+isync) */
71 : "=&r" (prev), "=&r" (temp), "=m" (*mem)
72 : "b" (mem), "r" (val)
73 : "cc", "memory");
74
75 return prev;
76}
77
79{
81
82 asm volatile (" sync\n" /* full barrier */
83 "1:\n" /* lost reservation */
84 " lwarx %0,0,%2\n" /* load and reserve */
85 " subf %0,%3,%0\n" /* subtract val */
86 PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
87 " stwcx. %0,0,%2\n" /* store new value */
88 " bne- 1b\n" /* loop if lost */
89 " isync\n" /* acquire barrier (bc+isync) */
90 : "=&r" (temp), "=m" (*mem)
91 : "b" (mem), "r" (val)
92 : "cc", "memory");
93}
94
96{
97 apr_uint32_t prev;
98
99 asm volatile (" sync\n" /* full barrier */
100 "1:\n" /* lost reservation */
101 " lwarx %0,0,%2\n" /* load and reserve */
102 " addi %0,%0,1\n" /* add immediate */
103 PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
104 " stwcx. %0,0,%2\n" /* store new value */
105 " bne- 1b\n" /* loop if lost */
106 " subi %0,%0,1\n" /* return old value */
107 " isync\n" /* acquire barrier (bc+isync) */
108 : "=&b" (prev), "=m" (*mem)
109 : "b" (mem), "m" (*mem)
110 : "cc", "memory");
111
112 return prev;
113}
114
116{
117 apr_uint32_t prev;
118
119 asm volatile (" sync\n" /* full barrier */
120 "1:\n" /* lost reservation */
121 " lwarx %0,0,%2\n" /* load and reserve */
122 " subi %0,%0,1\n" /* subtract immediate */
123 PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
124 " stwcx. %0,0,%2\n" /* store new value */
125 " bne- 1b\n" /* loop if lost */
126 " isync\n" /* acquire barrier (bc+isync) */
127 : "=&b" (prev), "=m" (*mem)
128 : "b" (mem), "m" (*mem)
129 : "cc", "memory");
130
131 return prev;
132}
133
136{
137 apr_uint32_t prev;
138
139 asm volatile (" sync\n" /* full barrier */
140 "1:\n" /* lost reservation */
141 " lwarx %0,0,%1\n" /* load and reserve */
142 " cmpw %0,%3\n" /* compare operands */
143 " bne- exit_%=\n" /* skip if not equal */
144 PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
145 " stwcx. %2,0,%1\n" /* store new value */
146 " bne- 1b\n" /* loop if lost */
147 "exit_%=:\n" /* not equal */
148 " isync\n" /* acquire barrier (bc+isync) */
149 : "=&r" (prev)
150 : "b" (mem), "r" (with), "r" (cmp)
151 : "cc", "memory");
152
153 return prev;
154}
155
157{
158 apr_uint32_t prev;
159
160 asm volatile (" sync\n" /* full barrier */
161 "1:\n" /* lost reservation */
162 " lwarx %0,0,%1\n" /* load and reserve */
163 PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
164 " stwcx. %2,0,%1\n" /* store new value */
165 " bne- 1b\n" /* loop if lost */
166 " isync\n" /* acquire barrier (bc+isync) */
167 : "=&r" (prev)
168 : "b" (mem), "r" (val)
169 : "cc", "memory");
170
171 return prev;
172}
173
174APR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
175{
176 void *prev;
177#if APR_SIZEOF_VOIDP == 4
178 asm volatile (" sync\n" /* full barrier */
179 "1:\n" /* lost reservation */
180 " lwarx %0,0,%1\n" /* load and reserve */
181 " cmpw %0,%3\n" /* compare operands */
182 " bne- 2f\n" /* skip if not equal */
183 PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
184 " stwcx. %2,0,%1\n" /* store new value */
185 " bne- 1b\n" /* loop if lost */
186 "2:\n" /* not equal */
187 " isync\n" /* acquire barrier (bc+isync) */
188 : "=&r" (prev)
189 : "b" (mem), "r" (with), "r" (cmp)
190 : "cc", "memory");
191#elif APR_SIZEOF_VOIDP == 8
192 asm volatile (" sync\n" /* full barrier */
193 "1:\n" /* lost reservation */
194 " ldarx %0,0,%1\n" /* load and reserve */
195 " cmpd %0,%3\n" /* compare operands */
196 " bne- 2f\n" /* skip if not equal */
197 PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
198 " stdcx. %2,0,%1\n" /* store new value */
199 " bne- 1b\n" /* loop if lost */
200 "2:\n" /* not equal */
201 " isync\n" /* acquire barrier (bc+isync) */
202 : "=&r" (prev)
203 : "b" (mem), "r" (with), "r" (cmp)
204 : "cc", "memory");
205#else
206#error APR_SIZEOF_VOIDP value not supported
207#endif
208 return prev;
209}
210
211APR_DECLARE(void*) apr_atomic_xchgptr(volatile void **mem, void *with)
212{
213 void *prev;
214#if APR_SIZEOF_VOIDP == 4
215 asm volatile (" sync\n" /* full barrier */
216 "1:\n" /* lost reservation */
217 " lwarx %0,0,%1\n" /* load and reserve */
218 PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
219 " stwcx. %2,0,%1\n" /* store new value */
220 " bne- 1b\n" /* loop if lost */
221 " isync\n" /* acquire barrier (bc+isync) */
222 : "=&r" (prev)
223 : "b" (mem), "r" (with)
224 : "cc", "memory");
225#elif APR_SIZEOF_VOIDP == 8
226 asm volatile (" sync\n" /* full barrier */
227 "1:\n" /* lost reservation */
228 " ldarx %0,0,%1\n" /* load and reserve */
229 PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
230 " stdcx. %2,0,%1\n" /* store new value */
231 " bne- 1b\n" /* loop if lost */
232 " isync\n" /* acquire barrier (bc+isync) */
233 : "=&r" (prev)
234 : "b" (mem), "r" (with)
235 : "cc", "memory");
236#else
237#error APR_SIZEOF_VOIDP value not supported
238#endif
239 return prev;
240}
241
242#endif /* USE_ATOMICS_PPC */
apr_status_t apr__atomic_generic64_init(apr_pool_t *p)
apr_uint32_t apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
Definition atomic.c:30
void apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
Definition atomic.c:41
apr_uint32_t apr_atomic_inc32(volatile apr_uint32_t *mem)
Definition atomic.c:51
apr_uint32_t apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
Definition atomic.c:111
int apr_atomic_dec32(volatile apr_uint32_t *mem)
Definition atomic.c:56
apr_status_t apr_atomic_init(apr_pool_t *p)
Definition atomic.c:21
void apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
Definition atomic.c:73
apr_uint32_t apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t swap, apr_uint32_t cmp)
Definition atomic.c:78
apr_uint32_t apr_atomic_read32(volatile apr_uint32_t *mem)
Definition atomic.c:68
const void apr_status_t(*) apr_status_t(* APR_DECLARE)(void) apr_pool_pre_cleanup_register(apr_pool_t *p
Definition apr_pools.h:646
apr_size_t size
apr_uint32_t apr_uint32_t cmp
Definition apr_atomic.h:106
apr_uint32_t with
Definition apr_atomic.h:105
apr_uint32_t val
Definition apr_atomic.h:66
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * mem
apr_pool_t * p
Definition md_event.c:32