summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/altivec-12.c
blob: 39d26940d4e36928d96d880f8bd86b4f6f0616af (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
/* { 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>

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

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 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));

  k = vec_avg (a1, a2);
  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;
}