1 #include "altivec.h"
2
3 typedef vector unsigned long long v2du;
4 typedef vector signed long long v2di;
5 typedef vector unsigned int v4su;
6 typedef vector signed int v4si;
7 typedef vector unsigned short v8hu;
8 typedef vector signed short v8hi;
9 typedef vector unsigned char v16qu;
10 typedef vector signed char v16qi;
11 typedef vector double v2df;
12 typedef vector float v4sf;
13
14 typedef unsigned long long du;
15 typedef signed long long di;
16 typedef unsigned int su;
17 typedef signed int si;
18 typedef unsigned short hu;
19 typedef signed short hi;
20 typedef unsigned char qu;
21 typedef signed char qi;
22 typedef double df;
23 typedef float sf;
24
25 /* To test whether we can optimize vector permutation away when
26 the two inputs are same type CTOR or one input is CTOR and the
27 other is CST. */
28
29 /* CTOR + CTOR part (only same type supported). */
30
31 /* Test both operands are same type CTOR (type unsigned long long). */
32 __attribute__ ((noipa)) v2du
test_ctor_ctor_same_du(du a,du b)33 test_ctor_ctor_same_du (du a, du b)
34 {
35 v2du v1 = {a, 0};
36 v2du v2 = {b, 0};
37 v16qu vc = {0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23};
38 v2du vres = (v2du) vec_perm ((v16qu) v1, (v16qu) v2, vc);
39 return vres;
40 }
41
42 /* Test both operands are same type CTOR (type double). */
43 __attribute__ ((noipa)) v2df
test_ctor_ctor_same_df(df a,df b)44 test_ctor_ctor_same_df (df a, df b)
45 {
46 v2df v1 = {0.0, a};
47 v2df v2 = {0.0, b};
48 v16qu vc = {8, 9, 10, 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30, 31};
49 v2df vres = (v2df) vec_perm ((v16qu) v1, (v16qu) v2, vc);
50 return vres;
51 }
52
53 /* Test both operands are same type CTOR (type signed int). */
54 __attribute__ ((noipa)) v4si
test_ctor_ctor_same_si(si a,si b,si c,si d)55 test_ctor_ctor_same_si (si a, si b, si c, si d)
56 {
57 v4si v1 = {0, a, 0, c};
58 v4si v2 = {0, b, 0, d};
59 v16qu vc = {4, 5, 6, 7, 20, 21, 22, 23, 12, 13, 14, 15, 28, 29, 30, 31};
60 v4si vres = (v4si) vec_perm ((v16qu) v1, (v16qu) v2, vc);
61 return vres;
62 }
63
64 /* Test both operands are same type CTOR (type float). */
65 __attribute__ ((noipa)) v4sf
test_ctor_ctor_same_sf(sf a,sf b,sf c,sf d)66 test_ctor_ctor_same_sf (sf a, sf b, sf c, sf d)
67 {
68 v4sf v1 = {c, 0.0f, d, 0.0f};
69 v4sf v2 = {a, 0.0f, b, 0.0f};
70 v16qu vc = {16, 17, 18, 19, 24, 25, 26, 27, 0, 1, 2, 3, 8, 9, 10, 11};
71 v4sf vres = (v4sf) vec_perm ((v16qu) v1, (v16qu) v2, vc);
72 return vres;
73 }
74
75 /* Test both operands are same type CTOR (type unsigned short). */
76 __attribute__ ((noipa)) v8hu
test_ctor_ctor_same_hu(hu a,hu b,hu c,hu d,hu e,hu f,hu g,hu h)77 test_ctor_ctor_same_hu (hu a, hu b, hu c, hu d, hu e, hu f, hu g, hu h)
78 {
79 v8hu v1 = {0, a, 0, b, 0, c, 0, d};
80 v8hu v2 = {0, e, 0, f, 0, g, 0, h};
81 v16qu vc = {2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31};
82 v8hu vres = (v8hu) vec_perm ((v16qu) v1, (v16qu) v2, vc);
83 return vres;
84 }
85
86 /* Test both operands are same type CTOR (type signed char). */
87 __attribute__ ((noipa)) v16qi
test_ctor_ctor_same_qi(qi a,qi b,qi c,qi d,qi e,qi f,qi g,qi h)88 test_ctor_ctor_same_qi (qi a, qi b, qi c, qi d, qi e, qi f, qi g, qi h)
89 {
90 v16qi v1 = {0, a, 0, b, 0, c, 0, d, 0, a, 0, b, 0, c, 0, d};
91 v16qi v2 = {0, e, 0, f, 0, g, 0, h, 0, e, 0, f, 0, g, 0, h};
92 v16qu vc = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31};
93 v16qi vres = (v16qi) vec_perm ((v16qu) v1, (v16qu) v2, vc);
94 return vres;
95 }
96
97 /* CTOR + CST part (same type). */
98
99 __attribute__ ((noipa)) v2du
test_ctor_cst_same_du(du a,du b)100 test_ctor_cst_same_du (du a, du b)
101 {
102 v2du v1 = {a, b};
103 v2du v2 = {100, 200};
104 v16qu vc = {0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23};
105 v2du vres = (v2du) vec_perm ((v16qu) v1, (v16qu) v2, vc);
106 return vres;
107 }
108
109 __attribute__ ((noipa)) v4sf
test_ctor_cst_same_sf(sf a,sf b)110 test_ctor_cst_same_sf (sf a, sf b)
111 {
112 v4sf v1 = {0.0f, a, 0.0f, b};
113 v4sf v2 = {1.0f, 2.0f, 3.0f, 4.0f};
114 v16qu vc = {4, 5, 6, 7, 20, 21, 22, 23, 12, 13, 14, 15, 28, 29, 30, 31};
115 v4sf vres = (v4sf) vec_perm ((v16qu) v1, (v16qu) v2, vc);
116 return vres;
117 }
118
119 /* CST + CTOR part (same type). */
120
121 __attribute__ ((noipa)) v2df
test_ctor_cst_same_df(df a,df b)122 test_ctor_cst_same_df (df a, df b)
123 {
124 v2df v1 = {a, b};
125 v2df v2 = {100.0, 200.0};
126 v16qu vc = {8, 9, 10, 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30, 31};
127 v2df vres = (v2df) vec_perm ((v16qu) v1, (v16qu) v2, vc);
128 return vres;
129 }
130
131 __attribute__ ((noipa)) v4si
test_cst_ctor_same_si(si a,si b)132 test_cst_ctor_same_si (si a, si b)
133 {
134 v4si v1 = {a, 0, b, 0};
135 v4si v2 = {1, 2, 3, 4};
136 v16qu vc = {16, 17, 18, 19, 24, 25, 26, 27, 0, 1, 2, 3, 8, 9, 10, 11};
137 v4si vres = (v4si) vec_perm ((v16qu) v1, (v16qu) v2, vc);
138 return vres;
139 }
140
141 /* CTOR + CST part (different types). */
142
143 __attribute__ ((noipa)) v2di
test_ctor_cst_diff_di_si(di a,di b)144 test_ctor_cst_diff_di_si (di a, di b)
145 {
146 v2di v1 = {a, b};
147 v4si v2 = {3, 0, 4, 0};
148 v16qu vc = {0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23};
149 v2di vres = (v2di) vec_perm ((v16qu) v1, (v16qu) v2, vc);
150 return vres;
151 }
152
153 /* CST + CTOR part (different types). */
154
155 __attribute__ ((noipa)) v2du
test_cst_ctor_diff_sf_du(du a,du b)156 test_cst_ctor_diff_sf_du (du a, du b)
157 {
158 v4sf v1 = {1.0f, 2.0f, 3.0f, 4.0f};
159 v2du v2 = {a, b};
160 v16qu vc = {0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23};
161 v2du vres = (v2du) vec_perm ((v16qu) v1, (v16qu) v2, vc);
162 return vres;
163 }
164