(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
powerpc/
builtins-5-p9-runnable.c
       1  /* { dg-do run { target lp64 } } */
       2  /* { dg-require-effective-target p9vector_hw } */
       3  /* { dg-options "-mdejagnu-cpu=power9 -O2" } */
       4  
       5  #include <stdint.h>
       6  #include <stdio.h> 
       7  #include <inttypes.h>
       8  #include <altivec.h> // vector
       9  
      10  #define TRUE 1
      11  #define FALSE 0
      12  
      13  #ifdef DEBUG
      14  #include <stdio.h>
      15  #endif
      16  
      17  void abort (void);
      18  
      19  int result_wrong(vector unsigned char vec_expected,
      20  		  vector unsigned char vec_actual)
      21  {
      22    int i;
      23  
      24    for (i=0; i<16; i++)
      25      if (vec_expected[i] != vec_actual[i])
      26        return TRUE;
      27  
      28    return FALSE;
      29  }
      30  
      31  int main() {
      32     int i, j;
      33     size_t size;
      34     unsigned char data_uc[100];
      35     vector unsigned char store_data_uc;
      36     unsigned char *address;
      37     vector unsigned char *datap;
      38     
      39     vector unsigned char vec_uc_expected1, vec_uc_result1;
      40     vector int data_int;
      41     
      42     for (i=0; i<100; i++)
      43        data_uc[i] = i+1;
      44  
      45     
      46     /* VEC_XL_LEN */
      47     
      48     size = 8;
      49     vec_uc_result1 = vec_xl_len (data_uc, size);
      50  
      51     vec_uc_expected1 = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
      52                                                0, 0, 0, 0, 0, 0, 0, 0};
      53     
      54     if (result_wrong (vec_uc_expected1, vec_uc_result1))
      55       {
      56  #ifdef DEBUG
      57         printf("Error: result does not match expected result\n");
      58         printf("vec_xl_len (%d): vec_uc_expected1[0] to vec_uc_expected1[15]\n",
      59  	      size);
      60  
      61         for (i=0; i<16; i++)
      62  	 printf(" %d,",vec_uc_expected1[i]);
      63  
      64         printf("\nvec_xl_len (%d): vec_uc_result1[0] to vec_uc_result1[15]\n",
      65  	      size);
      66     
      67         for (i=0; i<16; i++)
      68  	 printf(" %d,", vec_uc_result1[i]);
      69  
      70         printf("\n\n");
      71  #else
      72         abort();
      73  #endif
      74       }
      75  
      76  
      77     /* VEC_XL_LEN_R */
      78     size = 8;
      79     vec_uc_result1 = vec_xl_len_r(data_uc, size);
      80  
      81  #ifdef __LITTLE_ENDIAN__
      82     vec_uc_expected1 = (vector unsigned char){8, 7, 6, 5, 4, 3, 2, 1,
      83  					     0, 0, 0, 0, 0, 0, 0, 0,};
      84  #else
      85     vec_uc_expected1 = (vector unsigned char){0, 0, 0, 0, 0, 0, 0, 0,
      86  					     1, 2, 3, 4, 5, 6, 7, 8,};
      87  #endif
      88     
      89     if (result_wrong (vec_uc_expected1, vec_uc_result1))
      90       {
      91  #ifdef DEBUG
      92         printf("Error: result does not match expected result\n");
      93         printf("vec_xl_len_r(%d): vec_uc_expected1[0] to vec_uc_expected1[15]\n",
      94  	  size);
      95     
      96         for (i=0; i<16; i++)
      97  	 printf(" %d,", vec_uc_expected1[i]);
      98  
      99         printf("\nvec_xl_len_r(%d): vec_uc_result1[0] to vec_uc_result1[15]\n",
     100  	      size);
     101     
     102         for (i=0; i<16; i++)
     103  	 printf(" %d,", vec_uc_result1[i]);
     104  
     105         printf("\n\n");
     106  #else
     107         abort();
     108  #endif
     109       }
     110         
     111  
     112     size = 4;
     113     vec_uc_result1 = vec_xl_len_r(data_uc, size);
     114  
     115  #ifdef __LITTLE_ENDIAN__
     116     vec_uc_expected1 = (vector unsigned char){ 4, 3, 2, 1, 0, 0, 0, 0,
     117                                                0, 0, 0, 0, 0, 0, 0, 0 };
     118  #else
     119     vec_uc_expected1 = (vector unsigned char){ 0, 0, 0, 0, 0, 0, 0, 0,
     120                                                0, 0, 0, 0, 1, 2, 3, 4 };
     121  #endif
     122     
     123     if (result_wrong (vec_uc_expected1, vec_uc_result1))
     124       {
     125  #ifdef DEBUG
     126         printf("Error: result does not match expected result\n");
     127         printf("vec_xl_len_r(%d): vec_uc_expected1[0] to vec_uc_expected1[15]\n",
     128  	    size);
     129     
     130         for (i=0; i<16; i++)
     131  	 printf(" %d,", vec_uc_expected1[i]);
     132  
     133         printf("\nvec_xl_len_r(%d): vec_uc_result1[0] to vec_uc_result1[15]\n",
     134  	      size);
     135     
     136         for (i=0; i<16; i++)
     137  	 printf(" %d,", vec_uc_result1[i]);
     138  
     139         printf("\n\n");
     140  #else
     141         abort();
     142  #endif
     143       }
     144  
     145     size = 2;
     146     vec_uc_result1 = vec_xl_len_r(data_uc, size);
     147  
     148  #ifdef __LITTLE_ENDIAN__
     149     vec_uc_expected1 = (vector unsigned char){ 2, 1, 0, 0, 0, 0, 0, 0,
     150                                                0, 0, 0, 0, 0, 0, 0, 0 };
     151  #else
     152     vec_uc_expected1 = (vector unsigned char){ 0, 0, 0, 0, 0, 0, 0, 0,
     153                                                0, 0, 0, 0, 0, 0, 1, 2 };
     154  #endif
     155     
     156     if (result_wrong (vec_uc_expected1, vec_uc_result1))
     157       {
     158  #ifdef DEBUG
     159         printf("Error: result does not match expected result\n");
     160         printf("vec_xl_len_r(%d): vec_uc_expected1[0] to vec_uc_expected1[15]\n",
     161  	      size);
     162         for (i=0; i<16; i++)
     163  	 printf(" %d,", vec_uc_expected1[i]);
     164  
     165         printf("\nvec_xl_len_r(%d) vec_uc_result1[0] to vec_uc_result1[15]\n",
     166  	      size);
     167     
     168         for (i=0; i<16; i++)
     169  	 printf(" %d,", vec_uc_result1[i]);
     170  
     171         printf("\n\n");
     172  #else
     173         abort();
     174  #endif
     175       }
     176  
     177  
     178     /* VEC_XST_LEN */
     179     vec_uc_expected1 = (vector unsigned char){ 1, 2, 0, 0, 0, 0, 0, 0,
     180                                                0, 0, 0, 0, 0, 0, 0, 0 };
     181     store_data_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
     182  					   9, 10, 11, 12, 13, 14, 15, 16 };
     183     size = 2;
     184  
     185     for (i=0; i<16; i++)
     186       vec_uc_result1[i] = 0;
     187     
     188     address = &vec_uc_result1[0];
     189     vec_xst_len (store_data_uc, address, size);
     190  
     191     if (result_wrong (vec_uc_expected1, vec_uc_result1))
     192       {
     193  #ifdef DEBUG
     194         printf("Error: result does not match expected result\n");
     195         printf("vec_xst_len (%d) vec_uc_result1[0] to vec_uc_result1[15]\n",
     196  	      size);
     197  
     198         for (i=0; i<16; i++)
     199  	 printf(" %d,", vec_uc_expected1[i]);
     200  
     201         printf("\nvec_xst_len (%d) store_data_uc[0] to store_data_uc[15]\n",
     202  	      size);
     203  
     204         for (i=0; i<16; i++)
     205  	 printf(" %d,", vec_uc_result1[i]);
     206  
     207         printf("\n\n");
     208  #else
     209         abort();
     210  #endif
     211       }
     212  
     213     vec_uc_expected1 = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
     214                                                9, 10, 11, 12, 13, 14, 0, 0 };
     215     store_data_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
     216  					   9, 10, 11, 12, 13, 14, 15, 16 };
     217     size = 14;
     218  
     219     for (i=0; i<16; i++)
     220       vec_uc_result1[i] = 0;
     221  
     222     address = &vec_uc_result1[0];
     223  
     224     vec_xst_len (store_data_uc, address, size);
     225     
     226     if (result_wrong (vec_uc_expected1, vec_uc_result1))
     227       {
     228  #ifdef DEBUG
     229         printf("Error: result does not match expected result\n");
     230         printf("vec_xst_len (%d) vec_uc_result1[0] to vec_uc_result1[15]\n",
     231  	      size);
     232  
     233         for (i=0; i<16; i++)
     234  	 printf(" %d,", vec_uc_expected1[i]);
     235  
     236         printf("\nvec_xst_len (%d) store_data_uc[0] to store_data_uc[15]\n",
     237  	      size);
     238  
     239         for (i=0; i<16; i++)
     240  	 printf(" %d,", vec_uc_result1[i]);
     241  
     242         printf("\n\n");
     243  #else
     244         abort();
     245  #endif
     246       }
     247  
     248     /* VEC_XST_LEN_R */
     249  #ifdef __LITTLE_ENDIAN__
     250     vec_uc_expected1 = (vector unsigned char){ 16, 15, 14, 13, 12, 11, 10, 9,
     251  					      8, 7, 6, 5, 4, 3, 2, 1 };
     252  #else
     253     vec_uc_expected1 = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
     254  					      9, 10, 11, 12, 13, 14, 15, 16 };
     255  #endif
     256     store_data_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
     257  					   9, 10, 11, 12, 13, 14, 15, 16 };
     258     vec_uc_result1 = (vector unsigned char){ 0, 0, 0, 0, 0, 0, 0, 0,
     259  					    0, 0, 0, 0, 0, 0, 0, 0 };
     260  
     261     size = 16;
     262  
     263     address = &vec_uc_result1[0];
     264  
     265     vec_xst_len_r(store_data_uc, address, size);
     266  
     267     if (result_wrong (vec_uc_expected1, vec_uc_result1))
     268       {
     269  #ifdef DEBUG
     270         printf("Error: result does not match expected result\n");
     271         printf("vec_xst_len_r(%d) vec_uc_expected1[0] to vec_uc_expected1[15]\n",
     272  	      size);
     273  
     274         for (i=0; i<16; i++)
     275  	 printf(" %d,", vec_uc_expected1[i]);
     276  
     277         printf("\nvec_xst_len_r(%d) result[0] to result[15]\n", size);
     278  
     279         for (i=0; i<16; i++)
     280  	 printf(" %d,", vec_uc_result1[i]);
     281  
     282         printf("\n\n");
     283  #else
     284         abort();
     285  #endif
     286       }
     287  
     288  #ifdef __LITTLE_ENDIAN__
     289     vec_uc_expected1 = (vector unsigned char){ 2, 1, 0, 0, 0, 0, 0, 0,
     290                                                0, 0, 0, 0, 0, 0, 0, 0 };
     291  #else
     292     vec_uc_expected1 = (vector unsigned char){ 15, 16, 0, 0, 0, 0, 0, 0,
     293                                                0, 0, 0, 0, 0, 0, 0, 0 };
     294  #endif
     295     store_data_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
     296  					   9, 10, 11, 12, 13, 14, 15, 16 };
     297     vec_uc_result1 = (vector unsigned char){ 0, 0, 0, 0, 0, 0, 0, 0, 
     298  					    0, 0, 0, 0, 0, 0, 0, 0 };
     299  
     300     size = 2;
     301  
     302     address = &vec_uc_result1[0];
     303  
     304     vec_xst_len_r(store_data_uc, address, size);
     305  
     306     if (result_wrong (vec_uc_expected1, vec_uc_result1))
     307       {
     308  #ifdef DEBUG
     309         printf("Error: result does not match expected result\n");
     310         printf("vec_xst_len_r(%d) vec_uc_expected1[0] to vec_uc_expected1[15]\n",
     311  	      size);
     312     
     313         for (i=0; i<16; i++)
     314  	 printf(" %d,", vec_uc_expected1[i]);
     315  
     316         printf("\nvec_xst_len_r(%d) result[0] to result[15]\n", size);
     317  
     318         for (i=0; i<16; i++)
     319  	 printf(" %d,", vec_uc_result1[i]);
     320  
     321         printf("\n\n");
     322  #else
     323         abort();
     324  #endif
     325       }
     326  
     327  #ifdef __LITTLE_ENDIAN__
     328     vec_uc_expected1 = (vector unsigned char){ 16, 15, 14, 13, 12, 11, 10, 9,
     329                                                8, 7, 6, 5, 4, 3, 2, 1 };
     330  #else
     331     vec_uc_expected1 = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
     332  					      9, 10, 11, 12, 13, 14, 15, 16 };
     333  #endif
     334     store_data_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
     335  					   9, 10, 11, 12, 13, 14, 15, 16 };
     336     vec_uc_result1 = (vector unsigned char){ 0, 0, 0, 0, 0, 0, 0, 0, 
     337  					    0, 0, 0, 0, 0, 0, 0, 0 };
     338  
     339     size = 16;
     340  
     341     address = &vec_uc_result1[0];
     342  
     343     vec_xst_len_r(store_data_uc, address, size);
     344  
     345     if (result_wrong (vec_uc_expected1, vec_uc_result1))
     346       {
     347  #ifdef DEBUG
     348         printf("Error: result does not match expected result\n");
     349         printf("vec_xst_len_r(%d) vec_uc_expected1[0] to vec_uc_expected1[15]\n",
     350  	  size);
     351     
     352         for (i=0; i<16; i++)
     353  	 printf(" %d,", vec_uc_expected1[i]);
     354  
     355         printf("\nvec_xst_len_r(%d) result[0] to result[15]\n", size);
     356  
     357         for (i=0; i<16; i++)
     358  	 printf(" %d,", vec_uc_result1[i]);
     359  
     360         printf("\n\n");
     361  #else
     362         abort();
     363  #endif
     364       }
     365  
     366  #ifdef __LITTLE_ENDIAN__
     367     vec_uc_expected1 = (vector unsigned char){ 14, 13, 12, 11, 10, 9, 8, 7,
     368                                                6, 5, 4, 3, 2, 1, 0, 0 };
     369  #else
     370     vec_uc_expected1 = (vector unsigned char){ 3, 4, 5, 6, 7, 8, 9, 10,
     371                                                11, 12, 13, 14, 15, 16, 0, 0 };
     372  #endif
     373     store_data_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
     374  					   9, 10, 11, 12, 13, 14, 15, 16 };
     375     vec_uc_result1 = (vector unsigned char){ 0, 0, 0, 0, 0, 0, 0, 0, 
     376  					    0, 0, 0, 0, 0, 0, 0, 0 };
     377  
     378     size = 14;
     379  
     380     address = &vec_uc_result1[0];
     381  
     382     vec_xst_len_r(store_data_uc, address, size);
     383  
     384     if (result_wrong (vec_uc_expected1, vec_uc_result1))
     385       {
     386  #ifdef DEBUG
     387         printf("Error: result does not match expected result\n");
     388         printf("vec_xst_len_r(%d) vec_uc_expected1[0] to vec_uc_expected1[15]\n",
     389  	  size);
     390     
     391         for (i=0; i<16; i++)
     392  	 printf(" %d,", vec_uc_expected1[i]);
     393  
     394         printf("\nvec_xst_len_r(%d) result[0] to result[15]\n", size);
     395  
     396         for (i=0; i<16; i++)
     397  	 printf(" %d,", vec_uc_result1[i]);
     398  
     399         printf("\n\n");
     400  #else
     401         abort();
     402  #endif
     403       }
     404  }