libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-reduc-sad-1.c
blob73a83b8faacf524a4dd3434b714264c65db4939f
1 /* { dg-require-effective-target vect_int } */
3 #include "tree-vect.h"
5 #define N 50
7 #ifndef SIGNEDNESS_1
8 #define SIGNEDNESS_1 unsigned
9 #define SIGNEDNESS_2 unsigned
10 #define SIGNEDNESS_3 unsigned
11 #endif
13 SIGNEDNESS_1 int __attribute__ ((noipa))
14 f (SIGNEDNESS_1 int res, SIGNEDNESS_3 char *restrict a,
15 SIGNEDNESS_3 char *restrict b)
17 for (__INTPTR_TYPE__ i = 0; i < N; ++i)
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;
25 return res;
28 #define BASE1 ((SIGNEDNESS_3 int) -1 < 0 ? -126 : 4)
29 #define BASE2 ((SIGNEDNESS_3 int) -1 < 0 ? 116 : 220)
31 int
32 main (void)
34 check_vect ();
36 SIGNEDNESS_3 char a[N], b[N];
37 int expected = 0x12345;
38 for (int i = 0; i < N; ++i)
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);
46 if (f (0x12345, a, b) != expected)
47 __builtin_abort ();
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 } } } */