2 Copyright (c) 2003, Keir Fraser All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution. Neither the name of the Keir Fraser
14 * nor the names of its contributors may be used to endorse or
15 * promote products derived from this software without specific
16 * prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef __IA64_DEFNS_H__
32 #define __IA64_DEFNS_H__
41 #define CACHE_LINE_SIZE 64
44 * I. Compare-and-swap.
47 #define CAS32(_a, _o, _n) \
48 ({ __typeof__(_o) __o = _o; \
49 __asm__ __volatile__("mov ar.ccv=%0 ;;" :: "rO" (_o)); \
50 __asm__ __volatile__("cmpxchg4.acq %0=%1,%2,ar.ccv ;; " \
51 : "=r" (__o), "=m" (*(_a)) \
56 #define CAS64(_a, _o, _n) \
57 ({ __typeof__(_o) __o = _o; \
58 __asm__ __volatile__("mov ar.ccv=%0 ;;" :: "rO" (_o)); \
59 __asm__ __volatile__("cmpxchg8.acq %0=%1,%2,ar.ccv ;; " \
60 : "=r" (__o), "=m" (*(_a)) \
65 #define FAS32(_a, _n) \
66 ({ __typeof__(_n) __o; \
67 __asm__ __volatile__("xchg4 %0=%1,%2 ;; " \
68 : "=r" (__o), "=m" (*(_a)) \
73 #define FAS64(_a, _n) \
74 ({ __typeof__(_n) __o; \
75 __asm__ __volatile__("xchg8 %0=%1,%2 ;; " \
76 : "=r" (__o), "=m" (*(_a)) \
81 #define CAS(_x,_o,_n) ((sizeof (*_x) == 4)?CAS32(_x,_o,_n):CAS64(_x,_o,_n))
82 #define FAS(_x,_n) ((sizeof (*_x) == 4)?FAS32(_x,_n) :FAS64(_x,_n))
84 /* Update Integer location, return Old value. */
87 /* Update Pointer location, return Old value. */
90 /* Update 32/64-bit location, return Old value. */
96 * II. Memory barriers.
97 * WMB(): All preceding write operations must commit before any later writes.
98 * RMB(): All preceding read operations must commit before any later reads.
99 * MB(): All preceding memory accesses must commit before any later accesses.
101 * If the compiler does not observe these barriers (but any sane compiler
102 * will!), then VOLATILE should be defined as 'volatile'.
105 #define MB() __asm__ __volatile__ (";; mf ;; " : : : "memory")
108 #define VOLATILE /*volatile*/
111 * III. Cycle counter access.
114 typedef unsigned long long tick_t
;
116 ({ tick_t __t; __asm__ __volatile__ ("mov %0=ar.itc ;;" : "=rO" (__t)); __t; })
124 typedef unsigned char _u8
;
125 typedef unsigned short _u16
;
126 typedef unsigned int _u32
;
127 typedef unsigned long long _u64
;
129 #endif /* __IA64_DEFNS_H__ */