File: altivec-1-runnable.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A8-2019-q3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 571,828 kB
  • sloc: ansic: 2,937,651; cpp: 881,644; ada: 597,189; makefile: 65,528; asm: 56,499; xml: 46,621; exp: 24,747; sh: 19,684; python: 7,256; pascal: 4,370; awk: 3,497; perl: 2,695; yacc: 316; ml: 285; f90: 234; lex: 198; objc: 194; haskell: 119
file content (257 lines) | stat: -rw-r--r-- 7,367 bytes parent folder | download | duplicates (2)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/* { dg-do compile { target powerpc*-*-* } } */
/* { dg-require-effective-target powerpc_altivec_ok } */
/* { dg-options "-maltivec" } */

#include <altivec.h>

#ifdef DEBUG
#include <stdio.h>
#endif

/* Endian considerations: The "high" half of a vector with n elements is the
   first n/2 elements of the vector. For little endian, these elements are in
   the rightmost half of the vector. For big endian, these elements are in the
   leftmost half of the vector.  */


void abort (void);

int main ()
{
  int i;
  vector bool short vec_bs_arg;
  vector bool short vec_bs_result, vec_bs_expected;
  vector bool int vec_bi_arg;
  vector bool int vec_bi_result, vec_bi_expected;
  vector bool char vec_bc_arg;
  vector bool char vec_bc_result, vec_bc_expected;
  vector signed short vec_ss_arg;
  vector signed short vec_ss_result, vec_ss_expected;
  vector signed int vec_si_arg;
  vector signed int vec_si_result, vec_si_expected;
  vector signed char vec_sc_arg;
  vector signed char vec_sc_result, vec_sc_expected;
  vector float vec_float_arg;
  vector double vec_double_result, vec_double_expected;
  vector pixel vec_pixel_arg;
  vector unsigned int vec_ui_result, vec_ui_expected;

  union conv {
	  double d;
	  unsigned long long l;
  } conv_exp, conv_val;

  vec_bs_arg = (vector bool short){ 0, 101, 202, 303,
				    404, 505, 606, 707 };
  vec_bi_expected = (vector bool int){ 0, 101, 202, 303 };

  vec_bi_result = vec_unpackh (vec_bs_arg);

  for (i = 0; i < 4; i++) {
    if (vec_bi_expected[i] != vec_bi_result[i])
#if DEBUG
       printf("ERROR: vec_unpackh(),  vec_bi_expected[%d] = %d does not match vec_bi_result[%d] = %d\n",
	      i, vec_bi_expected[i], i, vec_bi_result[i]);
#else
       abort();
#endif
  }

  vec_bi_expected = (vector bool int){ 404, 505, 606, 707 };
  vec_bi_result = vec_unpackl (vec_bs_arg);

  for (i = 0; i < 4; i++) {
    if (vec_bi_expected[i] != vec_bi_result[i])
#if DEBUG
       printf("ERROR: vec_unpackl(), vec_bi_expected[%d] = %d does not match vec_bi_result[%d] = %d\n",
	      i, vec_bi_expected[i], i, vec_bi_result[i]);
#else
       abort();
#endif
  }

  
  vec_ss_arg = (vector signed short){ 0, 101, 202, 303,
				    404, 505, 606, 707 };
  vec_si_expected = (vector signed int){ 0, 101, 202, 303 };

  vec_si_result = vec_unpackh (vec_ss_arg);

  for (i = 0; i < 4; i++) {
    if (vec_si_expected[i] != vec_si_result[i])
#if DEBUG
       printf("ERROR: vec_unpackh(), vec_si_expected[%d] = %d does not match vec_si_result[%d] = %d\n",
	      i, vec_si_expected[i], i, vec_si_result[i]);
#else
       abort();
#endif
  }

  vec_si_expected = (vector signed int){ 404, 505, 606, 707 };

  vec_si_result = vec_unpackl (vec_ss_arg);

  for (i = 0; i < 4; i++) {
    if (vec_si_expected[i] != vec_si_result[i])
#if DEBUG
       printf("ERROR: vec_unpackl(), vec_si_expected[%d] = %d does not match vec_si_result[%d] = %d\n",
	      i, vec_si_expected[i], i, vec_si_result[i]);
#else
       abort();
#endif
  }


  vec_pixel_arg = (vector pixel){ 0x0, 0x65, 0xca, 0x12f,
				  0x194, 0x1f9, 0x25e, 0x2c3 };
  vec_ui_expected = (vector unsigned int){ 0x0, 0x305, 0x60a, 0x90f };

  vec_ui_result = vec_unpackh (vec_pixel_arg);

  for (i = 0; i < 4; i++) {
    if (vec_ui_expected[i] != vec_ui_result[i])
#if DEBUG
       printf("ERROR: vec_unpackh(), vec_ui_expected[%d] = 0x%x does not match vec_ui_result[%d] = 0x%x\n",
	      i, vec_ui_expected[i], i, vec_ui_result[i]);
#else
       abort();
#endif
  }

  vec_ui_expected = (vector unsigned int){ 0xc14, 0xf19, 0x121e, 0x1603 };

  vec_ui_result = vec_unpackl (vec_pixel_arg);

  for (i = 0; i < 4; i++) {
    if (vec_ui_expected[i] != vec_ui_result[i])
#if DEBUG
       printf("ERROR: vec_unpackl(), vec_ui_expected[%d] = 0x%x does not match vec_ui_result[%d] = 0x%x\n",
	      i, vec_ui_expected[i], i, vec_ui_result[i]);
#else
       abort();
#endif
  }


  vec_bc_arg = (vector bool char){ 0, 1, 0, 1, 0, 1, 0, 1,
				   0, 0, 1, 1, 0, 0, 1, 1 };

  vec_bs_expected = (vector bool short){ 0, 1, 0, 1, 0, 1, 0, 1 };

  vec_bs_result = vec_unpackh (vec_bc_arg);

  for (i = 0; i < 8; i++) {
    if (vec_bs_expected[i] != vec_bs_result[i])
#if DEBUG
       printf("ERROR: vec_unpackh(), vec_bs_expected[%d] = %d does not match vec_bs_result[%d] = %d\n",
	      i, vec_bs_expected[i], i, vec_bs_result[i]);
#else
       abort();
#endif
  }

  vec_bs_expected = (vector bool short){ 0, 0, 1, 1, 0, 0, 1, 1 };

  vec_bs_result = vec_unpackl (vec_bc_arg);

  for (i = 0; i < 8; i++) {
    if (vec_bs_expected[i] != vec_bs_result[i])
#if DEBUG
       printf("ERROR: vec_unpackh(), vec_bs_expected[%d] = %d does not match vec_bs_result[%d] = %d\n",
	      i, vec_bs_expected[i], i, vec_bs_result[i]);
#else
       abort();
#endif
  }

  vec_bs_expected = (vector bool short){ 0, 0, 1, 1, 0, 0, 1, 1 };

  vec_bs_result = vec_unpackl (vec_bc_arg);

  for (i = 0; i < 8; i++) {
    if (vec_bs_expected[i] != vec_bs_result[i])
#if DEBUG
       printf("ERROR: vec_unpackl(), vec_bs_expected[%d] = %d does not match vec_bs_result[%d] = %d\n",
	      i, vec_bs_expected[i], i, vec_bs_result[i]);
#else
       abort();
#endif
  }


  vec_sc_arg = (vector signed char){ 0, 1, 2, 3, 4, 5, 6, 7,
				     8, 9, 10, 11, 12, 13, 14, 15 };

  vec_ss_expected = (vector signed short){ 0, 1, 2, 3, 4, 5, 6, 7 };

  vec_ss_result = vec_unpackh (vec_sc_arg);

  for (i = 0; i < 8; i++) {
    if (vec_ss_expected[i] != vec_ss_result[i])
#if DEBUG
       printf("ERROR: vec_unpackh(), vec_ss_expected[%d] = %d does not match vec_ss_result[%d] = %d\n",
	      i, vec_ss_expected[i], i, vec_ss_result[i]);
#else
       abort();
#endif
  }

  vec_ss_expected = (vector signed short){ 8, 9, 10, 11, 12, 13, 14, 15 };

  vec_ss_result = vec_unpackl (vec_sc_arg);

  for (i = 0; i < 8; i++) {
    if (vec_ss_expected[i] != vec_ss_result[i])
#if DEBUG
       printf("ERROR: vec_unpackl(), vec_ss_expected[%d] = %d does not match vec_ss_result[%d] = %d\n",
	      i, vec_ss_expected[i], i, vec_ss_result[i]);
#else
       abort();
#endif
  }
  

  vec_float_arg = (vector float){ 0.0, 1.5, 2.5, 3.5 };

  vec_double_expected = (vector double){ 0.0, 1.5 };

  vec_double_result = vec_unpackh (vec_float_arg);

  for (i = 0; i < 2; i++) {
    if (vec_double_expected[i] != vec_double_result[i])
      {
#if DEBUG
	 printf("ERROR: vec_unpackh(), vec_double_expected[%d] = %f does not match vec_double_result[%d] = %f\n",
		i, vec_double_expected[i], i, vec_double_result[i]);
	 conv_val.d = vec_double_result[i];
	 conv_exp.d = vec_double_expected[i];
	 printf("     vec_unpackh(), vec_double_expected[%d] = 0x%llx does not match vec_double_result[%d] = 0x%llx\n",
		i, conv_exp.l, i,conv_val.l);
#else
	 abort();
#endif
    }
  }

  vec_double_expected = (vector double){ 2.5, 3.5 };

  vec_double_result = vec_unpackl (vec_float_arg);

  for (i = 0; i < 2; i++) {
    if (vec_double_expected[i] != vec_double_result[i])
      {
#if DEBUG
         printf("ERROR: vec_unpackl() vec_double_expected[%d] = %f does not match vec_double_result[%d] = %f\n",
		i, vec_double_expected[i], i, vec_double_result[i]);
	 conv_val.d = vec_double_result[i];
	 conv_exp.d = vec_double_expected[i];
	 printf("     vec_unpackh(), vec_double_expected[%d] = 0x%llx does not match vec_double_result[%d] = 0x%llx\n",
		i, conv_exp.l, i,conv_val.l);
#else
         abort();
#endif
      }
  }

  return 0;
}