summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/vec-ternarylogic-5.c
blob: 4d5d8e5e0d6a0776fc389ef47cc078a693a33e37 (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
/* { dg-do run } */
/* { dg-require-effective-target powerpc_future_hw } */
/* { dg-options "-mdejagnu-cpu=future" } */

#include <altivec.h>

extern void abort (void);

#define NumSamples 4

void
doTests00000001 (vector unsigned int a_sources [],
		 vector unsigned int b_sources [],
		 vector unsigned int 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 int a = a_sources [i];
	  vector unsigned int b = b_sources [j];
	  vector unsigned int c = c_sources [k];
	  vector unsigned int result = vec_ternarylogic (a, b, c, 0x01);
	  vector unsigned int intended = (a & b & c);
	  if (!vec_all_eq (result, intended))
	    abort ();
	}
}

void doTests11100101 (vector unsigned int a_sources [],
		      vector unsigned int b_sources [],
		      vector unsigned int 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 int a = a_sources [i];
	  vector unsigned int b = b_sources [j];
	  vector unsigned int c = c_sources [k];
	  vector unsigned int result = vec_ternarylogic (a, b, c, 0xe5);
	  vector unsigned int intended = { 0, 0, 0, 0 };
	  // Supposed to be a ? c: nand (b,c)
	  for (int l = 0; l < 4; l++)
	    {
	      for (int m = 0; m < 32; m++)
	      {
		unsigned int bit_selector = (0x01 << 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 (!vec_all_eq (result, intended))
	    abort ();
	}
}

void doTests11110011 (vector unsigned int a_sources [],
		      vector unsigned int b_sources [],
		      vector unsigned int 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 int a = a_sources [i];
	  vector unsigned int b = b_sources [j];
	  vector unsigned int c = c_sources [k];
	  vector unsigned int result = vec_ternarylogic (a, b, c, 0xfb);
	  vector unsigned int intended = { 0, 0, 0, 0 };
	  for (int i = 0; i < 4; i++)
	    intended [i] = b [i] | ~(a [i] & c [i]);
	  if (!vec_all_eq (result, intended))
	    abort ();
	}
}

int main (int argc, int *argv [])
{
  vector unsigned int a_sources [NumSamples] = {
    { 0x01234567, 0x89abcdef, 0x12345678, 0x9abcdef0 },
    { 0x55555555, 0x55555555, 0xffffffff, 0xffffffff },
    { 0xcccccccc, 0x55555555, 0x00000000, 0x00000000 },
    { 0xe7e7e7e7, 0xe7e7e7e7, 0x69696969, 0x69696969 },
  };
  vector unsigned int b_sources [NumSamples] = {
    { 0x01234567, 0x89abcdef, 0x12345678, 0x9abcdef0 },
    { 0x55555555, 0x55555555, 0xffffffff, 0xffffffff },
    { 0xcccccccc, 0x55555555, 0x00000000, 0x00000000 },
    { 0xe7e7e7e7, 0xe7e7e7e7, 0x69696969, 0x69696969 },
  };
  vector unsigned int c_sources [NumSamples] = {
    { 0x01234567, 0x89abcdef, 0x12345678, 0x9abcdef0 },
    { 0x55555555, 0x55555555, 0xffffffff, 0xffffffff },
    { 0xcccccccc, 0x55555555, 0x00000000, 0x00000000 },
    { 0xe7e7e7e7, 0xe7e7e7e7, 0x69696969, 0x69696969 },
  };

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

  return 0;
}