1 /* { dg-do run { target { power10_hw } } } */
2 /* { dg-do link { target { ! power10_hw } } } */
3 /* { dg-require-effective-target power10_ok } */
4 /* { dg-options "-mdejagnu-cpu=power10" } */
5
6 #include <altivec.h>
7
8 extern void abort (void);
9
10 #define NumSamples 4
11
12 void
doTests00000001(vector unsigned char a_sources[],vector unsigned char b_sources[],vector unsigned char c_sources[])13 doTests00000001 (vector unsigned char a_sources [],
14 vector unsigned char b_sources [],
15 vector unsigned char c_sources []) {
16 for (int i = 0; i < NumSamples; i++)
17 for (int j = 0; j < NumSamples; j++)
18 for (int k = 0; k < NumSamples; k++)
19 {
20 vector unsigned char a = a_sources [i];
21 vector unsigned char b = b_sources [j];
22 vector unsigned char c = c_sources [k];
23 vector unsigned char result = vec_ternarylogic (a, b, c, 0x01);
24 vector unsigned char intended = (a & b & c);
25 if (!vec_all_eq (result, intended))
26 abort ();
27 }
28 }
29
30 void
doTests11100101(vector unsigned char a_sources[],vector unsigned char b_sources[],vector unsigned char c_sources[])31 doTests11100101 (vector unsigned char a_sources [],
32 vector unsigned char b_sources [],
33 vector unsigned char c_sources []) {
34 for (int i = 0; i < NumSamples; i++)
35 for (int j = 0; j < NumSamples; j++)
36 for (int k = 0; k < NumSamples; k++)
37 {
38 vector unsigned char a = a_sources [i];
39 vector unsigned char b = b_sources [j];
40 vector unsigned char c = c_sources [k];
41 vector unsigned char result = vec_ternarylogic (a, b, c, 0xe5);
42 vector unsigned char intended =
43 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
44 // Supposed to be a ? c: nand (b,c)
45 for (int l = 0; l < 16; l++)
46 {
47 for (int m = 0; m < 8; m++)
48 {
49 unsigned char bit_selector = (0x01 << m);
50 if (a[l] & bit_selector)
51 intended [l] |= c [l] & bit_selector;
52 else if ((b [l] & c [l] & bit_selector) == 0)
53 intended [l] |= bit_selector;
54 }
55 }
56 if (!vec_all_eq (result, intended))
57 abort ();
58 }
59 }
60
61 void
doTests11110011(vector unsigned char a_sources[],vector unsigned char b_sources[],vector unsigned char c_sources[])62 doTests11110011 (vector unsigned char a_sources [],
63 vector unsigned char b_sources [],
64 vector unsigned char c_sources []) {
65 for (int i = 0; i < NumSamples; i++)
66 for (int j = 0; j < NumSamples; j++)
67 for (int k = 0; k < NumSamples; k++)
68 {
69 vector unsigned char a = a_sources [i];
70 vector unsigned char b = b_sources [j];
71 vector unsigned char c = c_sources [k];
72 vector unsigned char result = vec_ternarylogic (a, b, c, 0xfb);
73 vector unsigned char intended = {
74 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
75 for (int i = 0; i < 16; i++)
76 intended [i] = b [i] | ~(a [i] & c [i]);
77 if (!vec_all_eq (result, intended))
78 abort ();
79 }
80 }
81
main(int argc,char * argv[])82 int main (int argc, char *argv [])
83 {
84 vector unsigned char a_sources [NumSamples] = {
85 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
86 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 },
87 { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
88 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
89 { 0xcc, 0xcc, 0xcc, 0xcc, 0x55, 0x55, 0x55, 0x55,
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
91 { 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7,
92 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69 },
93 };
94 vector unsigned char b_sources [NumSamples] = {
95 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
96 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 },
97 { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
98 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
99 { 0xcc, 0xcc, 0xcc, 0xcc, 0x55, 0x55, 0x55, 0x55,
100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
101 { 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7,
102 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69 },
103 };
104 vector unsigned char c_sources [NumSamples] = {
105 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
106 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 },
107 { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
108 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
109 { 0xcc, 0xcc, 0xcc, 0xcc, 0x55, 0x55, 0x55, 0x55,
110 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
111 { 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7,
112 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69 },
113 };
114
115 doTests00000001 (a_sources, b_sources, c_sources);
116 doTests11100101 (a_sources, b_sources, c_sources);
117 doTests11110011 (a_sources, b_sources, c_sources);
118
119 return 0;
120 }
121