~ubuntu-branches/ubuntu/natty/eglibc/natty-security

« back to all changes in this revision

Viewing changes to sysdeps/powerpc/powerpc32/bits/atomic.h

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno
  • Date: 2009-05-05 09:54:14 UTC
  • Revision ID: james.westby@ubuntu.com-20090505095414-c45qsg9ixjheohru
ImportĀ upstreamĀ versionĀ 2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Atomic operations.  PowerPC32 version.
 
2
   Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
 
3
   This file is part of the GNU C Library.
 
4
   Contributed by Paul Mackerras <paulus@au.ibm.com>, 2003.
 
5
 
 
6
   The GNU C Library is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU Lesser General Public
 
8
   License as published by the Free Software Foundation; either
 
9
   version 2.1 of the License, or (at your option) any later version.
 
10
 
 
11
   The GNU C Library is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
   Lesser General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU Lesser General Public
 
17
   License along with the GNU C Library; if not, write to the Free
 
18
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
19
   02111-1307 USA.  */
 
20
 
 
21
/*  POWER6 adds a "Mutex Hint" to the Load and Reserve instruction.
 
22
    This is a hint to the hardware to expect additional updates adjacent
 
23
    to the lock word or not.  If we are acquiring a Mutex, the hint
 
24
    should be true. Otherwise we releasing a Mutex or doing a simple
 
25
    atomic operation.  In that case we don't expect addtional updates
 
26
    adjacent to the lock word after the Store Conditional and the hint
 
27
    should be false.  */
 
28
    
 
29
#if defined _ARCH_PWR6 || defined _ARCH_PWR6X
 
30
# define MUTEX_HINT_ACQ ",1"
 
31
# define MUTEX_HINT_REL ",0"
 
32
#else
 
33
# define MUTEX_HINT_ACQ
 
34
# define MUTEX_HINT_REL
 
35
#endif
 
36
 
 
37
/*
 
38
 * The 32-bit exchange_bool is different on powerpc64 because the subf
 
39
 * does signed 64-bit arthmatic while the lwarx is 32-bit unsigned
 
40
 * (a load word and zero (high 32) form).  So powerpc64 has a slightly
 
41
 * different version in sysdeps/powerpc/powerpc64/bits/atomic.h.
 
42
 */
 
43
#define __arch_compare_and_exchange_bool_32_acq(mem, newval, oldval)         \
 
44
({                                                                            \
 
45
  unsigned int __tmp;                                                         \
 
46
  __asm __volatile (                                                          \
 
47
                    "1: lwarx   %0,0,%1" MUTEX_HINT_ACQ "\n"                  \
 
48
                    "   subf.   %0,%2,%0\n"                                   \
 
49
                    "   bne     2f\n"                                         \
 
50
                    "   stwcx.  %3,0,%1\n"                                    \
 
51
                    "   bne-    1b\n"                                         \
 
52
                    "2: " __ARCH_ACQ_INSTR                                    \
 
53
                    : "=&r" (__tmp)                                           \
 
54
                    : "b" (mem), "r" (oldval), "r" (newval)                   \
 
55
                    : "cr0", "memory");                                       \
 
56
  __tmp != 0;                                                                 \
 
57
})
 
58
 
 
59
#define __arch_compare_and_exchange_bool_32_rel(mem, newval, oldval)          \
 
60
({                                                                            \
 
61
  unsigned int __tmp;                                                         \
 
62
  __asm __volatile (__ARCH_REL_INSTR "\n"                                     \
 
63
                    "1: lwarx   %0,0,%1" MUTEX_HINT_REL "\n"                  \
 
64
                    "   subf.   %0,%2,%0\n"                                   \
 
65
                    "   bne     2f\n"                                         \
 
66
                    "   stwcx.  %3,0,%1\n"                                    \
 
67
                    "   bne-    1b\n"                                         \
 
68
                    "2: "                                                     \
 
69
                    : "=&r" (__tmp)                                           \
 
70
                    : "b" (mem), "r" (oldval), "r" (newval)                   \
 
71
                    : "cr0", "memory");                                       \
 
72
  __tmp != 0;                                                                 \
 
73
})
 
74
 
 
75
/* Powerpc32 processors don't implement the 64-bit (doubleword) forms of
 
76
   load and reserve (ldarx) and store conditional (stdcx.) instructions.
 
77
   So for powerpc32 we stub out the 64-bit forms.  */
 
78
#define __arch_compare_and_exchange_bool_64_acq(mem, newval, oldval) \
 
79
  (abort (), 0)
 
80
 
 
81
#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
 
82
  (abort (), (__typeof (*mem)) 0)
 
83
 
 
84
#define __arch_compare_and_exchange_bool_64_rel(mem, newval, oldval) \
 
85
  (abort (), 0)
 
86
 
 
87
#define __arch_compare_and_exchange_val_64_rel(mem, newval, oldval) \
 
88
  (abort (), (__typeof (*mem)) 0)
 
89
 
 
90
#define __arch_atomic_exchange_64_acq(mem, value) \
 
91
    ({ abort (); (*mem) = (value); })
 
92
 
 
93
#define __arch_atomic_exchange_64_rel(mem, value) \
 
94
    ({ abort (); (*mem) = (value); })
 
95
 
 
96
#define __arch_atomic_exchange_and_add_64(mem, value) \
 
97
    ({ abort (); (*mem) = (value); })
 
98
 
 
99
#define __arch_atomic_increment_val_64(mem) \
 
100
    ({ abort (); (*mem)++; })
 
101
 
 
102
#define __arch_atomic_decrement_val_64(mem) \
 
103
    ({ abort (); (*mem)--; })
 
104
 
 
105
#define __arch_atomic_decrement_if_positive_64(mem) \
 
106
    ({ abort (); (*mem)--; })
 
107
 
 
108
#ifdef _ARCH_PWR4
 
109
/*
 
110
 * Newer powerpc64 processors support the new "light weight" sync (lwsync)
 
111
 * So if the build is using -mcpu=[power4,power5,power5+,970] we can
 
112
 * safely use lwsync.
 
113
 */
 
114
# define atomic_read_barrier()  __asm ("lwsync" ::: "memory")
 
115
/*
 
116
 * "light weight" sync can also be used for the release barrier.
 
117
 */
 
118
# ifndef UP
 
119
#  define __ARCH_REL_INSTR      "lwsync"
 
120
# endif
 
121
#else
 
122
/*
 
123
 * Older powerpc32 processors don't support the new "light weight"
 
124
 * sync (lwsync).  So the only safe option is to use normal sync
 
125
 * for all powerpc32 applications.
 
126
 */
 
127
# define atomic_read_barrier()  __asm ("sync" ::: "memory")
 
128
#endif
 
129
 
 
130
/*
 
131
 * Include the rest of the atomic ops macros which are common to both
 
132
 * powerpc32 and powerpc64.
 
133
 */
 
134
#include_next <bits/atomic.h>