(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
powerpc/
altivec-2-runnable.c
       1  /* { dg-do compile { target powerpc*-*-* } } */
       2  /* { dg-require-effective-target powerpc_p8vector_ok } */
       3  /* { dg-options "-mpower8-vector -mvsx" } */
       4  
       5  #include <altivec.h>
       6  
       7  #ifdef DEBUG
       8  #include <stdio.h>
       9  #endif
      10  
      11  void abort (void);
      12  
      13  /* Endian considerations: The "high" half of a vector with n elements is the
      14     first n/2 elements of the vector. For little endian, these elements are in
      15     the rightmost half of the vector. For big endian, these elements are in the
      16     leftmost half of the vector.  */
      17  
      18  int main ()
      19  {
      20    int i;
      21    vector bool int vec_bi_arg;
      22    vector bool long long vec_bll_result, vec_bll_expected;
      23  
      24    vector signed int vec_si_arg;
      25    vector signed long long int vec_slli_result, vec_slli_expected;
      26    vector float vec_float_arg;
      27    vector double vec_double_result, vec_double_expected;
      28  
      29    union conv {
      30  	  double d;
      31  	  unsigned long long l;
      32    } conv_exp, conv_val;
      33  
      34    /* Use of 'double' and ‘long long’ in AltiVec types requires -mvsx */
      35    /* __builtin_altivec_vupkhsw and __builtin_altivec_vupklsw
      36       requires the -mpower8-vector option */
      37  
      38    vec_bi_arg = (vector bool int){ 0, 1, 1, 0 };
      39  
      40    vec_bll_expected = (vector bool long long){ 0, 1 };
      41  
      42    vec_bll_result = vec_unpackh (vec_bi_arg);
      43  
      44    for (i = 0; i < 2; i++) {
      45      if (vec_bll_expected[i] != vec_bll_result[i])
      46  #if DEBUG
      47         printf("ERROR: vec_unpackh, vec_bll_expected[%d] = %d does not match vec_bll_result[%d] = %d\n",
      48  	      i, vec_bll_expected[i], i, vec_bll_result[i]);
      49  #else
      50         abort();
      51  #endif
      52    }
      53  
      54    vec_bll_expected = (vector bool long long){ 1, 0 };
      55  
      56    vec_bll_result = vec_unpackl (vec_bi_arg);
      57  
      58    for (i = 0; i < 2; i++) {
      59      if (vec_bll_expected[i] != vec_bll_result[i])
      60  #if DEBUG
      61         printf("ERROR: vec_unpackl, vec_bll_expected[%d] = %d does not match vec_bll_result[%d] = %d\n",
      62  	      i, vec_bll_expected[i], i, vec_bll_result[i]);
      63  #else
      64         abort();
      65  #endif
      66    }
      67  
      68  
      69    vec_si_arg = (vector signed int){ 0, 101, 202, 303 };
      70  
      71    vec_slli_expected = (vector signed long long int){ 0, 101 };
      72  
      73    vec_slli_result = vec_unpackh (vec_si_arg);
      74  
      75    for (i = 0; i < 2; i++) {
      76      if (vec_slli_expected[i] != vec_slli_result[i])
      77  #if DEBUG
      78         printf("ERROR: vec_unpackh, vec_slli_expected[%d] = %d does not match vec_slli_result[%d] = %d\n",
      79  	      i, vec_slli_expected[i], i, vec_slli_result[i]);
      80  #else
      81         abort();
      82  #endif
      83    }
      84  
      85    vec_slli_result = vec_unpackl (vec_si_arg);
      86    vec_slli_expected = (vector signed long long int){ 202, 303 };
      87  
      88    for (i = 0; i < 2; i++) {
      89      if (vec_slli_expected[i] != vec_slli_result[i])
      90  #if DEBUG
      91         printf("ERROR: vec_unpackl, vec_slli_expected[%d] = %d does not match vec_slli_result[%d] = %d\n",
      92  	      i, vec_slli_expected[i], i, vec_slli_result[i]);
      93  #else
      94         abort();
      95  #endif
      96    }
      97  
      98    vec_float_arg = (vector float){ 0.0, 1.5, 2.5, 3.5 };
      99  
     100    vec_double_expected = (vector double){ 0.0, 1.5 };
     101  
     102    vec_double_result = vec_unpackh (vec_float_arg);
     103  
     104    for (i = 0; i < 2; i++) {
     105      if (vec_double_expected[i] != vec_double_result[i])
     106        {
     107  #if DEBUG
     108  	 printf("ERROR: vec_unpackh(), vec_double_expected[%d] = %f does not match vec_double_result[%d] = %f\n",
     109  		i, vec_double_expected[i], i, vec_double_result[i]);
     110  	 conv_val.d = vec_double_result[i];
     111  	 conv_exp.d = vec_double_expected[i];
     112  	 printf("     vec_unpackh(), vec_double_expected[%d] = 0x%llx does not match vec_double_result[%d] = 0x%llx\n",
     113  		i, conv_exp.l, i,conv_val.l);
     114  #else
     115  	 abort();
     116  #endif
     117      }
     118    }
     119  
     120    vec_double_expected = (vector double){ 2.5, 3.5 };
     121  
     122    vec_double_result = vec_unpackl (vec_float_arg);
     123  
     124    for (i = 0; i < 2; i++) {
     125      if (vec_double_expected[i] != vec_double_result[i])
     126        {
     127  #if DEBUG
     128           printf("ERROR: vec_unpackl() vec_double_expected[%d] = %f does not match vec_double_result[%d] = %f\n",
     129  		i, vec_double_expected[i], i, vec_double_result[i]);
     130  	 conv_val.d = vec_double_result[i];
     131  	 conv_exp.d = vec_double_expected[i];
     132  	 printf("     vec_unpackh(), vec_double_expected[%d] = 0x%llx does not match vec_double_result[%d] = 0x%llx\n",
     133  		i, conv_exp.l, i,conv_val.l);
     134  #else
     135           abort();
     136  #endif
     137        }
     138    }
     139  
     140    return 0;
     141  }