summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/i386/avx512bw-vdbpsadbw-2.c
blob: fd81dbaa33d71cffd7c9ba81ba2f930e3679c1e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* { dg-do run } */
/* { dg-options "-O2 -mavx512bw" } */
/* { dg-require-effective-target avx512bw } */

#define AVX512BW
#include "avx512f-helper.h"

#define SIZE (AVX512F_LEN / 16)
#include "avx512f-mask-type.h"

void
CALC (unsigned short *dst, unsigned char *src1, unsigned char *src2,
      int imm)
{
  int i, j, k, part, power;
  unsigned char tmp[2 * SIZE];;

  for (i = 0; i < 2 * SIZE; i += 16)
    {
      for (j = 0; j < 4; j++)
	{
	  power = 1;
	  for (k = 0; k < j; k++)
	    power *= 4;
	  part = (imm & (3 * power)) >> (2 * j);
	  for (k = 0; k < 4; k++)
	    tmp[i + 4 * j + k] = src2[i + 4 * part + k];
	}
    }

  for (i = 0; i < SIZE; i += 4)
    {
      dst[i] = dst[i + 1] = dst[i + 2] = dst[i + 3] = 0;
      for (j = 0; j < 4; j++)
	{
	  dst[i] += abs (src1[2 * i + j] - tmp[2 * i + j]);
	  dst[i + 1] += abs (src1[2 * i + j] - tmp[2 * i + j + 1]);
	  dst[i + 2] += abs (src1[2 * i + j + 4] - tmp[2 * i + j + 2]);
	  dst[i + 3] += abs (src1[2 * i + j + 4] - tmp[2 * i + j + 3]);
	}
    }
}

void
TEST (void)
{
  int i, sign;
  UNION_TYPE (AVX512F_LEN, i_w) res1, res2, res3;
  UNION_TYPE (AVX512F_LEN, i_b) src1, src2;
  MASK_TYPE mask = MASK_VALUE;
  unsigned short res_ref[SIZE];
  int imm = 0x22;

  sign = -1;
  for (i = 0; i < 2*SIZE; i++)
    {
      src1.a[i] = 1 + 34 * i * sign;
      src1.a[i] = 179 - i;
      sign = sign * -1;
    }

  for (i = 0; i < SIZE; i++)
      res2.a[i] = DEFAULT_VALUE;

  res1.x = INTRINSIC (_dbsad_epu8) (src1.x, src2.x, imm);
  res2.x = INTRINSIC (_mask_dbsad_epu8) (res2.x, mask, src1.x, src2.x, imm);
  res3.x = INTRINSIC (_maskz_dbsad_epu8) (mask, src1.x, src2.x, imm);

  CALC (res_ref, src1.a, src2.a, imm);

  if (UNION_CHECK (AVX512F_LEN, i_w) (res1, res_ref))
    abort ();

  MASK_MERGE (i_w) (res_ref, mask, SIZE);
  if (UNION_CHECK (AVX512F_LEN, i_w) (res2, res_ref))
    abort ();

  MASK_ZERO (i_w) (res_ref, mask, SIZE);
  if (UNION_CHECK (AVX512F_LEN, i_w) (res3, res_ref))
    abort ();
}