Debian Codegraph @

gcc/testsuite/gcc.dg/vect/vect-reduc-sad-1.c

raw
1 /* { dg-require-effective-target vect_int } */
2
3 #include "tree-vect.h"
4
5 #define N 50
6
7 #ifndef SIGNEDNESS_1
8 #define SIGNEDNESS_1 unsigned
9 #define SIGNEDNESS_2 unsigned
10 #define SIGNEDNESS_3 unsigned
11 #endif
12
13 SIGNEDNESS_1 int __attribute__ ((noipa))
14 f (SIGNEDNESS_1 int res, SIGNEDNESS_3 char *restrict a,
15 SIGNEDNESS_3 char *restrict b)
16 {
17 for (__INTPTR_TYPE__ i = 0; i < N; ++i)
18 {
19 int av = a[i];
20 int bv = b[i];
21 short diff = av - bv;
22 SIGNEDNESS_2 short abs = diff < 0 ? -diff : diff;
23 res += abs;
24 }
25 return res;
26 }
27
28 #define BASE1 ((SIGNEDNESS_3 int) -1 < 0 ? -126 : 4)
29 #define BASE2 ((SIGNEDNESS_3 int) -1 < 0 ? 116 : 220)
30
31 int
32 main (void)
33 {
34 check_vect ();
35
36 SIGNEDNESS_3 char a[N], b[N];
37 int expected = 0x12345;
38 for (int i = 0; i < N; ++i)
39 {
40 a[i] = BASE1 + i * 5;
41 b[i] = BASE1 - i * 4;
42 asm volatile ("" ::: "memory");
43 int diff = a[i] - b[i];
44 expected += (SIGNEDNESS_2 short) (diff < 0 ? -diff : diff);
45 }
46 if (f (0x12345, a, b) != expected)
47 __builtin_abort ();
48 }
49
50 /* { dg-final { scan-tree-dump "vect_recog_sad_pattern: detected" "vect" } } */
51 /* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" { target vect_sdot_qi } } } */