aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/altivec-12.c
blob: b0267b59b84d09af38f84c9028d709c7069a1f21 (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
129
130
131
132
133
134
135
136
137
138
139
/* { dg-do run { target { powerpc*-*-* && vmx_hw } } } */
/* { dg-do compile { target { powerpc*-*-* && { ! vmx_hw } } } } */
/* { dg-require-effective-target powerpc_altivec_ok } */
/* { dg-options "-maltivec" } */

/* Program to test PowerPC AltiVec instructions.  */

#include <altivec.h>
#include <stdio.h>

extern void abort (void);
#define CHECK_IF(E) if(!(E)) abort()

vector char sca = {0,4,8,1,5,9,2,6,10,3,7,11,15,12,14,13};
vector char scb = {6,4,8,3,1,9,2,6,10,3,7,11,15,12,14,13};
vector char sc_expected = {3,4,8,2,3,9,2,6,10,3,7,11,15,12,14,13};
vector char scz;
vector unsigned char uca = {0,4,8,1,5,9,2,6,10,3,7,11,15,12,14,13};
vector unsigned char ucb = {6,4,8,3,1,9,2,6,10,3,7,11,15,12,14,13};
vector unsigned char uc_expected = {3,4,8,2,3,9,2,6,10,3,7,11,15,12,14,13};
vector char ucz;

vector short int ssia = {9, 16, 25, 36};
vector short int ssib = {-8, -27, -64, -125};
vector short int ssiz;

vector short unsigned int ssua = {9, 16, 25, 36};
vector short unsigned int ssub = {8, 27, 64, 125};
vector short unsigned int ssuz;

vector unsigned int uia = {22, 13, 24, 39};
vector unsigned int uib = {8, 7, 4, 15};
vector unsigned int ui_expected = {15, 10, 14, 27};
vector unsigned int uiz;

vector int a1 = (vector int){ 100, 200, 300, 400 };
vector int a2 = (vector int){ 500, 600, 700, 800 };
vector int addi = (vector int){ 600, 800, 1000, 1200 };
vector int avgi = (vector int){ 300, 400, 500, 600 };

vector float f1 = (vector float){ 1.0, 2.0, 3.0, 4.0 };
vector float f2 = (vector float){ 5.0, 6.0, 7.0, 8.0 };
vector float f3;
vector float addf1 = (vector float){ 6.0, 8.0, 10.0, 12.0 };
vector float addf2 = (vector float){ 6.1, 8.1, 10.1, 12.1 };
vector float addf3 = (vector float){ 6.0, 8.0, 9.9, 12.1 };
vector int k;
vector float f, g, h;

int i;

int main ()
{

  k = vec_add (a1, a2);
  CHECK_IF (vec_all_eq (addi, k));
  CHECK_IF (vec_all_ge (addi, k));
  CHECK_IF (vec_all_le (addi, k));
  CHECK_IF (vec_any_eq (addi, k));
  CHECK_IF (vec_any_ge (addi, k));
  CHECK_IF (vec_any_le (addi, k));
  CHECK_IF (!vec_any_ne (addi, k));
  CHECK_IF (!vec_any_lt (addi, k));
  CHECK_IF (!vec_any_gt (addi, k));
  CHECK_IF (!vec_any_ne (addi, k));
  CHECK_IF (!vec_any_lt (addi, k));
  CHECK_IF (!vec_any_gt (addi, k));

  ssiz = vec_avg (ssia, ssib);
  ssuz = vec_avg (ssua, ssub);
  k = vec_avg (a1, a2);
  scz = vec_avg (sca, scb);

  for (i=0; i< 16; i++)
    if (scz[i] != sc_expected[i])
      abort ();
  
  ucz = vec_avg (uca, ucb);

  for (i=0; i<16; i++)
    if (ucz[i] != uc_expected[i])
      abort ();
  
  uiz = vec_avg (uia, uib);

  for (i=0; i< 4; i++)
    if (uiz[i] != ui_expected[i])
      abort ();
  
  CHECK_IF (vec_all_eq (k, avgi));

  h = vec_add (f1, f2);
  CHECK_IF (vec_all_eq (h, addf1));
  CHECK_IF (vec_all_ge (h, addf1));
  CHECK_IF (vec_all_le (h, addf1));
  CHECK_IF (vec_any_eq (h, addf1));
  CHECK_IF (vec_any_ge (h, addf1));
  CHECK_IF (vec_any_le (h, addf1));
  CHECK_IF (!vec_any_ne (h, addf1));
  CHECK_IF (!vec_any_lt (h, addf1));
  CHECK_IF (!vec_any_gt (h, addf1));
  CHECK_IF (!vec_any_ne (h, addf1));
  CHECK_IF (!vec_any_lt (h, addf1));
  CHECK_IF (!vec_any_gt (h, addf1));

  CHECK_IF (vec_all_gt (addf2, addf1));
  CHECK_IF (vec_any_gt (addf2, addf1));
  CHECK_IF (vec_all_ge (addf2, addf1));
  CHECK_IF (vec_any_ge (addf2, addf1));
  CHECK_IF (vec_all_ne (addf2, addf1));
  CHECK_IF (vec_any_ne (addf2, addf1));
  CHECK_IF (!vec_all_lt (addf2, addf1));
  CHECK_IF (!vec_any_lt (addf2, addf1));
  CHECK_IF (!vec_all_le (addf2, addf1));
  CHECK_IF (!vec_any_le (addf2, addf1));
  CHECK_IF (!vec_all_eq (addf2, addf1));
  CHECK_IF (!vec_any_eq (addf2, addf1));

  CHECK_IF (vec_any_eq (addf3, addf1));
  CHECK_IF (vec_any_ne (addf3, addf1));
  CHECK_IF (vec_any_lt (addf3, addf1));
  CHECK_IF (vec_any_le (addf3, addf1));
  CHECK_IF (vec_any_gt (addf3, addf1));
  CHECK_IF (vec_any_ge (addf3, addf1));
  CHECK_IF (!vec_all_eq (addf3, addf1));
  CHECK_IF (!vec_all_ne (addf3, addf1));
  CHECK_IF (!vec_all_lt (addf3, addf1));
  CHECK_IF (!vec_all_le (addf3, addf1));
  CHECK_IF (!vec_all_gt (addf3, addf1));
  CHECK_IF (!vec_all_ge (addf3, addf1));

  CHECK_IF (vec_all_numeric (addf3));
  CHECK_IF (vec_all_in (addf1, addf2));

  CHECK_IF (vec_step (vector bool char) == 16);
  CHECK_IF (vec_step (addf3) == 4);

  return 0;
}