(root)/
glibc-2.38/
sysdeps/
ia64/
atomic-machine.h
       1  /* Copyright (C) 2003-2023 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     <https://www.gnu.org/licenses/>.  */
      17  
      18  #include <ia64intrin.h>
      19  
      20  #define __HAVE_64B_ATOMICS 1
      21  #define USE_ATOMIC_COMPILER_BUILTINS 0
      22  
      23  /* XXX Is this actually correct?  */
      24  #define ATOMIC_EXCHANGE_USES_CAS 0
      25  
      26  
      27  #define __arch_compare_and_exchange_bool_8_acq(mem, newval, oldval) \
      28    (abort (), 0)
      29  
      30  #define __arch_compare_and_exchange_bool_16_acq(mem, newval, oldval) \
      31    (abort (), 0)
      32  
      33  #define __arch_compare_and_exchange_bool_32_acq(mem, newval, oldval) \
      34    (!__sync_bool_compare_and_swap ((mem), (int) (long) (oldval), \
      35  				  (int) (long) (newval)))
      36  
      37  #define __arch_compare_and_exchange_bool_64_acq(mem, newval, oldval) \
      38    (!__sync_bool_compare_and_swap ((mem), (long) (oldval), \
      39  				  (long) (newval)))
      40  
      41  #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
      42    (abort (), (__typeof (*mem)) 0)
      43  
      44  #define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
      45    (abort (), (__typeof (*mem)) 0)
      46  
      47  #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
      48    __sync_val_compare_and_swap ((mem), (int) (long) (oldval), \
      49  			       (int) (long) (newval))
      50  
      51  #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
      52    __sync_val_compare_and_swap ((mem), (long) (oldval), (long) (newval))
      53  
      54  /* Atomically store newval and return the old value.  */
      55  #define atomic_exchange_acq(mem, value) \
      56    __sync_lock_test_and_set (mem, value)
      57  
      58  #define atomic_exchange_rel(mem, value) \
      59    (__sync_synchronize (), __sync_lock_test_and_set (mem, value))
      60  
      61  #define atomic_exchange_and_add(mem, value) \
      62    __sync_fetch_and_add ((mem), (value))
      63  
      64  #define atomic_decrement_if_positive(mem) \
      65    ({ __typeof (*mem) __oldval, __val;					      \
      66       __typeof (mem) __memp = (mem);					      \
      67  									      \
      68       __val = (*__memp);							      \
      69       do									      \
      70         {								      \
      71  	 __oldval = __val;						      \
      72  	 if (__builtin_expect (__val <= 0, 0))				      \
      73  	   break;							      \
      74  	 __val = atomic_compare_and_exchange_val_acq (__memp,	__oldval - 1, \
      75  						      __oldval);	      \
      76         }								      \
      77       while (__builtin_expect (__val != __oldval, 0));			      \
      78       __oldval; })
      79  
      80  #define atomic_bit_test_set(mem, bit) \
      81    ({ __typeof (*mem) __oldval, __val;					      \
      82       __typeof (mem) __memp = (mem);					      \
      83       __typeof (*mem) __mask = ((__typeof (*mem)) 1 << (bit));		      \
      84  									      \
      85       __val = (*__memp);							      \
      86       do									      \
      87         {								      \
      88  	 __oldval = __val;						      \
      89  	 __val = atomic_compare_and_exchange_val_acq (__memp,		      \
      90  						      __oldval | __mask,      \
      91  						      __oldval);	      \
      92         }								      \
      93       while (__builtin_expect (__val != __oldval, 0));			      \
      94       __oldval & __mask; })
      95  
      96  #define atomic_full_barrier() __sync_synchronize ()