summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ext/altivec-cell-2.C
blob: f0d3433cdd99fd87fb6e987a404dee290fce335d (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
140
141
/* { dg-do run { target { powerpc*-*-* && vmx_hw } } } */
/* { dg-do compile { target { powerpc*-*-* && { ! vmx_hw } } } } */
/* { dg-require-effective-target powerpc_altivec_ok } */
/* { dg-options "-maltivec" } */
/* Test the vec_extract VMX intrinsics.  */
#include <altivec.h>

extern "C" void abort (void);

vector int a = {0, 1, 2, 3};
vector short b = {0, 1, 2, 3, 4, 5, 6, 7};

int f(vector int a, int b)
{
  return vec_extract (a, b);
}

int f0 (vector int a)
{
  return vec_extract (a, 0);
}
int f1 (vector int a)
{
  return vec_extract (a, 1);
}
int f2 (vector int a)
{
  return vec_extract (a, 2);
}
int f3 (vector int a)
{
  return vec_extract (a, 3);
}
int f4 (vector int a)
{
  return vec_extract (a, 4);
}

int g(vector short a, int b)
{
  return vec_extract (a, b);
}

int g0 (vector short a)
{
  return vec_extract (a, 0);
}
int g1 (vector short a)
{
  return vec_extract (a, 1);
}
int g2 (vector short a)
{
  return vec_extract (a, 2);
}
int g3 (vector short a)
{
  return vec_extract (a, 3);
}

int g4 (vector short a)
{ 
  return vec_extract (a, 4);
}
int g5 (vector short a)
{ 
  return vec_extract (a, 5);
}
int g6 (vector short a)
{ 
  return vec_extract (a, 6);
}
int g7 (vector short a)
{ 
  return vec_extract (a, 7);
}
int g8 (vector short a)
{ 
  return vec_extract (a, 8);
}
int main1(void) __attribute__((noinline));
int main1(void)
{ 
  int i;
  /* Check vec_extract with a non constant element numbering */
  for(i=0;i<10;i++)
    { 
      if (f(a, i) != (i&0x3))
        abort ();
    }
  
  /* Check vec_extract with a constant element numbering */
  if (f0(a) != 0)
    abort ();
  if (f1(a) != 1)
    abort ();
  if (f2(a) != 2)
    abort ();
  if (f3(a) != 3)
    abort ();
  /* Check that vec_extract works with a constant element higher than
     the number of elements.  */
  if (f4(a) != 0)
    abort ();

  /* Check vec_extract with a non constant element numbering */
  for(i=0;i<10;i++)
    {
      if (g(b, i) != (i&0x7))
        abort ();
    }
  
  /* Check vec_extract with a constant element numbering */
  if (g0(b) != 0)
    abort ();
  if (g1(b) != 1)
    abort ();
  if (g2(b) != 2)
    abort ();
  if (g3(b) != 3)
    abort ();
  if (g4(b) != 4)
    abort ();
  if (g5(b) != 5)
    abort ();
  if (g6(b) != 6)
    abort ();
  if (g7(b) != 7)
    abort ();
  /* Check that vec_extract works with a constant element higher than
     the number of elements.  */
  if (g8(b) != 0)
    abort ();
  
  return 0;
}

int main(void)
{ 
  return main1 ();
}