1 /* { dg-do run } */
2 /* { dg-options "-O3 -mpower8-vector -Wno-psabi" } */
3 /* { dg-require-effective-target p8vector_hw } */
4
5 #ifndef CHECK_H
6 #define CHECK_H "ssse3-check.h"
7 #endif
8
9 #ifndef TEST
10 #define TEST ssse3_test
11 #endif
12
13 #include CHECK_H
14
15 #include "ssse3-vals.h"
16
17 #include <tmmintrin.h>
18
19 #ifndef __AVX__
20 /* Test the 64-bit form */
21 static void
ssse3_test_pshufb(__m64 * i1,__m64 * i2,__m64 * r)22 ssse3_test_pshufb (__m64 *i1, __m64 *i2, __m64 *r)
23 {
24 *r = _mm_shuffle_pi8 (*i1, *i2);
25 _mm_empty ();
26 }
27 #endif
28
29 /* Test the 128-bit form */
30 static void
ssse3_test_pshufb128(__m128i * i1,__m128i * i2,__m128i * r)31 ssse3_test_pshufb128 (__m128i *i1, __m128i *i2, __m128i *r)
32 {
33 /* Assumes incoming pointers are 16-byte aligned */
34 *r = _mm_shuffle_epi8 (*i1, *i2);
35 }
36
37 #ifndef __AVX__
38 /* Routine to manually compute the results */
39 static void
compute_correct_result_64(signed char * i1,signed char * i2,signed char * r)40 compute_correct_result_64 (signed char *i1, signed char *i2, signed char *r)
41 {
42 int i;
43 char select;
44
45 for (i = 0; i < 16; i++)
46 {
47 select = i2[i];
48 if (select & 0x80)
49 r[i] = 0;
50 else if (i < 8)
51 r[i] = i1[select & 0x7];
52 else
53 r[i] = i1[8 + (select & 0x7)];
54 }
55 }
56 #endif
57
58 static void
compute_correct_result_128(signed char * i1,signed char * i2,signed char * r)59 compute_correct_result_128 (signed char *i1, signed char *i2, signed char *r)
60 {
61 int i;
62 char select;
63
64 for (i = 0; i < 16; i++)
65 {
66 select = i2[i];
67 if (select & 0x80)
68 r[i] = 0;
69 else
70 r[i] = i1[select & 0xf];
71 }
72 }
73
74 static void
TEST(void)75 TEST (void)
76 {
77 int i;
78 union data r __attribute__ ((aligned(16)));
79 union data ck;
80 int fail = 0;
81
82 for (i = 0; i < ARRAY_SIZE (vals) - 1; i++)
83 {
84 #ifndef __AVX__
85 /* Manually compute the result */
86 compute_correct_result_64 (&vals[i + 0].b[0], &vals[i + 1].b[0], &ck.b[0]);
87
88 /* Run the 64-bit tests */
89 ssse3_test_pshufb (&vals[i + 0].ll[0], &vals[i + 1].ll[0], &r.ll[0]);
90 ssse3_test_pshufb (&vals[i + 0].ll[1], &vals[i + 1].ll[1], &r.ll[1]);
91 fail += chk_128 (ck.m[0], r.m[0]);
92 #endif
93
94 /* Recompute the result for 128-bits */
95 compute_correct_result_128 (&vals[i + 0].b[0], &vals[i + 1].b[0], &ck.b[0]);
96
97 /* Run the 128-bit tests */
98 ssse3_test_pshufb128 (&vals[i + 0].m[0], &vals[i + 1].m[0], &r.m[0]);
99 fail += chk_128 (ck.m[0], r.m[0]);
100 }
101
102 if (fail != 0)
103 abort ();
104 }
105