1 /* { dg-do run { target { powerpc*-*-* && vmx_hw } } } */
2 /* { dg-do compile { target { powerpc*-*-* && { ! vmx_hw } } } } */
3 /* { dg-require-effective-target powerpc_altivec_ok } */
4 /* { dg-options "-maltivec" } */
5 
6 /* Program to test PowerPC AltiVec instructions.  */
7 
8 #include <altivec.h>
9 #include <stdio.h>
10 
11 extern void abort (void);
12 #define CHECK_IF(E) if(!(E)) abort()
13 
14 vector char sca = {0,4,8,1,5,9,2,6,10,3,7,11,15,12,14,13};
15 vector char scb = {6,4,8,3,1,9,2,6,10,3,7,11,15,12,14,13};
16 vector char sc_expected = {3,4,8,2,3,9,2,6,10,3,7,11,15,12,14,13};
17 vector char scz;
18 vector unsigned char uca = {0,4,8,1,5,9,2,6,10,3,7,11,15,12,14,13};
19 vector unsigned char ucb = {6,4,8,3,1,9,2,6,10,3,7,11,15,12,14,13};
20 vector unsigned char uc_expected = {3,4,8,2,3,9,2,6,10,3,7,11,15,12,14,13};
21 vector unsigned char ucz;
22 
23 vector short int ssia = {9, 16, 25, 36};
24 vector short int ssib = {-8, -27, -64, -125};
25 vector short int ssiz;
26 
27 vector short unsigned int ssua = {9, 16, 25, 36};
28 vector short unsigned int ssub = {8, 27, 64, 125};
29 vector short unsigned int ssuz;
30 
31 vector unsigned int uia = {22, 13, 24, 39};
32 vector unsigned int uib = {8, 7, 4, 15};
33 vector unsigned int ui_expected = {15, 10, 14, 27};
34 vector unsigned int uiz;
35 
36 vector int a1 = (vector int){ 100, 200, 300, 400 };
37 vector int a2 = (vector int){ 500, 600, 700, 800 };
38 vector int addi = (vector int){ 600, 800, 1000, 1200 };
39 vector int avgi = (vector int){ 300, 400, 500, 600 };
40 
41 vector float f1 = (vector float){ 1.0, 2.0, 3.0, 4.0 };
42 vector float f2 = (vector float){ 5.0, 6.0, 7.0, 8.0 };
43 vector float f3;
44 vector float addf1 = (vector float){ 6.0, 8.0, 10.0, 12.0 };
45 vector float addf2 = (vector float){ 6.1, 8.1, 10.1, 12.1 };
46 vector float addf3 = (vector float){ 6.0, 8.0, 9.9, 12.1 };
47 vector int k;
48 vector float f, g, h;
49 
50 int i;
51 
main()52 int main ()
53 {
54 
55   k = vec_add (a1, a2);
56   CHECK_IF (vec_all_eq (addi, k));
57   CHECK_IF (vec_all_ge (addi, k));
58   CHECK_IF (vec_all_le (addi, k));
59   CHECK_IF (vec_any_eq (addi, k));
60   CHECK_IF (vec_any_ge (addi, k));
61   CHECK_IF (vec_any_le (addi, k));
62   CHECK_IF (!vec_any_ne (addi, k));
63   CHECK_IF (!vec_any_lt (addi, k));
64   CHECK_IF (!vec_any_gt (addi, k));
65   CHECK_IF (!vec_any_ne (addi, k));
66   CHECK_IF (!vec_any_lt (addi, k));
67   CHECK_IF (!vec_any_gt (addi, k));
68 
69   ssiz = vec_avg (ssia, ssib);
70   ssuz = vec_avg (ssua, ssub);
71   k = vec_avg (a1, a2);
72   scz = vec_avg (sca, scb);
73 
74   for (i=0; i< 16; i++)
75     if (scz[i] != sc_expected[i])
76       abort ();
77 
78   ucz = vec_avg (uca, ucb);
79 
80   for (i=0; i<16; i++)
81     if (ucz[i] != uc_expected[i])
82       abort ();
83 
84   uiz = vec_avg (uia, uib);
85 
86   for (i=0; i< 4; i++)
87     if (uiz[i] != ui_expected[i])
88       abort ();
89 
90   CHECK_IF (vec_all_eq (k, avgi));
91 
92   h = vec_add (f1, f2);
93   CHECK_IF (vec_all_eq (h, addf1));
94   CHECK_IF (vec_all_ge (h, addf1));
95   CHECK_IF (vec_all_le (h, addf1));
96   CHECK_IF (vec_any_eq (h, addf1));
97   CHECK_IF (vec_any_ge (h, addf1));
98   CHECK_IF (vec_any_le (h, addf1));
99   CHECK_IF (!vec_any_ne (h, addf1));
100   CHECK_IF (!vec_any_lt (h, addf1));
101   CHECK_IF (!vec_any_gt (h, addf1));
102   CHECK_IF (!vec_any_ne (h, addf1));
103   CHECK_IF (!vec_any_lt (h, addf1));
104   CHECK_IF (!vec_any_gt (h, addf1));
105 
106   CHECK_IF (vec_all_gt (addf2, addf1));
107   CHECK_IF (vec_any_gt (addf2, addf1));
108   CHECK_IF (vec_all_ge (addf2, addf1));
109   CHECK_IF (vec_any_ge (addf2, addf1));
110   CHECK_IF (vec_all_ne (addf2, addf1));
111   CHECK_IF (vec_any_ne (addf2, addf1));
112   CHECK_IF (!vec_all_lt (addf2, addf1));
113   CHECK_IF (!vec_any_lt (addf2, addf1));
114   CHECK_IF (!vec_all_le (addf2, addf1));
115   CHECK_IF (!vec_any_le (addf2, addf1));
116   CHECK_IF (!vec_all_eq (addf2, addf1));
117   CHECK_IF (!vec_any_eq (addf2, addf1));
118 
119   CHECK_IF (vec_any_eq (addf3, addf1));
120   CHECK_IF (vec_any_ne (addf3, addf1));
121   CHECK_IF (vec_any_lt (addf3, addf1));
122   CHECK_IF (vec_any_le (addf3, addf1));
123   CHECK_IF (vec_any_gt (addf3, addf1));
124   CHECK_IF (vec_any_ge (addf3, addf1));
125   CHECK_IF (!vec_all_eq (addf3, addf1));
126   CHECK_IF (!vec_all_ne (addf3, addf1));
127   CHECK_IF (!vec_all_lt (addf3, addf1));
128   CHECK_IF (!vec_all_le (addf3, addf1));
129   CHECK_IF (!vec_all_gt (addf3, addf1));
130   CHECK_IF (!vec_all_ge (addf3, addf1));
131 
132   CHECK_IF (vec_all_numeric (addf3));
133   CHECK_IF (vec_all_in (addf1, addf2));
134 
135   CHECK_IF (vec_step (vector bool char) == 16);
136   CHECK_IF (vec_step (addf3) == 4);
137 
138   return 0;
139 }
140