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