1/* { dg-do run } */
2/* { dg-options "-mavx512f -O2" } */
3/* { dg-require-effective-target avx512f } */
4
5#include "avx512f-check.h"
6
7#define SCALE 2
8
9static void
10compute_gatherdps (float *res, __mmask16 m16, int *idx,
11		   float *src, int scale, float *r)
12{
13  int i;
14
15  for (i = 0; i < 16; i++)
16    {
17      if (m16 & (1 << i))
18	r[i] = *(float *) (((unsigned char *) src) + idx[i] * scale);
19      else
20	r[i] = res[i];
21    }
22}
23
24static void
25avx512f_test (void)
26{
27  int i;
28  union512 res;
29  union512i_d idx;
30  float src[16];
31  float res_ref[16];
32  __mmask16 m16 = 0xBC5D;
33
34  res.x = _mm512_setzero_ps();
35
36  for (i = 0; i < 16; i++)
37    {
38      src[i] = 2.718281828459045 * (i + 1) * (i + 2);
39
40      /* About to gather in reverse order,
41	 divide by 2 to demonstrate scale */
42      idx.a[i] = (64 - (i + 1) * 4) >> 1;
43    }
44
45  res.x = _mm512_mask_i32gather_ps (res.x, m16, idx.x, src, SCALE);
46  compute_gatherdps (res.a, m16, idx.a, src, SCALE, res_ref);
47
48  if (check_union512 (res, res_ref))
49    abort ();
50
51  res.x = _mm512_i32gather_ps (idx.x, src, SCALE);
52  compute_gatherdps (res.a, 0xFFFF, idx.a, src, SCALE, res_ref);
53
54  if (check_union512 (res, res_ref))
55    abort ();
56}
57