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