summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/builtins-2-p9-runnable.c
blob: 2f317077fcb26e13abaa27945888dd4281fad27f (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
/* { dg-do run { target { powerpc64*-*-* && { lp64 && p9vector_hw } } } } */
/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power9" } } */
/* { dg-require-effective-target powerpc_p9vector_ok } */
/* { dg-options "-mcpu=power9 -O2" } */

#include <altivec.h> // vector

void abort (void);

int main() {
  int i;
  vector int vsia;
  vector unsigned int vsir, vsiexpt;
  vector unsigned int vuia, vuir, vuiexpt;
  vector signed long long vslla;
  vector unsigned long long vsllr, vsllexpt;
  vector unsigned long long vulla, vullr, vullexpt;
  vector __int128_t  vs128a;
  vector __uint128_t vs128r, vs128expt;
  vector __uint128_t vu128a, vu128r, vu128expt;  

  /* Returns a vector with each element containing the parity of the low-order
     bit of each of the bytes in that element.  Note results are always
     returned in an unsinged type, per the ABI spec.  */
  vsia = (vector int) {0x10101010, 0x10101011, 0x10101111, 0x10111111};
  vsiexpt = (vector unsigned int){0x0, 0x1, 0x0, 0x1};

  vuia = (vector unsigned int) {0x000010000, 0x00010001,
				0x10100000, 0x000010101};
  vuiexpt = (vector unsigned int){0x1, 0x0, 0x0, 0x1};

  vslla = (vector long long) {0x0000000000010000,  0x0001000100010000};
  vsllexpt = (vector unsigned long long){0x1, 0x1};

  vulla = (vector unsigned long long)   {0x0000000000000001,
					 0x0001000000000001};
  vullexpt = (vector unsigned long long){0x1, 0x0};

  vs128a = (vector __int128_t) {0x0000000000001};
  vs128expt = (vector __uint128_t) {0x1};
  vu128a = (vector __uint128_t) {0x1000000000001};
  vu128expt = (vector __uint128_t) {0x0};

  vsir = vec_parity_lsbb(vsia);
  vuir = vec_parity_lsbb(vuia);
  vsllr = vec_parity_lsbb(vslla);
  vullr = vec_parity_lsbb(vulla);
  vs128r = vec_parity_lsbb(vs128a);
  vu128r = vec_parity_lsbb(vu128a);

  for(i = 0; i< 4; i++) {
    if (vsir[i] != vsiexpt[i])
      abort();

    if (vuir[i] != vuiexpt[i])
      abort();
  }

  for(i = 0; i< 2; i++) {
    if (vsllr[i] != vsllexpt[i])
      abort();

    if (vullr[i] != vullexpt[i])
      abort();
  }

  if (vs128r[0] != vs128expt[0])
    abort();

  if (vu128r[0] != vu128expt[0])
    abort();
}