comparison src/os/unix/ngx_gcc_atomic_ppc.h @ 110:dad2fe8ecf08 NGINX_0_3_2

nginx 0.3.2 *) Feature: the Sun Studio 10 C compiler support. *) Feature: the "proxy_upstream_max_fails", "proxy_upstream_fail_timeout", "fastcgi_upstream_max_fails", and "fastcgi_upstream_fail_timeout" directives.
author Igor Sysoev <http://sysoev.ru>
date Wed, 12 Oct 2005 00:00:00 +0400
parents
children 408f195b3482
comparison
equal deleted inserted replaced
109:97da525033a1 110:dad2fe8ecf08
1
2 /*
3 * Copyright (C) Igor Sysoev
4 */
5
6
7 /*
8 * The ppc assembler treats ";" as comment, so we have to use "\n".
9 * The minus in "bne-" is a hint for the branch prediction unit that
10 * this branch is unlikely to be taken.
11 * The "1b" means the nearest backward label "1" and the "1f" means
12 * the nearest forward label "1".
13 *
14 * The "b" means that the base registers can be used only, i.e.
15 * any register except r0. The r0 register always has a zero value and
16 * could not be used in "addi r0, r0, 1".
17 * The "=&b" means that no input registers can be used.
18 */
19
20 static ngx_inline ngx_atomic_uint_t
21 ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old,
22 ngx_atomic_uint_t set)
23 {
24 ngx_atomic_uint_t res, temp;
25
26 __asm__ volatile (
27
28 " li %0, 0 \n" /* preset "0" to "res" */
29 " lwarx %1, 0, %2 \n" /* load from [lock] into "temp" */
30 /* and store reservation */
31 " cmpw %1, %3 \n" /* compare "temp" and "old" */
32 " bne- 1f \n" /* not equal */
33 " stwcx. %4, 0, %2 \n" /* store "set" into [lock] if reservation */
34 /* is not cleared */
35 " bne- 1f \n" /* the reservation was cleared */
36 " li %0, 1 \n" /* set "1" to "res" */
37 "1: \n"
38
39 : "=&b" (res), "=&b" (temp)
40 : "b" (lock), "b" (old), "b" (set)
41 : "cc", "memory");
42
43 return res;
44 }
45
46
47 static ngx_inline ngx_atomic_int_t
48 ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add)
49 {
50 ngx_atomic_uint_t res, temp;
51
52 __asm__ volatile (
53
54 "1: lwarx %0, 0, %2 \n" /* load from [value] into "res" */
55 /* and store reservation */
56 " add %1, %0, %3 \n" /* "res" + "add" store in "temp" */
57 " stwcx. %1, 0, %2 \n" /* store "temp" into [value] if reservation */
58 /* is not cleared */
59 " bne- 1b \n" /* try again if reservation was cleared */
60
61 : "=&b" (res), "=&b" (temp)
62 : "b" (value), "b" (add)
63 : "cc", "memory");
64
65 return res;
66 }