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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
/* { dg-do run } */
/* { dg-require-effective-target ssse3 } */
/* { dg-options "-O2 -fno-strict-aliasing -mssse3" } */
#ifndef CHECK_H
#define CHECK_H "ssse3-check.h"
#endif
#ifndef TEST
#define TEST ssse3_test
#endif
#include CHECK_H
#include "ssse3-vals.h"
#include <tmmintrin.h>
#include <string.h>
#ifndef __AVX__
/* Test the 64-bit form */
static void
ssse3_test_palignr (int *i1, int *i2, unsigned int imm, int *r)
{
__m64 t1 = *(__m64 *) i1;
__m64 t2 = *(__m64 *) i2;
switch (imm)
{
case 0:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 0);
break;
case 1:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 1);
break;
case 2:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 2);
break;
case 3:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 3);
break;
case 4:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 4);
break;
case 5:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 5);
break;
case 6:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 6);
break;
case 7:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 7);
break;
case 8:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 8);
break;
case 9:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 9);
break;
case 10:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 10);
break;
case 11:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 11);
break;
case 12:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 12);
break;
case 13:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 13);
break;
case 14:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 14);
break;
case 15:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 15);
break;
default:
*(__m64 *) r = _mm_alignr_pi8 (t1, t2, 16);
break;
}
_mm_empty();
}
#endif
/* Test the 128-bit form */
static void
ssse3_test_palignr128 (int *i1, int *i2, unsigned int imm, int *r)
{
/* Assumes incoming pointers are 16-byte aligned */
__m128i t1 = *(__m128i *) i1;
__m128i t2 = *(__m128i *) i2;
switch (imm)
{
case 0:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 0);
break;
case 1:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 1);
break;
case 2:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 2);
break;
case 3:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 3);
break;
case 4:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 4);
break;
case 5:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 5);
break;
case 6:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 6);
break;
case 7:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 7);
break;
case 8:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 8);
break;
case 9:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 9);
break;
case 10:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 10);
break;
case 11:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 11);
break;
case 12:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 12);
break;
case 13:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 13);
break;
case 14:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 14);
break;
case 15:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 15);
break;
case 16:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 16);
break;
case 17:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 17);
break;
case 18:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 18);
break;
case 19:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 19);
break;
case 20:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 20);
break;
case 21:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 21);
break;
case 22:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 22);
break;
case 23:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 23);
break;
case 24:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 24);
break;
case 25:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 25);
break;
case 26:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 26);
break;
case 27:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 27);
break;
case 28:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 28);
break;
case 29:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 29);
break;
case 30:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 30);
break;
case 31:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 31);
break;
default:
*(__m128i *) r = _mm_alignr_epi8 (t1, t2, 32);
break;
}
}
/* Routine to manually compute the results */
static void
compute_correct_result_128 (int *i1, int *i2, unsigned int imm, int *r)
{
char buf [32];
char *bout = (char *) r;
int i;
memcpy (&buf[0], i2, 16);
memcpy (&buf[16], i1, 16);
for (i = 0; i < 16; i++)
if (imm >= 32 || imm + i >= 32)
bout[i] = 0;
else
bout[i] = buf[imm + i];
}
#ifndef __AVX__
static void
compute_correct_result_64 (int *i1, int *i2, unsigned int imm, int *r)
{
char buf [16];
char *bout = (char *)r;
int i;
/* Handle the first half */
memcpy (&buf[0], i2, 8);
memcpy (&buf[8], i1, 8);
for (i = 0; i < 8; i++)
if (imm >= 16 || imm + i >= 16)
bout[i] = 0;
else
bout[i] = buf[imm + i];
/* Handle the second half */
memcpy (&buf[0], &i2[2], 8);
memcpy (&buf[8], &i1[2], 8);
for (i = 0; i < 8; i++)
if (imm >= 16 || imm + i >= 16)
bout[i + 8] = 0;
else
bout[i + 8] = buf[imm + i];
}
#endif
static void
TEST (void)
{
int i;
int r [4] __attribute__ ((aligned(16)));
int ck [4];
unsigned int imm;
int fail = 0;
for (i = 0; i < 256; i += 8)
for (imm = 0; imm < 100; imm++)
{
#ifndef __AVX__
/* Manually compute the result */
compute_correct_result_64 (&vals[i + 0], &vals[i + 4], imm, ck);
/* Run the 64-bit tests */
ssse3_test_palignr (&vals[i + 0], &vals[i + 4], imm, &r[0]);
ssse3_test_palignr (&vals[i + 2], &vals[i + 6], imm, &r[2]);
fail += chk_128 (ck, r);
#endif
/* Recompute the results for 128-bits */
compute_correct_result_128 (&vals[i + 0], &vals[i + 4], imm, ck);
/* Run the 128-bit tests */
ssse3_test_palignr128 (&vals[i + 0], &vals[i + 4], imm, r);
fail += chk_128 (ck, r);
}
if (fail != 0)
abort ();
}
|