(root)/
gcc-13.2.0/
libatomic/
config/
s390/
exch_n.c
       1  /* Copyright (C) 2018-2023 Free Software Foundation, Inc.
       2     Contributed by Andreas Krebbel <krebbel@linux.vnet.ibm.com>
       3  
       4     This file is part of the GNU Atomic Library (libatomic).
       5  
       6     Libatomic is free software; you can redistribute it and/or modify it
       7     under the terms of the GNU General Public License as published by
       8     the Free Software Foundation; either version 3 of the License, or
       9     (at your option) any later version.
      10  
      11     Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
      12     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      13     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
      14     more details.
      15  
      16     Under Section 7 of GPL version 3, you are granted additional
      17     permissions described in the GCC Runtime Library Exception, version
      18     3.1, as published by the Free Software Foundation.
      19  
      20     You should have received a copy of the GNU General Public License and
      21     a copy of the GCC Runtime Library Exception along with this program;
      22     see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
      23     <http://www.gnu.org/licenses/>.  */
      24  
      25  #include <libatomic_i.h>
      26  
      27  
      28  /* The compiler builtin will use the hardware instruction cdsg if the
      29     memory operand is properly aligned and will fall back to the
      30     library call otherwise.
      31  
      32     In case the compiler for one part is able to detect that the
      33     location is aligned and fails to do so for another usage of the hw
      34     instruction and the sw fall back would be mixed on the same memory
      35     location.  To avoid this the library fall back also has to use the
      36     hardware instruction if possible.  */
      37  
      38  #if !DONE && N == 16
      39  UTYPE
      40  SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel UNUSED)
      41  {
      42    if (!((uintptr_t)mptr & 0xf))
      43      {
      44        /* Use the builtin only if the memory operand is 16 byte
      45  	 aligned.  */
      46        return __atomic_exchange_n ((UTYPE *)__builtin_assume_aligned (mptr, 16),
      47  				  newval, __ATOMIC_SEQ_CST);
      48      }
      49    else
      50      {
      51        UTYPE oldval;
      52        UWORD magic;
      53  
      54        pre_seq_barrier (smodel);
      55        magic = protect_start (mptr);
      56  
      57        oldval = *mptr;
      58        *mptr = newval;
      59  
      60        protect_end (mptr, magic);
      61        post_seq_barrier (smodel);
      62  
      63        return oldval;
      64      }
      65  }
      66  #define DONE 1
      67  #endif /* N == 16 */
      68  
      69  #include "../../exch_n.c"