[RS6000] dg-do !compile and scan-assembler
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / vsx-load-element-extend-int.c
blob366a01370044990b034d83c323dc0bbf5658d87b
1 /*
2 Test of vec_xl_sext and vec_xl_zext (load into rightmost
3 vector element and zero/sign extend). */
5 /* { dg-do compile {target power10_ok} } */
6 /* { dg-do run {target power10_hw} } */
7 /* { dg-require-effective-target int128 } */
9 /* Deliberately set optization to zero for this test to confirm
10 the lxvr*x instruction is generated. At higher optimization levels
11 the instruction we are looking for is sometimes replaced by other
12 load instructions. */
13 /* { dg-options "-mdejagnu-cpu=power10 -O0" } */
15 /* { dg-final { scan-assembler-times {\mlxvrwx\M} 2 } } */
17 #define NUM_VEC_ELEMS 4
18 #define ITERS 16
21 Codegen at time of writing is a single lxvrwx for the zero
22 extended test, and a lwax,mtvsrdd,vextsd2q for the sign
23 extended test.
25 0000000010000c90 <test_sign_extended_load>:
26 10000c90: aa 1a 24 7d lwax r9,r4,r3
27 10000c94: 67 4b 40 7c mtvsrdd vs34,0,r9
28 10000c98: 02 16 5b 10 vextsd2q v2,v2
29 10000c9c: 20 00 80 4e blr
31 0000000010000cb0 <test_zero_extended_unsigned_load>:
32 10000cb0: 9b 18 44 7c lxvrwx vs34,r4,r3
33 10000cb4: 20 00 80 4e blr
36 #include <altivec.h>
37 #include <stdio.h>
38 #include <inttypes.h>
39 #include <string.h>
40 #include <stdlib.h>
42 long long buffer[8];
43 unsigned long verbose=0;
45 char initbuffer[64] = {
46 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
47 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x80,
48 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
49 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0x90,
50 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
51 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xa0,
52 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
53 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xb0
56 vector signed __int128 signed_expected[16] = {
57 { (__int128) 0x0000000000000000 << 64 | (__int128) 0x0000000014131211},
58 { (__int128) 0x0000000000000000 << 64 | (__int128) 0x0000000015141312},
59 { (__int128) 0x0000000000000000 << 64 | (__int128) 0x0000000016151413},
60 { (__int128) 0x0000000000000000 << 64 | (__int128) 0x0000000017161514},
61 { (__int128) 0x0000000000000000 << 64 | (__int128) 0x0000000018171615},
62 { (__int128) 0xffffffffffffffff << 64 | (__int128) 0xffffffff89181716},
63 { (__int128) 0xffffffffffffffff << 64 | (__int128) 0xffffffff8a891817},
64 { (__int128) 0xffffffffffffffff << 64 | (__int128) 0xffffffff8b8a8918},
65 { (__int128) 0xffffffffffffffff << 64 | (__int128) 0xffffffff8c8b8a89},
66 { (__int128) 0xffffffffffffffff << 64 | (__int128) 0xffffffff8d8c8b8a},
67 { (__int128) 0xffffffffffffffff << 64 | (__int128) 0xffffffff8e8d8c8b},
68 { (__int128) 0xffffffffffffffff << 64 | (__int128) 0xffffffff8f8e8d8c},
69 { (__int128) 0xffffffffffffffff << 64 | (__int128) 0xffffffff808f8e8d},
70 { (__int128) 0x0000000000000000 << 64 | (__int128) 0x0000000021808f8e},
71 { (__int128) 0x0000000000000000 << 64 | (__int128) 0x000000002221808f},
72 { (__int128) 0x0000000000000000 << 64 | (__int128) 0x0000000023222180}
75 vector unsigned __int128 unsigned_expected[16] = {
76 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x0000000014131211},
77 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x0000000015141312},
78 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x0000000016151413},
79 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x0000000017161514},
80 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x0000000018171615},
81 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x0000000089181716},
82 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x000000008a891817},
83 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x000000008b8a8918},
84 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x000000008c8b8a89},
85 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x000000008d8c8b8a},
86 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x000000008e8d8c8b},
87 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x000000008f8e8d8c},
88 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x00000000808f8e8d},
89 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x0000000021808f8e},
90 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x000000002221808f},
91 { (unsigned __int128) 0x0000000000000000 << 64 | (unsigned __int128) 0x0000000023222180}
94 __attribute__ ((noinline))
95 vector signed __int128 test_sign_extended_load(int RA, signed int * RB) {
96 return vec_xl_sext (RA, RB);
99 __attribute__ ((noinline))
100 vector unsigned __int128 test_zero_extended_unsigned_load(int RA, unsigned int * RB) {
101 return vec_xl_zext (RA, RB);
104 int main (int argc, char *argv [])
106 int iteration=0;
107 int mismatch=0;
108 vector signed __int128 signed_result_v;
109 vector unsigned __int128 unsigned_result_v;
110 #if VERBOSE
111 verbose=1;
112 printf("%s %s\n", __DATE__, __TIME__);
113 #endif
115 memcpy(&buffer, &initbuffer, sizeof(buffer));
117 if (verbose) {
118 printf("input buffer:\n");
119 for (int k=0;k<64;k++) {
120 printf("%x ",initbuffer[k]);
121 if (k && (k+1)%16==0) printf("\n");
123 printf("signed_expected:\n");
124 for (int k=0;k<ITERS;k++) {
125 printf("%llx ",signed_expected[iteration][0]>>64);
126 printf(" %llx \n",signed_expected[iteration][0]&0xffffffffffffffff);
127 printf("\n");
129 printf("unsigned_expected:\n");
130 for (int k=0;k<ITERS;k++) {
131 printf("%llx ",signed_expected[iteration][0]>>64);
132 printf(" %llx \n",signed_expected[iteration][0]&0xffffffffffffffff);
133 printf("\n");
137 for (iteration = 0; iteration < ITERS ; iteration++ ) {
138 signed_result_v = test_sign_extended_load (iteration, (signed int*)buffer);
139 if (signed_result_v[0] != signed_expected[iteration][0] ) {
140 mismatch++;
141 printf("Unexpected results from signed load. i=%d \n", iteration);
142 printf("got: %llx ",signed_result_v[0]>>64);
143 printf(" %llx \n",signed_result_v[0]&0xffffffffffffffff);
144 printf("expected: %llx ",signed_expected[iteration][0]>>64);
145 printf(" %llx \n",signed_expected[iteration][0]&0xffffffffffffffff);
146 fflush(stdout);
150 for (iteration = 0; iteration < ITERS ; iteration++ ) {
151 unsigned_result_v = test_zero_extended_unsigned_load (iteration, (unsigned int*)buffer);
152 if (unsigned_result_v[0] != unsigned_expected[iteration][0]) {
153 mismatch++;
154 printf("Unexpected results from unsigned load. i=%d \n", iteration);
155 printf("got: %llx ",unsigned_result_v[0]>>64);
156 printf(" %llx \n",unsigned_result_v[0]&0xffffffffffffffff);
157 printf("expected: %llx ",unsigned_expected[iteration][0]>>64);
158 printf(" %llx \n",unsigned_expected[iteration][0]&0xffffffffffffffff);
159 fflush(stdout);
163 if (mismatch) {
164 printf("%d mismatches. \n",mismatch);
165 abort();
167 return 0;