summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/vec-ternarylogic-8.c
blob: 0d6b9e742393206fc7008969cfeb54dec005ed14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* { dg-do compile } */
/* { dg-options "-mdejagnu-cpu=future" } */

#include <altivec.h>

extern void abort (void);

#define NumSamples 4

/* vec_all_eq not yet supported for arguments of type
   vector unsigned __int128.  */
int
vector_equal (vector unsigned __int128 a, vector unsigned __int128 b)
{
  return a[0] == b[0];
}

void
doTests00000001 (vector unsigned __int128 a_sources [],
		 vector unsigned __int128 b_sources [],
		 vector unsigned __int128 c_sources []) {
  for (int i = 0; i < NumSamples; i++)
    for (int j = 0; j < NumSamples; j++)
      for (int k = 0; k < NumSamples; k++)
	{
	  vector unsigned __int128 a = a_sources [i];
	  vector unsigned __int128 b = b_sources [j];
	  vector unsigned __int128 c = c_sources [k];
	  vector unsigned __int128 result = vec_ternarylogic (a, b, c, 0x01);
	  vector unsigned __int128 intended = (a & b & c);
	  if (!vector_equal (result, intended))
	    abort ();
	}
}

void
doTests11100101 (vector unsigned __int128 a_sources [],
		 vector unsigned __int128 b_sources [],
		 vector unsigned __int128 c_sources []) {
  for (int i = 0; i < NumSamples; i++)
    for (int j = 0; j < NumSamples; j++)
      for (int k = 0; k < NumSamples; k++)
	{
	  vector unsigned __int128 a = a_sources [i];
	  vector unsigned __int128 b = b_sources [j];
	  vector unsigned __int128 c = c_sources [k];
	  vector unsigned __int128 result = vec_ternarylogic (a, b, c, 0xe5);
	  vector unsigned __int128 intended = { 0 };
	  // Supposed to be a ? c: nand (b,c)
	  for (int l = 0; l < 1; l++)
	    {
	      for (int m = 0; m < 128; m++)
	      {
		unsigned __int128 bit_selector = 0x01;
		bit_selector = bit_selector << m;

		if (a[l] & bit_selector)
		  intended [l] |= c [l] & bit_selector;
		else if ((b [l] & c [l] & bit_selector) == 0)
		  intended [l] |= bit_selector;
	      }
	    }
	  if (!vector_equal (result, intended))
	    abort ();
	}
}

void
doTests11110011 (vector unsigned __int128 a_sources [],
		 vector unsigned __int128 b_sources [],
		 vector unsigned __int128 c_sources []) {
  for (int i = 0; i < NumSamples; i++)
    for (int j = 0; j < NumSamples; j++)
      for (int k = 0; k < NumSamples; k++)
	{
	  vector unsigned __int128 a = a_sources [i];
	  vector unsigned __int128 b = b_sources [j];
	  vector unsigned __int128 c = c_sources [k];
	  vector unsigned __int128 result = vec_ternarylogic (a, b, c, 0xfb);
	  vector unsigned __int128 intended = { 0 };
	  for (int i = 0; i < 1; i++)
	    intended [i] = b [i] | ~(a [i] & c [i]);
	  if (!vector_equal (result, intended))
	    abort ();
	}
}

int main (int argc, int *argv [])
{
  vector unsigned __int128 a_sources [NumSamples];
  vector unsigned __int128 b_sources [NumSamples];
  vector unsigned __int128 c_sources [NumSamples];

  a_sources [0][0] = 0x0123456789abcdefull;
  a_sources [0][0] = a_sources [0][0] << 64 | 0x123456789abcdef0ull;
  a_sources [1][0] = 0x5555555555555555ull;
  a_sources [1][0] = a_sources [1][0] << 64 | 0xffffffffffffffffull;
  a_sources [2][0] = 0xcccccccc55555555ull;
  a_sources [2][0] = a_sources [2][0] << 64 | 0x0000000000000000ull;
  a_sources [3][0] = 0xe7e7e7e7e7e7e7e7ull;
  a_sources [3][0] = a_sources [3][0] << 64 | 0x6969696969696969ull;

  b_sources [0][0] = 0x0123456789abcdefull;
  b_sources [0][0] = b_sources [0][0] << 64 | 0x123456789abcdef0ull;
  b_sources [1][0] = 0x5555555555555555ull;
  b_sources [1][0] = b_sources [1][0] << 64 | 0xffffffffffffffffull;
  b_sources [2][0] = 0xcccccccc55555555ull;
  b_sources [2][0] = b_sources [2][0] << 64 | 0x0000000000000000ull;
  b_sources [3][0] = 0xe7e7e7e7e7e7e7e7ull;
  b_sources [3][0] = b_sources [3][0] << 64 | 0x6969696969696969ull;

  c_sources [0][0] = 0x0123456789abcdefull;
  c_sources [0][0] = c_sources [0][0] << 64 | 0x123456789abcdef0ull;
  c_sources [1][0] = 0x5555555555555555ull;
  c_sources [1][0] = c_sources [1][0] << 64 | 0xffffffffffffffffull;
  c_sources [2][0] = 0xcccccccc55555555ull;
  c_sources [2][0] = c_sources [2][0] << 64 | 0x0000000000000000ull;
  c_sources [3][0] = 0xe7e7e7e7e7e7e7e7ull;
  c_sources [3][0] = c_sources [3][0] << 64 | 0x6969696969696969ull;

  doTests00000001 (a_sources, b_sources, c_sources);
  doTests11100101 (a_sources, b_sources, c_sources);
  doTests11110011 (a_sources, b_sources, c_sources);

  return 0;
}

/* { dg-final { scan-assembler {\mxxeval\M} } } */