[RS6000] Tests that use int128_t and -m32
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / vsx-store-element-truncate-char.c
blobb69a1f3e291a2038e12c712eff7b54f0c94f2bd4
1 /*
2 Test of vec_xst_trunc (truncate and store rightmost vector element) */
4 /* { dg-do compile {target power10_ok} } */
5 /* { dg-do run {target power10_hw} } */
6 /* { dg-require-effective-target int128 } */
7 /* Deliberately set optization to zero for this test to confirm
8 the stxvr*x instruction is generated. At higher optimization levels
9 the instruction we are looking for is sometimes replaced by other
10 store instructions. */
11 /* { dg-options "-mdejagnu-cpu=power10 -O0" } */
13 /* { dg-final { scan-assembler-times {\mstxvrbx\M} 2 } } */
14 /* { dg-final { scan-assembler-times {\mstbx\M} 0 } } */
16 #include <altivec.h>
17 #include <stdio.h>
18 #include <inttypes.h>
19 #include <string.h>
20 #include <stdlib.h>
22 vector signed __int128 store_this_s[4] = {
23 { (__int128) 0x7000000000000000 << 64 | (__int128) 0x123456789abcdef8ULL},
24 { (__int128) 0x8000000000000000 << 64 | (__int128) 0xfedcba9876543217ULL},
25 { (__int128) 0x1000000000000000 << 64 | (__int128) 0xccccccccccccccccULL},
26 { (__int128) 0xf000000000000000 << 64 | (__int128) 0xaaaaaaaaaaaaaaaaULL}
29 vector unsigned __int128 store_this_us[4] = {
30 { (unsigned __int128) 0x7000000000000000 << 64 | (unsigned __int128) 0x123456789abcdef8ULL},
31 { (unsigned __int128) 0x8000000000000000 << 64 | (unsigned __int128) 0xfedcba9876543217ULL},
32 { (unsigned __int128) 0x1000000000000000 << 64 | (unsigned __int128) 0xeeeeeeeeeeeeeeeeULL},
33 { (unsigned __int128) 0xf000000000000000 << 64 | (unsigned __int128) 0x5555555555555555ULL}
36 #define NUM_VEC_ELEMS 16
38 vector signed char signed_expected[4] = {
39 { 0xf8, 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0},
40 { 0x0 , 0x0, 0x0, 0x0, 0x17, 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0},
41 { 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0xcc, 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0},
42 { 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0xaa, 0x0, 0x0, 0x0}
44 vector unsigned char unsigned_expected[4] = {
45 { 0xf8, 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0},
46 { 0x0 , 0x0, 0x0, 0x0, 0x17, 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0},
47 { 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0xee, 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0},
48 { 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x55, 0x0, 0x0, 0x0}
51 unsigned long long rawbuffer[32];
52 signed char * vsbuffer = (char *)rawbuffer;
53 unsigned char * vubuffer = (unsigned char *)rawbuffer;
55 void reset_buffer() {
56 memset (&rawbuffer,0,sizeof(rawbuffer));
59 #define PRINT_VEC(V) \
60 for (int j=0;j<NUM_VEC_ELEMS;j++) { printf ("(0x%lx) ", V[j] ); }
62 void test_signed_store(vector signed __int128 myvec, int offset, signed char * store_data ) {
63 vec_xst_trunc (myvec, offset, store_data );
66 void test_unsigned_store(vector unsigned __int128 myvec, int offset, unsigned char * store_data ) {
67 vec_xst_trunc (myvec, offset, store_data );
70 int main (int argc, char *argv [])
72 int i;
73 int memcmpresult;
74 int mismatch=0;
75 int verbose=0;
77 #if VERBOSE
78 verbose=1;
79 printf("%s %s\n", __DATE__, __TIME__);
80 #endif
82 if (verbose) {
83 printf("expected results from signed tests:\n");
84 for (i = 0; i < 4 ; i++ ) {
85 PRINT_VEC(signed_expected[i]);
86 printf("\n");
90 for (i = 0; i < 4 ; i++ ) {
91 reset_buffer();
92 test_signed_store (store_this_s[i], 4*i, vsbuffer);
93 memcmpresult = memcmp(rawbuffer,&signed_expected[i],sizeof(vector char));
94 if (memcmpresult) {
95 printf("mismatch signed buffer, i %d (memcmpresult:%d) \n",i,memcmpresult);
96 mismatch++;
97 if (verbose) {
98 printf("results: ");
99 PRINT_VEC(vsbuffer);
100 printf("\n");
105 for (i = 0; i < 4 ; i++ ) {
106 reset_buffer();
107 test_unsigned_store (store_this_us[i], 4*i, vubuffer);
108 memcmpresult = memcmp(rawbuffer,&unsigned_expected[i],sizeof(vector char));
109 if (memcmpresult) {
110 printf("mismatch unsigned buffer, i %d (memcmpresult:%d) \n",i,memcmpresult);
111 mismatch++;
112 if (verbose) {
113 printf("results :");
114 PRINT_VEC(vubuffer);
115 printf("\n");
120 if (mismatch) {
121 printf("%d mismatches. \n",mismatch);
122 abort();
124 return 0;