(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
powerpc/
vsx-store-element-truncate-longlong.c
       1  /*
       2     Test of vec_xst_trunc (truncate and store rightmost vector element) */
       3  
       4  /* { dg-do run { target power10_hw } } */
       5  /* { dg-do compile { target { ! power10_hw } } } */
       6  /* { dg-require-effective-target power10_ok } */
       7  /* { dg-require-effective-target int128 } */
       8  
       9  /* Deliberately set optization to zero for this test to confirm
      10     the stxvr*x instruction is generated. At higher optimization levels
      11     the instruction we are looking for is sometimes replaced by other
      12     store instructions. */
      13  /* { dg-options "-mdejagnu-cpu=power10 -O0 -save-temps" } */
      14  
      15  /* { dg-final { scan-assembler-times {\mstxvrdx\M} 2 } } */
      16  /* { dg-final { scan-assembler-times {\mstwx\M} 0 } } */
      17  
      18  #include <altivec.h>
      19  #include <stdio.h>
      20  #include <inttypes.h>
      21  #include <string.h>
      22  #include <stdlib.h>
      23  
      24  vector signed __int128 store_this_s[4] = {
      25  { (__int128) 0x7000000000000000 << 64 | (__int128) 0x123456789abcdef8ULL},
      26  { (__int128) 0x8000000000000000 << 64 | (__int128) 0xfedcba9876543217ULL},
      27  { (__int128) 0x1000000000000000 << 64 | (__int128) 0xccccccccccccccccULL},
      28  { (__int128) 0xf000000000000000 << 64 | (__int128) 0xaaaaaaaaaaaaaaaaULL}
      29  };
      30  
      31  vector unsigned __int128 store_this_us[4] = {
      32  { (unsigned __int128) 0x7000000000000000 << 64 | (unsigned __int128) 0x123456789abcdef8ULL},
      33  { (unsigned __int128) 0x8000000000000000 << 64 | (unsigned __int128) 0xfedcba9876543217ULL},
      34  { (unsigned __int128) 0x1000000000000000 << 64 | (unsigned __int128) 0xeeeeeeeeeeeeeeeeULL},
      35  { (unsigned __int128) 0xf000000000000000 << 64 | (unsigned __int128) 0x5555555555555555ULL}
      36  };
      37  
      38  #define NUM_VEC_ELEMS 2
      39  
      40  vector signed long long signed_expected[5] = {
      41  	{ 0x123456789abcdef8,                0x0},
      42  	{ 0x7654321700000000,         0xfedcba98},
      43  	{ 0x0000000000000000, 0xcccccccccccccccc},
      44  	{ 0x0000000000000000, 0xaaaaaaaa00000000}  /*note that some data written into the next word */
      45  };
      46  vector unsigned long long unsigned_expected[5] = {
      47  	{ 0x123456789abcdef8,                0x0},
      48  	{ 0x7654321700000000,         0xfedcba98},
      49  	{ 0x0000000000000000, 0xeeeeeeeeeeeeeeee},
      50  	{ 0x0000000000000000, 0x5555555500000000}
      51  };
      52  
      53  unsigned long long rawbuffer[32];
      54  signed long long * vsbuffer = (long long *)rawbuffer;
      55  unsigned long long * vubuffer = (unsigned long long *)rawbuffer;
      56  
      57  void reset_buffer() {
      58  	memset (&rawbuffer,0,sizeof(rawbuffer));
      59  }
      60  
      61  #define PRINT_VEC(V) \
      62     for (int j=0;j<NUM_VEC_ELEMS;j++) {	printf ("(0x%lx) ", V[j] ); }
      63  
      64  void test_signed_store(vector signed __int128 myvec, int offset, signed long long * store_data ) {
      65  	vec_xst_trunc (myvec, offset, store_data);
      66  }
      67  
      68  void test_unsigned_store(vector unsigned __int128 myvec, int offset, unsigned long long * store_data )   {
      69  	vec_xst_trunc (myvec, offset, store_data);
      70  }
      71  
      72  int main (int argc, char *argv [])
      73  {
      74     int i;
      75     int memcmpresult;
      76     int mismatch=0;
      77     int verbose=0;
      78  
      79  #if VERBOSE
      80     verbose=1;
      81     printf("%s %s\n", __DATE__, __TIME__);
      82  #endif
      83  
      84     if (verbose) {
      85        printf("expected results from signed tests:\n");
      86        for (i = 0; i < 4 ; i++ ) {
      87  	 PRINT_VEC(signed_expected[i]);
      88  	 printf("\n");
      89        }
      90     }
      91  
      92     for (i = 0; i < 4 ; i++ ) {
      93        reset_buffer();
      94        test_signed_store (store_this_s[i], 4*i, vsbuffer);
      95        memcmpresult = memcmp(rawbuffer,&signed_expected[i],sizeof(vector long long));
      96        if (memcmpresult) {
      97  	 printf("mismatch signed buffer, i %d (memcmpresult:%d) \n",i,memcmpresult);
      98  	 mismatch++;
      99  	 if (verbose) {
     100  	    printf("results: ");
     101  	    PRINT_VEC(vsbuffer);
     102  	    printf("\n");
     103  	 }
     104        }
     105     }
     106  
     107     for (i = 0; i < 4 ; i++ ) {
     108        reset_buffer();
     109        test_unsigned_store (store_this_us[i], 4*i, vubuffer);
     110        memcmpresult = memcmp(rawbuffer,&unsigned_expected[i],sizeof(vector long long));
     111        if (memcmpresult) {
     112  	 printf("mismatch unsigned buffer, i %d (memcmpresult:%d) \n",i,memcmpresult);
     113  	 mismatch++;
     114  	 if (verbose) {
     115  	    printf("results :");
     116  	    PRINT_VEC(vubuffer);
     117  	    printf("\n");
     118  	 }
     119        }
     120     }
     121  
     122     if (mismatch) {
     123        printf("%d mismatches. \n",mismatch);
     124        abort();
     125     }
     126     return 0;
     127  }
     128