2
* Copyright (c) 2003 by Hewlett-Packard Company. All rights reserved.
4
* Permission is hereby granted, free of charge, to any person obtaining a copy
5
* of this software and associated documentation files (the "Software"), to deal
6
* in the Software without restriction, including without limitation the rights
7
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
* copies of the Software, and to permit persons to whom the Software is
9
* furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
* This file specifies Itanimum primitives for use with the Intel (ecc)
25
* compiler. We use intrinsics instead of the inline assembly code in the
29
#include "../all_atomic_load_store.h"
31
#include "../test_and_set_t_is_char.h"
33
#include <ia64intrin.h>
35
/* The acquire release semantics of volatile can be turned off. And volatile */
36
/* operations in icc9 don't imply ordering with respect to other nonvolatile */
39
#define AO_INTEL_PTR_t void *
42
AO_load_acquire(volatile AO_t *p)
44
return (AO_t)(__ld8_acq((AO_INTEL_PTR_t)p));
46
#define AO_HAVE_load_acquire
49
AO_store_release(volatile AO_t *p, AO_t val)
51
__st8_rel((AO_INTEL_PTR_t)p, (__int64)val);
53
#define AO_HAVE_store_release
55
AO_INLINE unsigned char
56
AO_char_load_acquire(volatile unsigned char *p)
58
/* A normal volatile load generates an ld.acq */
59
return (__ld1_acq((AO_INTEL_PTR_t)p));
61
#define AO_HAVE_char_load_acquire
64
AO_char_store_release(volatile unsigned char *p, unsigned char val)
66
__st1_rel((AO_INTEL_PTR_t)p, val);
68
#define AO_HAVE_char_store_release
70
AO_INLINE unsigned short
71
AO_short_load_acquire(volatile unsigned short *p)
73
/* A normal volatile load generates an ld.acq */
74
return (__ld2_acq((AO_INTEL_PTR_t)p));
76
#define AO_HAVE_short_load_acquire
79
AO_short_store_release(volatile unsigned short *p, unsigned short val)
81
__st2_rel((AO_INTEL_PTR_t)p, val);
83
#define AO_HAVE_short_store_release
85
AO_INLINE unsigned int
86
AO_int_load_acquire(volatile unsigned int *p)
88
/* A normal volatile load generates an ld.acq */
89
return (__ld4_acq((AO_INTEL_PTR_t)p));
91
#define AO_HAVE_int_load_acquire
94
AO_int_store_release(volatile unsigned int *p, unsigned int val)
96
__st4_rel((AO_INTEL_PTR_t)p, val);
98
#define AO_HAVE_int_store_release
105
#define AO_HAVE_nop_full
108
AO_fetch_and_add1_acquire (volatile AO_t *p)
110
return __fetchadd8_acq((unsigned __int64 *)p, 1);
112
#define AO_HAVE_fetch_and_add1_acquire
115
AO_fetch_and_add1_release (volatile AO_t *p)
117
return __fetchadd8_rel((unsigned __int64 *)p, 1);
120
#define AO_HAVE_fetch_and_add1_release
123
AO_fetch_and_sub1_acquire (volatile AO_t *p)
125
return __fetchadd8_acq((unsigned __int64 *)p, -1);
128
#define AO_HAVE_fetch_and_sub1_acquire
131
AO_fetch_and_sub1_release (volatile AO_t *p)
133
return __fetchadd8_rel((unsigned __int64 *)p, -1);
136
#define AO_HAVE_fetch_and_sub1_release
139
AO_compare_and_swap_acquire(volatile AO_t *addr,
140
AO_t old, AO_t new_val)
143
oldval = _InterlockedCompareExchange64_acq(addr, new_val, old);
144
return (oldval == old);
147
#define AO_HAVE_compare_and_swap_acquire
150
AO_compare_and_swap_release(volatile AO_t *addr,
151
AO_t old, AO_t new_val)
154
oldval = _InterlockedCompareExchange64_rel(addr, new_val, old);
155
return (oldval == old);
158
#define AO_HAVE_compare_and_swap_release
161
AO_char_compare_and_swap_acquire(volatile unsigned char *addr,
162
unsigned char old, unsigned char new_val)
164
unsigned char oldval;
165
oldval = _InterlockedCompareExchange8_acq(addr, new_val, old);
166
return (oldval == old);
169
#define AO_HAVE_char_compare_and_swap_acquire
172
AO_char_compare_and_swap_release(volatile unsigned char *addr,
173
unsigned char old, unsigned char new_val)
175
unsigned char oldval;
176
oldval = _InterlockedCompareExchange8_rel(addr, new_val, old);
177
return (oldval == old);
180
#define AO_HAVE_char_compare_and_swap_release
183
AO_short_compare_and_swap_acquire(volatile unsigned short *addr,
184
unsigned short old, unsigned short new_val)
186
unsigned short oldval;
187
oldval = _InterlockedCompareExchange16_acq(addr, new_val, old);
188
return (oldval == old);
191
#define AO_HAVE_short_compare_and_swap_acquire
194
AO_short_compare_and_swap_release(volatile unsigned short *addr,
195
unsigned short old, unsigned short new_val)
197
unsigned short oldval;
198
oldval = _InterlockedCompareExchange16_rel(addr, new_val, old);
199
return (oldval == old);
202
#define AO_HAVE_short_compare_and_swap_release
205
AO_int_compare_and_swap_acquire(volatile unsigned int *addr,
206
unsigned int old, unsigned int new_val)
209
oldval = _InterlockedCompareExchange_acq(addr, new_val, old);
210
return (oldval == old);
213
#define AO_HAVE_int_compare_and_swap_acquire
216
AO_int_compare_and_swap_release(volatile unsigned int *addr,
217
unsigned int old, unsigned int new_val)
220
oldval = _InterlockedCompareExchange_rel(addr, new_val, old);
221
return (oldval == old);
224
#define AO_HAVE_int_compare_and_swap_release