Debian Codegraph @

gcc/testsuite/gcc.target/powerpc/vsx-builtin-14b.c

raw
1 /* { dg-do run } */
2 /* { dg-require-effective-target vmx_hw } */
3 /* { dg-options "-maltivec -O3" } */
4
5 /* This test should run the same on any target that supports altivec/dfp
6 instructions. Intentionally not specifying cpu in order to test
7 all code generation paths. */
8
9 #include <altivec.h>
10
11 extern void abort (void);
12
13 #define CONST0 ((float) (3.1415926539))
14 #define CONST1 ((float) (3.1415926539 * 2))
15 #define CONST2 ((float) (3.1415926539 * 3))
16 #define CONST3 ((float) (3.1415926539 * 4))
17
18 /* Test that indices > length of vector are applied modulo the vector
19 length. */
20
21 /* Test for vector residing in register. */
22 float e0(vector float v){ return __builtin_vec_ext_v4sf (v, 0); }
23 float e1(vector float v){ return __builtin_vec_ext_v4sf (v, 1); }
24 float e7(vector float v){ return __builtin_vec_ext_v4sf (v, 7); }
25 float e8(vector float v){ return __builtin_vec_ext_v4sf (v, 8); }
26
27 /* Test for vector residing in memory. */
28 float me0(vector float *vp){ return __builtin_vec_ext_v4sf (*vp, 0); }
29 float me1(vector float *vp){ return __builtin_vec_ext_v4sf (*vp, 1); }
30
31 float me13(vector float *vp)
32 {
33 return __builtin_vec_ext_v4sf (*vp, 13);
34 }
35
36 float me15(vector float *vp)
37 {
38 return __builtin_vec_ext_v4sf (*vp, 15);
39 }
40
41 /* Test the same with variable indices. */
42
43 /* Test for variable selector and vector residing in register. */
44 __attribute__((noinline))
45 float ei(vector float v, int i)
46 {
47 return __builtin_vec_ext_v4sf (v, i);
48 }
49
50 /* Test for variable selector and vector residing in memory. */
51 float mei(vector float *vp, int i)
52 {
53 return __builtin_vec_ext_v4sf (*vp, i);
54 }
55
56
57 int main (int argc, char *argv[]) {
58 vector float dv = { CONST0, CONST1, CONST2, CONST3 };
59 float d;
60
61 d = e0 (dv);
62 if (d != CONST0)
63 abort ();
64
65 d = e1 (dv);
66 if (d != CONST1)
67 abort ();
68
69 d = e7 (dv);
70 if (d != CONST3)
71 abort ();
72
73 d = e8 (dv);
74 if (d != CONST0)
75 abort ();
76
77 d = me0 (&dv);
78 if (d != CONST0)
79 abort ();
80
81 d = me1 (&dv);
82 if (d != CONST1)
83 abort ();
84
85 d = me13 (&dv);
86 if (d != CONST1)
87 abort ();
88
89 d = me15 (&dv);
90 if (d != CONST3)
91 abort ();
92
93 d = ei (dv, 0);
94 if (d != CONST0)
95 abort ();
96
97 d = ei (dv, 2);
98 if (d != CONST2)
99 abort ();
100
101 d = ei (dv, 11);
102 if (d != CONST3)
103 abort ();
104
105 d = ei (dv, 17);
106 if (d != CONST1)
107 abort ();
108
109 d = mei (&dv, 0);
110 if (d != CONST0)
111 abort ();
112
113 d = mei (&dv, 1);
114 if (d != CONST1)
115 abort ();
116
117 d = mei (&dv, 15);
118 if (d != CONST3)
119 abort ();
120
121 d = mei (&dv, 6);
122 if (d != CONST2)
123 abort ();
124
125 return 0;
126 }