(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
aarch64/
atomic-store.c
       1  /* { dg-do compile } */
       2  /* { dg-options "-march=armv8.4-a -O2" } */
       3  
       4  #include <stdatomic.h>
       5  
       6  typedef __INT8_TYPE__ int8_t;
       7  typedef __INT16_TYPE__ int16_t;
       8  typedef __INT32_TYPE__ int32_t;
       9  typedef __INT64_TYPE__ int64_t;
      10  
      11  #define STORE_TESTS(size) \
      12    void \
      13    foo##size (int##size##_t *atomic_vals) \
      14  { \
      15    atomic_store_explicit (atomic_vals, 2, memory_order_relaxed); \
      16    atomic_store_explicit (atomic_vals, 2, memory_order_release); \
      17    atomic_store_explicit ((atomic_vals + 1), 2, memory_order_release); \
      18    atomic_store ((atomic_vals + 2), 2); \
      19    atomic_store_explicit ((atomic_vals + 3), 2, memory_order_relaxed); \
      20  }
      21  
      22  STORE_TESTS (8);
      23  /* { dg-final { scan-assembler-times "strb\tw\[0-9\]+, \\\[x\[0-9\]+\\\]" 1 } } */
      24  /* { dg-final { scan-assembler-times "stlrb\tw\[0-9\]+, \\\[x\[0-9\]+\\\]" 1  { target { ! ilp32 } } } } */
      25  /* { dg-final { scan-assembler-times "stlrb\tw\[0-9\]+, \\\[x\[0-9\]+\\\]" 2  { target { ilp32 } } } } */
      26  /* { dg-final { scan-assembler-times "stlurb\tw\[0-9\]+, \\\[x\[0-9\]+, 1\\\]" 1 } } */
      27  /* { dg-final { scan-assembler-times "stlurb\tw\[0-9\]+, \\\[x\[0-9\]+, 2\\\]" 1 } } */
      28  /* { dg-final { scan-assembler-times "strb\tw\[0-9\]+, \\\[x\[0-9\]+, 3\\\]" 1 } } */
      29  
      30  STORE_TESTS (16);
      31  /* { dg-final { scan-assembler-times "strh\tw\[0-9\]+, \\\[x\[0-9\]+\\\]" 1 } } */
      32  /* { dg-final { scan-assembler-times "stlrh\tw\[0-9\]+, \\\[x\[0-9\]+\\\]" 1 } } */
      33  /* { dg-final { scan-assembler-times "stlurh\tw\[0-9\]+, \\\[x\[0-9\]+, 2\\\]" 1 } } */
      34  /* { dg-final { scan-assembler-times "stlurh\tw\[0-9\]+, \\\[x\[0-9\]+, 4\\\]" 1 } } */
      35  /* { dg-final { scan-assembler-times "strh\tw\[0-9\]+, \\\[x\[0-9\]+, 6\\\]" 1 } } */
      36  
      37  STORE_TESTS (32);
      38  /* { dg-final { scan-assembler-times "str\tw\[0-9\]+, \\\[x\[0-9\]+\\\]" 1 } } */
      39  /* { dg-final { scan-assembler-times "stlr\tw\[0-9\]+, \\\[x\[0-9\]+\\\]" 1 } } */
      40  /* { dg-final { scan-assembler-times "stlur\tw\[0-9\]+, \\\[x\[0-9\]+, 4\\\]" 1 } } */
      41  /* { dg-final { scan-assembler-times "stlur\tw\[0-9\]+, \\\[x\[0-9\]+, 8\\\]" 1 } } */
      42  /* { dg-final { scan-assembler-times "str\tw\[0-9\]+, \\\[x\[0-9\]+, 12\\\]" 1 } } */
      43  
      44  STORE_TESTS (64);
      45  /* { dg-final { scan-assembler-times "str\tx\[0-9\]+, \\\[x\[0-9\]+\\\]" 1 } } */
      46  /* { dg-final { scan-assembler-times "stlur\tx\[0-9\]+, \\\[x\[0-9\]+, 8\\\]" 1 } } */
      47  /* { dg-final { scan-assembler-times "stlur\tx\[0-9\]+, \\\[x\[0-9\]+, 16\\\]" 1 } } */
      48  /* { dg-final { scan-assembler-times "str\tx\[0-9\]+, \\\[x\[0-9\]+, 24\\\]" 1 } } */
      49  
      50  void
      51  foo_toolarge_offset (int64_t *atomic_vals)
      52  {
      53    /* 9bit signed unscaled immediate =>
      54  	largest representable value +255.
      55  	smallest representable value -256.  */
      56    atomic_store_explicit (atomic_vals + 32, 2, memory_order_release);
      57    atomic_store_explicit (atomic_vals - 33, 2, memory_order_release);
      58  }
      59  
      60  void
      61  foo_negative (int8_t *atomic_vals)
      62  {
      63    atomic_store_explicit (atomic_vals - 2, 2, memory_order_release);
      64  }
      65  /* { dg-final { scan-assembler-times "stlurb\tw\[0-9\]+, \\\[x\[0-9\]+, -2\\\]" 1 { target { ! ilp32 } } } } */
      66  
      67  #pragma GCC target ("arch=armv8.3-a")
      68  void
      69  foo_older_arch (int64_t *atomic_vals)
      70  {
      71    atomic_store_explicit (atomic_vals + 2, 2, memory_order_release);
      72  }
      73  
      74  /* Three times, one for each of the three above functions.  */
      75  /* { dg-final { scan-assembler-times "stlr\tx\[0-9\]+, \\\[x\[0-9\]+\\\]" 4 } } */