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_sadbw256(unsigned char * s1,unsigned char * s2,unsigned short * r)9 compute_sadbw256 (unsigned char *s1, unsigned char *s2, unsigned short *r)
10 {
11 int i;
12 unsigned char tmp[32];
13
14 for (i = 0; i < 32; i++)
15 tmp[i] = s1[i] > s2[i] ? s1[i] - s2[i] : s2[i] - s1[i];
16
17 memset (r, 0, 32);
18
19 for (i = 0; i < 8; i++)
20 r[0] += tmp[i];
21
22 for (i = 8; i < 16; i++)
23 r[4] += tmp[i];
24
25 for (i = 16; i < 24; i++)
26 r[8] += tmp[i];
27
28 for (i = 24; i < 32; i++)
29 r[12] += tmp[i];
30 }
31
32 void static
avx2_test(void)33 avx2_test (void)
34 {
35 union256i_b s1, s2;
36 union256i_w res;
37 unsigned short res_ref[16];
38 int i, j;
39 int fail = 0;
40
41 for (i = 0; i < 10; i++)
42 {
43 for (j = 0; j < 32; j++)
44 {
45 s1.a[j] = j * i;
46 s2.a[j] = j + 20;
47 }
48
49 res.x = _mm256_sad_epu8 (s1.x, s2.x);;
50 compute_sadbw256 (s1.a, s2.a, res_ref);
51
52 fail += check_union256i_w (res, res_ref);
53 }
54
55 if (fail != 0)
56 abort ();
57 }
58