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