(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
aarch64/
vect-abs.c
       1  
       2  /* { dg-do run } */
       3  /* { dg-options "-O3 -std=c99" } */
       4  
       5  #include "limits.h"
       6  
       7  extern void abort (void);
       8  
       9  #define N 16
      10  
      11  #include "vect-abs.x"
      12  
      13  #define SET_VEC(size, type) void set_vector_##size (pRINT##size a) \
      14  		      	    {				        \
      15  			      int i;			        \
      16  			      for (i=0; i<N; i++)	        \
      17  			        a[i] = (type##_MIN) + (i + 1);  \
      18  		      	    }
      19  
      20  #define SET_RVEC(size, type) void set_rvector_##size (pRINT##size a) \
      21  		      	     {				      \
      22  			       int i;			      \
      23  			       for (i=0; i<N; i++)	      \
      24  			         a[i] = type##_MAX - i;       \
      25  		      	     }
      26  
      27  #define CHECK_VEC(size) void check_vector_##size (pRINT##size a, \
      28  						  pRINT##size b) \
      29  			{				       \
      30  			  int i;			       \
      31  			  for (i=0; i<N; i++)		       \
      32  			    if (a[i] != b[i])  		       \
      33  			      abort (); 		       \
      34  			}
      35  
      36  
      37  SET_RVEC (8, SCHAR)
      38  SET_RVEC (16, SHRT)
      39  SET_RVEC (32, INT)
      40  SET_RVEC (64, LLONG)
      41  
      42  void
      43  set_rvector_long (pRLONG a)
      44  {
      45    int i;
      46    for (i=0; i<N; i++)
      47      a[i] = (LONG_MAX) - i;
      48  }
      49  
      50  SET_VEC (8, SCHAR)
      51  SET_VEC (16, SHRT)
      52  SET_VEC (32, INT)
      53  SET_VEC (64, LLONG)
      54  
      55  void
      56  set_vector_long (long *__restrict__ a)
      57  {
      58    long i;
      59    for (i=0; i<N; i++)
      60      a[i] = (LONG_MIN) + i + 1;
      61  }
      62  
      63  CHECK_VEC (8)
      64  CHECK_VEC (16)
      65  CHECK_VEC (32)
      66  CHECK_VEC (64)
      67  
      68  void
      69  check_vector_long (long *__restrict__ a, long *__restrict__ b)
      70  {
      71    long i;
      72    for (i=0; i<N; i++)
      73      if (a[i] != b[i])
      74        abort ();
      75  }
      76  
      77  int main (void)
      78  {
      79  
      80    signed char a8[N];
      81    short a16[N];
      82    int a32[N];
      83    long long a64[N];
      84    /* abs () from stdlib.  */
      85    int alib32[N];
      86    long alibl[N];
      87  
      88  
      89    signed char b8[N];
      90    short b16[N];
      91    int b32[N];
      92    long long b64[N];
      93    /* abs () from stdlib.  */
      94    long blibl[N];
      95  
      96    signed char abs_vector_8[N];
      97    short abs_vector_16[N];
      98    int abs_vector_32[N];
      99    long long abs_vector_64[N];
     100    long abs_vector_long[N];
     101  
     102    /* Set up result vectors.  */
     103    set_rvector_8 (abs_vector_8);
     104    set_rvector_16 (abs_vector_16);
     105    set_rvector_32 (abs_vector_32);
     106    set_rvector_long (abs_vector_long);
     107    set_rvector_64 (abs_vector_64);
     108  
     109    /* Set up inputs.  */
     110    set_vector_8 (b8);
     111    set_vector_16 (b16);
     112    set_vector_32 (b32);
     113    set_vector_64 (b64);
     114    set_vector_long (blibl);
     115  
     116    /* Calculate their absolute values.  */
     117    absolute_s8 (a8, b8);
     118    absolute_s16 (a16, b16);
     119    absolute_s32 (a32, b32);
     120    absolute_s64 (a64, b64);
     121    /* abs () from stdlib.  */
     122    absolute_s32_lib (alib32, b32);
     123    absolute_l32_lib (alibl, blibl);
     124  
     125    /* Check.  */
     126    check_vector_8 (a8, abs_vector_8);
     127    check_vector_16 (a16, abs_vector_16);
     128    check_vector_32 (a32, abs_vector_32);
     129    check_vector_64 (a64, abs_vector_64);
     130    check_vector_32 (alib32, abs_vector_32);
     131    check_vector_long (alibl, abs_vector_long);
     132  
     133    return 0;
     134  }