(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
powerpc/
altivec-1-runnable.c
       1  /* { dg-do compile { target powerpc*-*-* } } */
       2  /* { dg-require-effective-target powerpc_altivec_ok } */
       3  /* { dg-options "-maltivec" } */
       4  
       5  #include <altivec.h>
       6  
       7  #ifdef DEBUG
       8  #include <stdio.h>
       9  #endif
      10  
      11  /* Endian considerations: The "high" half of a vector with n elements is the
      12     first n/2 elements of the vector. For little endian, these elements are in
      13     the rightmost half of the vector. For big endian, these elements are in the
      14     leftmost half of the vector.  */
      15  
      16  
      17  void abort (void);
      18  
      19  int main ()
      20  {
      21    int i;
      22    vector bool short vec_bs_arg;
      23    vector bool short vec_bs_result, vec_bs_expected;
      24    vector bool int vec_bi_arg;
      25    vector bool int vec_bi_result, vec_bi_expected;
      26    vector bool char vec_bc_arg;
      27    vector bool char vec_bc_result, vec_bc_expected;
      28    vector signed short vec_ss_arg;
      29    vector signed short vec_ss_result, vec_ss_expected;
      30    vector signed int vec_si_arg;
      31    vector signed int vec_si_result, vec_si_expected;
      32    vector signed char vec_sc_arg;
      33    vector signed char vec_sc_result, vec_sc_expected;
      34    vector pixel vec_pixel_arg;
      35    vector unsigned int vec_ui_result, vec_ui_expected;
      36  
      37    vec_bs_arg = (vector bool short){ 0, 101, 202, 303,
      38  				    404, 505, 606, 707 };
      39    vec_bi_expected = (vector bool int){ 0, 101, 202, 303 };
      40  
      41    vec_bi_result = vec_unpackh (vec_bs_arg);
      42  
      43    for (i = 0; i < 4; i++) {
      44      if (vec_bi_expected[i] != vec_bi_result[i])
      45  #if DEBUG
      46         printf("ERROR: vec_unpackh(),  vec_bi_expected[%d] = %d does not match vec_bi_result[%d] = %d\n",
      47  	      i, vec_bi_expected[i], i, vec_bi_result[i]);
      48  #else
      49         abort();
      50  #endif
      51    }
      52  
      53    vec_bi_expected = (vector bool int){ 404, 505, 606, 707 };
      54    vec_bi_result = vec_unpackl (vec_bs_arg);
      55  
      56    for (i = 0; i < 4; i++) {
      57      if (vec_bi_expected[i] != vec_bi_result[i])
      58  #if DEBUG
      59         printf("ERROR: vec_unpackl(), vec_bi_expected[%d] = %d does not match vec_bi_result[%d] = %d\n",
      60  	      i, vec_bi_expected[i], i, vec_bi_result[i]);
      61  #else
      62         abort();
      63  #endif
      64    }
      65  
      66    
      67    vec_ss_arg = (vector signed short){ 0, 101, 202, 303,
      68  				    404, 505, 606, 707 };
      69    vec_si_expected = (vector signed int){ 0, 101, 202, 303 };
      70  
      71    vec_si_result = vec_unpackh (vec_ss_arg);
      72  
      73    for (i = 0; i < 4; i++) {
      74      if (vec_si_expected[i] != vec_si_result[i])
      75  #if DEBUG
      76         printf("ERROR: vec_unpackh(), vec_si_expected[%d] = %d does not match vec_si_result[%d] = %d\n",
      77  	      i, vec_si_expected[i], i, vec_si_result[i]);
      78  #else
      79         abort();
      80  #endif
      81    }
      82  
      83    vec_si_expected = (vector signed int){ 404, 505, 606, 707 };
      84  
      85    vec_si_result = vec_unpackl (vec_ss_arg);
      86  
      87    for (i = 0; i < 4; i++) {
      88      if (vec_si_expected[i] != vec_si_result[i])
      89  #if DEBUG
      90         printf("ERROR: vec_unpackl(), vec_si_expected[%d] = %d does not match vec_si_result[%d] = %d\n",
      91  	      i, vec_si_expected[i], i, vec_si_result[i]);
      92  #else
      93         abort();
      94  #endif
      95    }
      96  
      97  
      98    vec_pixel_arg = (vector pixel){ 0x0, 0x65, 0xca, 0x12f,
      99  				  0x194, 0x1f9, 0x25e, 0x2c3 };
     100    vec_ui_expected = (vector unsigned int){ 0x0, 0x305, 0x60a, 0x90f };
     101  
     102    vec_ui_result = vec_unpackh (vec_pixel_arg);
     103  
     104    for (i = 0; i < 4; i++) {
     105      if (vec_ui_expected[i] != vec_ui_result[i])
     106  #if DEBUG
     107         printf("ERROR: vec_unpackh(), vec_ui_expected[%d] = 0x%x does not match vec_ui_result[%d] = 0x%x\n",
     108  	      i, vec_ui_expected[i], i, vec_ui_result[i]);
     109  #else
     110         abort();
     111  #endif
     112    }
     113  
     114    vec_ui_expected = (vector unsigned int){ 0xc14, 0xf19, 0x121e, 0x1603 };
     115  
     116    vec_ui_result = vec_unpackl (vec_pixel_arg);
     117  
     118    for (i = 0; i < 4; i++) {
     119      if (vec_ui_expected[i] != vec_ui_result[i])
     120  #if DEBUG
     121         printf("ERROR: vec_unpackl(), vec_ui_expected[%d] = 0x%x does not match vec_ui_result[%d] = 0x%x\n",
     122  	      i, vec_ui_expected[i], i, vec_ui_result[i]);
     123  #else
     124         abort();
     125  #endif
     126    }
     127  
     128  
     129    vec_bc_arg = (vector bool char){ 0, 1, 0, 1, 0, 1, 0, 1,
     130  				   0, 0, 1, 1, 0, 0, 1, 1 };
     131  
     132    vec_bs_expected = (vector bool short){ 0, 1, 0, 1, 0, 1, 0, 1 };
     133  
     134    vec_bs_result = vec_unpackh (vec_bc_arg);
     135  
     136    for (i = 0; i < 8; i++) {
     137      if (vec_bs_expected[i] != vec_bs_result[i])
     138  #if DEBUG
     139         printf("ERROR: vec_unpackh(), vec_bs_expected[%d] = %d does not match vec_bs_result[%d] = %d\n",
     140  	      i, vec_bs_expected[i], i, vec_bs_result[i]);
     141  #else
     142         abort();
     143  #endif
     144    }
     145  
     146    vec_bs_expected = (vector bool short){ 0, 0, 1, 1, 0, 0, 1, 1 };
     147  
     148    vec_bs_result = vec_unpackl (vec_bc_arg);
     149  
     150    for (i = 0; i < 8; i++) {
     151      if (vec_bs_expected[i] != vec_bs_result[i])
     152  #if DEBUG
     153         printf("ERROR: vec_unpackh(), vec_bs_expected[%d] = %d does not match vec_bs_result[%d] = %d\n",
     154  	      i, vec_bs_expected[i], i, vec_bs_result[i]);
     155  #else
     156         abort();
     157  #endif
     158    }
     159  
     160    vec_bs_expected = (vector bool short){ 0, 0, 1, 1, 0, 0, 1, 1 };
     161  
     162    vec_bs_result = vec_unpackl (vec_bc_arg);
     163  
     164    for (i = 0; i < 8; i++) {
     165      if (vec_bs_expected[i] != vec_bs_result[i])
     166  #if DEBUG
     167         printf("ERROR: vec_unpackl(), vec_bs_expected[%d] = %d does not match vec_bs_result[%d] = %d\n",
     168  	      i, vec_bs_expected[i], i, vec_bs_result[i]);
     169  #else
     170         abort();
     171  #endif
     172    }
     173  
     174  
     175    vec_sc_arg = (vector signed char){ 0, 1, 2, 3, 4, 5, 6, 7,
     176  				     8, 9, 10, 11, 12, 13, 14, 15 };
     177  
     178    vec_ss_expected = (vector signed short){ 0, 1, 2, 3, 4, 5, 6, 7 };
     179  
     180    vec_ss_result = vec_unpackh (vec_sc_arg);
     181  
     182    for (i = 0; i < 8; i++) {
     183      if (vec_ss_expected[i] != vec_ss_result[i])
     184  #if DEBUG
     185         printf("ERROR: vec_unpackh(), vec_ss_expected[%d] = %d does not match vec_ss_result[%d] = %d\n",
     186  	      i, vec_ss_expected[i], i, vec_ss_result[i]);
     187  #else
     188         abort();
     189  #endif
     190    }
     191  
     192    vec_ss_expected = (vector signed short){ 8, 9, 10, 11, 12, 13, 14, 15 };
     193  
     194    vec_ss_result = vec_unpackl (vec_sc_arg);
     195  
     196    for (i = 0; i < 8; i++) {
     197      if (vec_ss_expected[i] != vec_ss_result[i])
     198  #if DEBUG
     199         printf("ERROR: vec_unpackl(), vec_ss_expected[%d] = %d does not match vec_ss_result[%d] = %d\n",
     200  	      i, vec_ss_expected[i], i, vec_ss_result[i]);
     201  #else
     202         abort();
     203  #endif
     204    }
     205  
     206    return 0;
     207  }