| xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /* Copyright (C) 2003-2016 Free Software Foundation, Inc. | 
|  | 2 | This file is part of the GNU C Library. | 
|  | 3 |  | 
|  | 4 | The GNU C Library is free software; you can redistribute it and/or | 
|  | 5 | modify it under the terms of the GNU Lesser General Public | 
|  | 6 | License as published by the Free Software Foundation; either | 
|  | 7 | version 2.1 of the License, or (at your option) any later version. | 
|  | 8 |  | 
|  | 9 | The GNU C Library is distributed in the hope that it will be useful, | 
|  | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|  | 12 | Lesser General Public License for more details. | 
|  | 13 |  | 
|  | 14 | You should have received a copy of the GNU Lesser General Public | 
|  | 15 | License along with the GNU C Library; if not, see | 
|  | 16 | <http://www.gnu.org/licenses/>.  */ | 
|  | 17 |  | 
|  | 18 | #include <stdint.h> | 
|  | 19 | #include <ia64intrin.h> | 
|  | 20 |  | 
|  | 21 | typedef int8_t atomic8_t; | 
|  | 22 | typedef uint8_t uatomic8_t; | 
|  | 23 | typedef int_fast8_t atomic_fast8_t; | 
|  | 24 | typedef uint_fast8_t uatomic_fast8_t; | 
|  | 25 |  | 
|  | 26 | typedef int16_t atomic16_t; | 
|  | 27 | typedef uint16_t uatomic16_t; | 
|  | 28 | typedef int_fast16_t atomic_fast16_t; | 
|  | 29 | typedef uint_fast16_t uatomic_fast16_t; | 
|  | 30 |  | 
|  | 31 | typedef int32_t atomic32_t; | 
|  | 32 | typedef uint32_t uatomic32_t; | 
|  | 33 | typedef int_fast32_t atomic_fast32_t; | 
|  | 34 | typedef uint_fast32_t uatomic_fast32_t; | 
|  | 35 |  | 
|  | 36 | typedef int64_t atomic64_t; | 
|  | 37 | typedef uint64_t uatomic64_t; | 
|  | 38 | typedef int_fast64_t atomic_fast64_t; | 
|  | 39 | typedef uint_fast64_t uatomic_fast64_t; | 
|  | 40 |  | 
|  | 41 | typedef intptr_t atomicptr_t; | 
|  | 42 | typedef uintptr_t uatomicptr_t; | 
|  | 43 | typedef intmax_t atomic_max_t; | 
|  | 44 | typedef uintmax_t uatomic_max_t; | 
|  | 45 |  | 
|  | 46 | #define __HAVE_64B_ATOMICS 1 | 
|  | 47 | #define USE_ATOMIC_COMPILER_BUILTINS 0 | 
|  | 48 |  | 
|  | 49 |  | 
|  | 50 | #define __arch_compare_and_exchange_bool_8_acq(mem, newval, oldval) \ | 
|  | 51 | (abort (), 0) | 
|  | 52 |  | 
|  | 53 | #define __arch_compare_and_exchange_bool_16_acq(mem, newval, oldval) \ | 
|  | 54 | (abort (), 0) | 
|  | 55 |  | 
|  | 56 | #define __arch_compare_and_exchange_bool_32_acq(mem, newval, oldval) \ | 
|  | 57 | (!__sync_bool_compare_and_swap ((mem), (int) (long) (oldval), \ | 
|  | 58 | (int) (long) (newval))) | 
|  | 59 |  | 
|  | 60 | #define __arch_compare_and_exchange_bool_64_acq(mem, newval, oldval) \ | 
|  | 61 | (!__sync_bool_compare_and_swap ((mem), (long) (oldval), \ | 
|  | 62 | (long) (newval))) | 
|  | 63 |  | 
|  | 64 | #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \ | 
|  | 65 | (abort (), (__typeof (*mem)) 0) | 
|  | 66 |  | 
|  | 67 | #define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \ | 
|  | 68 | (abort (), (__typeof (*mem)) 0) | 
|  | 69 |  | 
|  | 70 | #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \ | 
|  | 71 | __sync_val_compare_and_swap ((mem), (int) (long) (oldval), \ | 
|  | 72 | (int) (long) (newval)) | 
|  | 73 |  | 
|  | 74 | #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \ | 
|  | 75 | __sync_val_compare_and_swap ((mem), (long) (oldval), (long) (newval)) | 
|  | 76 |  | 
|  | 77 | /* Atomically store newval and return the old value.  */ | 
|  | 78 | #define atomic_exchange_acq(mem, value) \ | 
|  | 79 | __sync_lock_test_and_set (mem, value) | 
|  | 80 |  | 
|  | 81 | #define atomic_exchange_rel(mem, value) \ | 
|  | 82 | (__sync_synchronize (), __sync_lock_test_and_set (mem, value)) | 
|  | 83 |  | 
|  | 84 | #define atomic_exchange_and_add(mem, value) \ | 
|  | 85 | __sync_fetch_and_add ((mem), (value)) | 
|  | 86 |  | 
|  | 87 | #define atomic_decrement_if_positive(mem) \ | 
|  | 88 | ({ __typeof (*mem) __oldval, __val;					      \ | 
|  | 89 | __typeof (mem) __memp = (mem);					      \ | 
|  | 90 | \ | 
|  | 91 | __val = (*__memp);							      \ | 
|  | 92 | do									      \ | 
|  | 93 | {								      \ | 
|  | 94 | __oldval = __val;						      \ | 
|  | 95 | if (__builtin_expect (__val <= 0, 0))				      \ | 
|  | 96 | break;							      \ | 
|  | 97 | __val = atomic_compare_and_exchange_val_acq (__memp,	__oldval - 1, \ | 
|  | 98 | __oldval);	      \ | 
|  | 99 | }								      \ | 
|  | 100 | while (__builtin_expect (__val != __oldval, 0));			      \ | 
|  | 101 | __oldval; }) | 
|  | 102 |  | 
|  | 103 | #define atomic_bit_test_set(mem, bit) \ | 
|  | 104 | ({ __typeof (*mem) __oldval, __val;					      \ | 
|  | 105 | __typeof (mem) __memp = (mem);					      \ | 
|  | 106 | __typeof (*mem) __mask = ((__typeof (*mem)) 1 << (bit));		      \ | 
|  | 107 | \ | 
|  | 108 | __val = (*__memp);							      \ | 
|  | 109 | do									      \ | 
|  | 110 | {								      \ | 
|  | 111 | __oldval = __val;						      \ | 
|  | 112 | __val = atomic_compare_and_exchange_val_acq (__memp,		      \ | 
|  | 113 | __oldval | __mask,      \ | 
|  | 114 | __oldval);	      \ | 
|  | 115 | }								      \ | 
|  | 116 | while (__builtin_expect (__val != __oldval, 0));			      \ | 
|  | 117 | __oldval & __mask; }) | 
|  | 118 |  | 
|  | 119 | #define atomic_full_barrier() __sync_synchronize () |