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 #include <stdlib.h>
18
19 /* mingw runtime don't provide random(). */
20 #ifdef __MINGW32__
21 #define random rand
22 #endif
23
24 #define NUM 20
25
26 #ifndef MASK
27 #define MASK 0x0f
28 #endif
29
30 static void
init_blendps(float * src1,float * src2)31 init_blendps (float *src1, float *src2)
32 {
33 int i, sign = 1;
34
35 for (i = 0; i < NUM * 4; i++)
36 {
37 src1[i] = i * i * sign;
38 src2[i] = (i + 20) * sign;
39 sign = -sign;
40 }
41 }
42
43 static int
check_blendps(__m128 * dst,float * src1,float * src2)44 check_blendps (__m128 *dst, float *src1, float *src2)
45 {
46 float tmp[4];
47 int j;
48
49 memcpy (&tmp[0], src1, sizeof (tmp));
50 for (j = 0; j < 4; j++)
51 if ((MASK & (1 << j)))
52 tmp[j] = src2[j];
53
54 return memcmp (dst, &tmp[0], sizeof (tmp));
55 }
56
57 static void
TEST(void)58 TEST (void)
59 {
60 __m128 x, y;
61 union
62 {
63 __m128 x[NUM];
64 float f[NUM * 4];
65 } dst, src1, src2;
66 union
67 {
68 __m128 x;
69 float f[4];
70 } src3;
71 int i;
72
73 init_blendps (src1.f, src2.f);
74
75 for (i = 0; i < 4; i++)
76 src3.f[i] = (int) random ();
77
78 /* Check blendps imm8, m128, xmm */
79 for (i = 0; i < NUM; i++)
80 {
81 dst.x[i] = _mm_blend_ps (src1.x[i], src2.x[i], MASK);
82 if (check_blendps (&dst.x[i], &src1.f[i * 4], &src2.f[i * 4]))
83 abort ();
84 }
85
86 /* Check blendps imm8, xmm, xmm */
87 x = _mm_blend_ps (dst.x[2], src3.x, MASK);
88 y = _mm_blend_ps (src3.x, dst.x[2], MASK);
89
90 if (check_blendps (&x, &dst.f[8], &src3.f[0]))
91 abort ();
92
93 if (check_blendps (&y, &src3.f[0], &dst.f[8]))
94 abort ();
95 }
96