| xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /* Copyright (C) 2011-2016 Free Software Foundation, Inc. | 
|  | 2 | This file is part of the GNU C Library. | 
|  | 3 | Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. | 
|  | 4 |  | 
|  | 5 | The GNU C Library is free software; you can redistribute it and/or | 
|  | 6 | modify it under the terms of the GNU Lesser General Public | 
|  | 7 | License as published by the Free Software Foundation; either | 
|  | 8 | version 2.1 of the License, or (at your option) any later version. | 
|  | 9 |  | 
|  | 10 | The GNU C Library is distributed in the hope that it will be useful, | 
|  | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|  | 13 | Lesser General Public License for more details. | 
|  | 14 |  | 
|  | 15 | You should have received a copy of the GNU Lesser General Public | 
|  | 16 | License along with the GNU C Library.  If not, see | 
|  | 17 | <http://www.gnu.org/licenses/>.  */ | 
|  | 18 |  | 
|  | 19 | /* The sub-architecture headers provide definitions for these macros | 
|  | 20 | that work for "int" and "long" size values only: | 
|  | 21 |  | 
|  | 22 | atomic_compare_and_exchange_val_acq() | 
|  | 23 | atomic_exchange_acq() | 
|  | 24 | atomic_exchange_and_add() | 
|  | 25 | atomic_and_val() | 
|  | 26 | atomic_or_val() | 
|  | 27 | atomic_decrement_if_positive() [tilegx only] | 
|  | 28 |  | 
|  | 29 | Here we provide generic definitions true for all Tilera chips.  */ | 
|  | 30 |  | 
|  | 31 | #include <stdint.h> | 
|  | 32 | #include <features.h> | 
|  | 33 |  | 
|  | 34 | typedef int32_t atomic32_t; | 
|  | 35 | typedef uint32_t uatomic32_t; | 
|  | 36 | typedef int_fast32_t atomic_fast32_t; | 
|  | 37 | typedef uint_fast32_t uatomic_fast32_t; | 
|  | 38 |  | 
|  | 39 | typedef int64_t atomic64_t; | 
|  | 40 | typedef uint64_t uatomic64_t; | 
|  | 41 | typedef int_fast64_t atomic_fast64_t; | 
|  | 42 | typedef uint_fast64_t uatomic_fast64_t; | 
|  | 43 |  | 
|  | 44 | typedef intptr_t atomicptr_t; | 
|  | 45 | typedef uintptr_t uatomicptr_t; | 
|  | 46 | typedef intmax_t atomic_max_t; | 
|  | 47 | typedef uintmax_t uatomic_max_t; | 
|  | 48 |  | 
|  | 49 | /* Barrier macro. */ | 
|  | 50 | #define atomic_full_barrier() __sync_synchronize() | 
|  | 51 |  | 
|  | 52 | /* APIs with "release" semantics. */ | 
|  | 53 | #define atomic_compare_and_exchange_val_rel(mem, n, o)          \ | 
|  | 54 | ({                                                            \ | 
|  | 55 | atomic_full_barrier ();                                     \ | 
|  | 56 | atomic_compare_and_exchange_val_acq ((mem), (n), (o));      \ | 
|  | 57 | }) | 
|  | 58 | #define atomic_compare_and_exchange_bool_rel(mem, n, o)         \ | 
|  | 59 | ({                                                            \ | 
|  | 60 | atomic_full_barrier ();                                     \ | 
|  | 61 | atomic_compare_and_exchange_bool_acq ((mem), (n), (o));     \ | 
|  | 62 | }) | 
|  | 63 | #define atomic_exchange_rel(mem, n)                             \ | 
|  | 64 | ({                                                            \ | 
|  | 65 | atomic_full_barrier ();                                     \ | 
|  | 66 | atomic_exchange_acq ((mem), (n));                           \ | 
|  | 67 | }) | 
|  | 68 |  | 
|  | 69 | /* Various macros that should just be synonyms. */ | 
|  | 70 | #define catomic_exchange_and_add atomic_exchange_and_add | 
|  | 71 | #define atomic_and(mem, mask) ((void) atomic_and_val ((mem), (mask))) | 
|  | 72 | #define catomic_and atomic_and | 
|  | 73 | #define atomic_or(mem, mask) ((void) atomic_or_val ((mem), (mask))) | 
|  | 74 | #define catomic_or atomic_or | 
|  | 75 |  | 
|  | 76 | /* atomic_bit_test_set in terms of atomic_or_val. */ | 
|  | 77 | #define atomic_bit_test_set(mem, bit)                                   \ | 
|  | 78 | ({ __typeof (*(mem)) __att0_mask = ((__typeof (*(mem))) 1 << (bit));  \ | 
|  | 79 | atomic_or_val ((mem), __att0_mask) & __att0_mask; }) | 
|  | 80 |  | 
|  | 81 | /* | 
|  | 82 | * This non-existent symbol is called for unsupporrted sizes, | 
|  | 83 | * indicating a bug in the caller. | 
|  | 84 | */ | 
|  | 85 | extern int __atomic_error_bad_argument_size(void) | 
|  | 86 | __attribute__ ((warning ("bad sizeof atomic argument"))); |