Debian Codegraph @

gcc/testsuite/gcc.target/powerpc/builtins-3-p9-runnable.c

raw
1 /* { dg-do run } */
2 /* { dg-require-effective-target p9vector_hw } */
3 /* { dg-options "-mdejagnu-cpu=power9 -O2" } */
4
5 #ifdef DEBUG
6 #include <stdio.h>
7 #endif
8
9 #include <altivec.h> // vector
10
11 void abort (void);
12
13 int main() {
14 int i;
15 vector float vfr, vfexpt;
16 vector unsigned short vusha;
17
18 /* 1.0, -2.0, 0.0, 8.5, 1.5, 0.5, 1.25, -0.25 */
19 vusha = (vector unsigned short){0B011110000000000, 0B1100000000000000,
20 0B000000000000000, 0B0100100001000000,
21 0B011111000000000, 0B0011100000000000,
22 0B011110100000000, 0B1011010000000000};
23
24 #ifdef DEBUG
25 printf ("Claim, source data is 8 16-bit floats:\n");
26 printf (" {1.0, -2.0, 0.0, 8.5, 1.5, 0.5, 1.25, -0.25}\n");
27 printf ("vusha = (vector unsigned short){0B011110000000000, 0B1100000000000000,\n");
28 printf (" 0B000000000000000, 0B0100100001000000,\n");
29 printf (" 0B011111000000000, 0B0011100000000000,\n");
30 printf (" 0B011110100000000, 0B1011010000000000};\n\n");
31 #endif
32
33 /* The ABI lists the builtins as:
34
35 vec_extract_fp32_from_shorth()
36 vec_extract_fp32_from_shortl()
37
38 GCC will also accept and map the builtin names
39
40 vec_extract_fp_from_shorth()
41 vec_extract_fp_from_shortl()
42
43 to the same builtins internally. For completeness,
44 test both builtin function names. */
45
46 vfexpt = (vector float){1.0, -2.0, 0.0, 8.5};
47 vfr = vec_extract_fp32_from_shorth(vusha);
48
49 #ifdef DEBUG
50 printf ("vec_extract_fp32_from_shorth\n");
51 for (i=0; i<4; i++)
52 printf("result[%d] = %f; expected[%d] = %f\n",
53 i, vfr[i], i, vfexpt[i]);
54 #endif
55
56 for (i=0; i<4; i++) {
57 if (vfr[i] != vfexpt[i])
58 abort();
59 }
60
61 vfexpt = (vector float){1.5, 0.5, 1.25, -0.25};
62 vfr = vec_extract_fp32_from_shortl(vusha);
63
64 #ifdef DEBUG
65 printf ("\nvec_extract_fp32_from_shortl\n");
66 for (i=0; i<4; i++)
67 printf("result[%d] = %f; expected[%d] = %f\n",
68 i, vfr[i], i, vfexpt[i]);
69 #endif
70
71 for (i=0; i<4; i++) {
72 if (vfr[i] != vfexpt[i])
73 abort();
74 }
75 vfexpt = (vector float){1.0, -2.0, 0.0, 8.5};
76 vfr = vec_extract_fp_from_shorth(vusha);
77
78 #ifdef DEBUG
79 printf ("vec_extract_fp_from_shorth\n");
80 for (i=0; i<4; i++)
81 printf("result[%d] = %f; expected[%d] = %f\n",
82 i, vfr[i], i, vfexpt[i]);
83 #endif
84
85 for (i=0; i<4; i++) {
86 if (vfr[i] != vfexpt[i])
87 abort();
88 }
89
90 vfexpt = (vector float){1.5, 0.5, 1.25, -0.25};
91 vfr = vec_extract_fp_from_shortl(vusha);
92
93 #ifdef DEBUG
94 printf ("\nvec_extract_fp_from_shortl\n");
95 for (i=0; i<4; i++)
96 printf("result[%d] = %f; expected[%d] = %f\n",
97 i, vfr[i], i, vfexpt[i]);
98 #endif
99
100 for (i=0; i<4; i++) {
101 if (vfr[i] != vfexpt[i])
102 abort();
103 }
104 }