2015-12-10 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / sse4_1-blendps.c
blob3f4b335aca6ae205ad4d3c857eaf8f3eb72afba4
1 /* { dg-do run } */
2 /* { dg-require-effective-target sse4 } */
3 /* { dg-options "-O2 -msse4.1" } */
5 #ifndef CHECK_H
6 #define CHECK_H "sse4_1-check.h"
7 #endif
9 #ifndef TEST
10 #define TEST sse4_1_test
11 #endif
13 #include CHECK_H
15 #include <smmintrin.h>
16 #include <string.h>
17 #include <stdlib.h>
19 /* mingw runtime don't provide random(). */
20 #ifdef __MINGW32__
21 #define random rand
22 #endif
24 #define NUM 20
26 #ifndef MASK
27 #define MASK 0x0f
28 #endif
30 static void
31 init_blendps (float *src1, float *src2)
33 int i, sign = 1;
35 for (i = 0; i < NUM * 4; i++)
37 src1[i] = i * i * sign;
38 src2[i] = (i + 20) * sign;
39 sign = -sign;
43 static int
44 check_blendps (__m128 *dst, float *src1, float *src2)
46 float tmp[4];
47 int j;
49 memcpy (&tmp[0], src1, sizeof (tmp));
50 for (j = 0; j < 4; j++)
51 if ((MASK & (1 << j)))
52 tmp[j] = src2[j];
54 return memcmp (dst, &tmp[0], sizeof (tmp));
57 static void
58 TEST (void)
60 __m128 x, y;
61 union
63 __m128 x[NUM];
64 float f[NUM * 4];
65 } dst, src1, src2;
66 union
68 __m128 x;
69 float f[4];
70 } src3;
71 int i;
73 init_blendps (src1.f, src2.f);
75 for (i = 0; i < 4; i++)
76 src3.f[i] = (int) random ();
78 /* Check blendps imm8, m128, xmm */
79 for (i = 0; i < NUM; i++)
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 ();
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);
90 if (check_blendps (&x, &dst.f[8], &src3.f[0]))
91 abort ();
93 if (check_blendps (&y, &src3.f[0], &dst.f[8]))
94 abort ();