Debian Codegraph @

gcc/testsuite/gcc.target/powerpc/vec-ternarylogic-7.c

raw
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
13 doTests00000001 (vector unsigned long long int a_sources [],
14 vector unsigned long long int b_sources [],
15 vector unsigned long long int 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 long long a = a_sources [i];
21 vector unsigned long long b = b_sources [j];
22 vector unsigned long long c = c_sources [k];
23 vector unsigned long long result = vec_ternarylogic (a, b, c, 0x01);
24 vector unsigned long long intended = (a & b & c);
25 if (!vec_all_eq (result, intended))
26 abort ();
27 }
28 }
29
30 void doTests11100101 (vector unsigned long long int a_sources [],
31 vector unsigned long long int b_sources [],
32 vector unsigned long long int c_sources []) {
33 for (int i = 0; i < NumSamples; i++)
34 for (int j = 0; j < NumSamples; j++)
35 for (int k = 0; k < NumSamples; k++)
36 {
37 vector unsigned long long a = a_sources [i];
38 vector unsigned long long b = b_sources [j];
39 vector unsigned long long c = c_sources [k];
40 vector unsigned long long result = vec_ternarylogic (a, b, c, 0xe5);
41 vector unsigned long long intended = { 0, 0 };
42 // Supposed to be a ? c: nand (b,c)
43 for (int l = 0; l < 2; l++)
44 {
45 for (int m = 0; m < 64; m++)
46 {
47 unsigned long long int bit_selector = (0x01ll << m);
48 if (a[l] & bit_selector)
49 intended [l] |= c [l] & bit_selector;
50 else if ((b [l] & c [l] & bit_selector) == 0)
51 intended [l] |= (0x01ll << m);
52 }
53 }
54 if (!vec_all_eq (result, intended))
55 abort ();
56 }
57 }
58
59 void doTests11110011 (vector unsigned long long int a_sources [],
60 vector unsigned long long int b_sources [],
61 vector unsigned long long int c_sources []) {
62 for (int i = 0; i < NumSamples; i++)
63 for (int j = 0; j < NumSamples; j++)
64 for (int k = 0; k < NumSamples; k++)
65 {
66 vector unsigned long long a = a_sources [i];
67 vector unsigned long long b = b_sources [j];
68 vector unsigned long long c = c_sources [k];
69 vector unsigned long long result = vec_ternarylogic (a, b, c, 0xfb);
70 vector unsigned long long intended = { 0, 0 };
71 intended [0] = b [0] | ~(a [0] & c [0]);
72 intended [1] = b [1] | ~(a [1] & c [1]);
73 if (!vec_all_eq (result, intended))
74 abort ();
75 }
76 }
77
78 int main (int argc, char *argv [])
79 {
80 vector unsigned long long int a_sources [NumSamples] = {
81 { 0x0123456789abcdef, 0x123456789abcdef0 },
82 { 0x5555555555555555, 0xffffffffffffffff },
83 { 0xcccccccc55555555, 0x0000000000000000 },
84 { 0xe7e7e7e7e7e7e7e7, 0x6969696969696969 },
85 };
86 vector unsigned long long int b_sources [NumSamples] = {
87 { 0x0123456789abcdef, 0x123456789abcdef0 },
88 { 0x5555555555555555, 0xffffffffffffffff },
89 { 0xcccccccc55555555, 0x0000000000000000 },
90 { 0xe7e7e7e7e7e7e7e7, 0x6969696969696969 },
91 };
92 vector unsigned long long int c_sources [NumSamples] = {
93 { 0x0123456789abcdef, 0x123456789abcdef0 },
94 { 0x5555555555555555, 0xffffffffffffffff },
95 { 0xcccccccc55555555, 0x0000000000000000 },
96 { 0xe7e7e7e7e7e7e7e7, 0x6969696969696969 },
97 };
98
99 doTests00000001 (a_sources, b_sources, c_sources);
100 doTests11100101 (a_sources, b_sources, c_sources);
101 doTests11110011 (a_sources, b_sources, c_sources);
102
103 return 0;
104 }