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