(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
powerpc/
vec-cmpne-long.c
       1  /* { dg-do run { target { powerpc64*-*-* && { p8vector_hw } } } } */
       2  /* { dg-require-effective-target powerpc_p8vector_ok } */
       3  /* { dg-options "-mdejagnu-cpu=power8 -mpower8-vector -O3" } */
       4  
       5  /* Test that the vec_cmpne builtin works as expected for long long
       6     and double vectors.  */
       7  
       8  #include "altivec.h"
       9  
      10  #define N 4096
      11  
      12  void abort ();
      13  
      14  #define define_test_functions(VBTYPE, RTYPE, STYPE, NAME) \
      15  \
      16  RTYPE result_ne_##NAME[N] __attribute__((aligned(16))); \
      17  RTYPE result_eq_##NAME[N] __attribute__((aligned(16))); \
      18  STYPE operand1_##NAME[N] __attribute__((aligned(16))); \
      19  STYPE operand2_##NAME[N] __attribute__((aligned(16))); \
      20  RTYPE expected_##NAME[N] __attribute__((aligned(16))); \
      21  \
      22  __attribute__((noinline)) void vector_tests_##NAME () \
      23  { \
      24    vector STYPE v1_##NAME, v2_##NAME; \
      25    vector bool VBTYPE tmp_##NAME; \
      26    int i; \
      27    for (i = 0; i < N; i+=16/sizeof (STYPE)) \
      28      { \
      29        /* result_ne = operand1!=operand2.  */ \
      30        v1_##NAME = (vector STYPE) { operand1_##NAME[i], \
      31  					 operand1_##NAME[i+1] }; \
      32        v2_##NAME = (vector STYPE) { operand2_##NAME[i], \
      33  					 operand2_##NAME[i+1] }; \
      34  \
      35        tmp_##NAME = vec_cmpeq (v1_##NAME, v2_##NAME); \
      36        result_eq_##NAME[i] = tmp_##NAME[0]; \
      37        result_eq_##NAME[i+1] = tmp_##NAME[1]; \
      38  \
      39        tmp_##NAME = vec_cmpne (v1_##NAME, v2_##NAME); \
      40        result_ne_##NAME[i] = tmp_##NAME[0]; \
      41        result_ne_##NAME[i+1] = tmp_##NAME[1]; \
      42      } \
      43  } \
      44  \
      45  __attribute__((noinline)) void init_##NAME () \
      46  { \
      47    int i; \
      48    for (i = 0; i < N; ++i) \
      49      { \
      50        result_ne_##NAME[i] = 7; \
      51        result_eq_##NAME[i] = 15; \
      52        if (i%3 == 0) \
      53  	{ \
      54  	  /* op1 < op2.  */ \
      55  	  operand1_##NAME[i] = 1; \
      56  	  operand2_##NAME[i] = 2; \
      57  	} \
      58        else if (i%3 == 1) \
      59  	{ \
      60  	  /* op1 > op2.  */ \
      61  	  operand1_##NAME[i] = 2; \
      62  	  operand2_##NAME[i] = 1; \
      63  	} \
      64        else if (i%3 == 2) \
      65  	{ \
      66  	  /* op1 == op2.  */ \
      67  	  operand1_##NAME[i] = 3; \
      68  	  operand2_##NAME[i] = 3; \
      69  	} \
      70        /* For vector comparisons: "For each element of the result_ne, the \
      71  	  value of each bit is 1 if the corresponding elements of ARG1 and \
      72  	  ARG2 are equal." {or whatever the comparison is} "Otherwise, the \
      73  	  value of each bit is 0."  */ \
      74      expected_##NAME[i] = -1 * (RTYPE)(operand1_##NAME[i] != operand2_##NAME[i]); \
      75    } \
      76  } \
      77  \
      78  __attribute__((noinline)) void verify_results_##NAME () \
      79  { \
      80    int i; \
      81    for (i = 0; i < N; ++i) \
      82      { \
      83        if ( ((result_ne_##NAME[i] != expected_##NAME[i]) || \
      84  	    (result_ne_##NAME[i] == result_eq_##NAME[i]))) \
      85  	abort (); \
      86      } \
      87  }
      88  
      89  
      90  #define execute_test_functions(VBTYPE, RTYPE, STYPE, NAME) \
      91  { \
      92    init_##NAME (); \
      93    vector_tests_##NAME (); \
      94    verify_results_##NAME (); \
      95  }
      96  
      97  
      98  define_test_functions (long long, signed long long, signed long long, si);
      99  define_test_functions (long long, signed long long, double, dd);
     100  
     101  int main ()
     102  {
     103    execute_test_functions (long long, signed long long, signed long long, si);
     104    execute_test_functions (long long, signed long long, double, dd);
     105  
     106    return 0;
     107  }
     108  
     109