1 /* { dg-do run } */
2 /* { dg-require-effective-target avx2 } */
3 /* { dg-options "-O2 -mavx2" } */
4
5 #include <string.h>
6 #include "avx2-check.h"
7
8 static void
compute_i32gatherps(float * src,float * s1,int * s2,float * mask,int scale,float * r)9 compute_i32gatherps (float *src,
10 float *s1, int *s2, float *mask, int scale, float *r)
11 {
12 int i;
13
14 for (i = 0; i < 4; ++i)
15 if ((((int *) mask)[i] >> 31) & 1)
16 r[i] = *(float *) (((unsigned char *) s1) + s2[i] * scale);
17 else
18 r[i] = src[i];
19 }
20
21 void static
avx2_test(void)22 avx2_test (void)
23 {
24 int i;
25 union128i_d idx;
26 union128 res, src, mask;
27 float s1[4], res_ref[4] = { 0 };
28
29 for (i = 0; i < 4; ++i)
30 {
31 /* Set some stuff */
32 s1[i] = 2.718281828459045 * (i + 1) * (i + 2);
33
34 /* Set src as something different from s1 */
35 src.a[i] = -s1[i];
36
37 /* Mask out evens */
38 ((int *) mask.a)[i] = i % 2 ? 0 : -1;
39
40 /* About to gather in reverse order,
41 divide by 2 to demonstrate scale */
42 idx.a[i] = (16 - (i + 1) * 4) >> 1;
43 }
44
45 res.x = _mm_mask_i32gather_ps (src.x, s1, idx.x, mask.x, 2);
46
47 compute_i32gatherps (src.a, s1, idx.a, mask.a, 2, res_ref);
48
49 if (check_union128 (res, res_ref) != 0)
50 abort ();
51 }
52