1 /* { dg-do run } */
2 /* { dg-options "-O2 -mpower8-vector -Wno-psabi" } */
3 /* { dg-require-effective-target p8vector_hw } */
4
5 #define NO_WARN_X86_INTRINSICS 1
6 #ifndef CHECK_H
7 #define CHECK_H "sse4_1-check.h"
8 #endif
9
10 #ifndef TEST
11 #define TEST sse4_1_test
12 #endif
13
14 #include CHECK_H
15
16 #include <smmintrin.h>
17 #include <string.h>
18
19 #define NUM 20
20
21 #ifndef MASK
22 #define MASK 0x0f
23 #endif
24
25 static void
init_pblendw(short * src1,short * src2)26 init_pblendw (short *src1, short *src2)
27 {
28 int i, sign = 1;
29
30 for (i = 0; i < NUM * 8; i++)
31 {
32 src1[i] = i * i * sign;
33 src2[i] = (i + 20) * sign;
34 sign = -sign;
35 }
36 }
37
38 static int
check_pblendw(__m128i * dst,short * src1,short * src2)39 check_pblendw (__m128i *dst, short *src1, short *src2)
40 {
41 short tmp[8];
42 int j;
43
44 memcpy (&tmp[0], src1, sizeof (tmp));
45 for (j = 0; j < 8; j++)
46 if ((MASK & (1 << j)))
47 tmp[j] = src2[j];
48
49 return memcmp (dst, &tmp[0], sizeof (tmp));
50 }
51
52 static void
TEST(void)53 TEST (void)
54 {
55 __m128i x, y;
56 union
57 {
58 __m128i x[NUM];
59 short s[NUM * 8];
60 } dst, src1, src2;
61 union
62 {
63 __m128i x;
64 short s[8];
65 } src3;
66 int i;
67
68 init_pblendw (src1.s, src2.s);
69
70 /* Check pblendw imm8, m128, xmm */
71 for (i = 0; i < NUM; i++)
72 {
73 dst.x[i] = _mm_blend_epi16 (src1.x[i], src2.x[i], MASK);
74 if (check_pblendw (&dst.x[i], &src1.s[i * 8], &src2.s[i * 8]))
75 abort ();
76 }
77
78 /* Check pblendw imm8, xmm, xmm */
79 src3.x = _mm_setzero_si128 ();
80
81 x = _mm_blend_epi16 (dst.x[2], src3.x, MASK);
82 y = _mm_blend_epi16 (src3.x, dst.x[2], MASK);
83
84 if (check_pblendw (&x, &dst.s[16], &src3.s[0]))
85 abort ();
86
87 if (check_pblendw (&y, &src3.s[0], &dst.s[16]))
88 abort ();
89 }
90