1 /* { dg-require-effective-target vect_usad_char } */
2 
3 #include <stdarg.h>
4 #include "tree-vect.h"
5 
6 #define N 64
7 #define SAD N*N/2
8 
9 unsigned char X[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__)));
10 unsigned char Y[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__)));
11 int abs (int);
12 
13 /* Sum of absolute differences between arrays of unsigned char types.
14    Detected as a sad pattern.
15    Vectorized on targets that support sad for unsigned chars.  */
16 
17 __attribute__ ((noinline)) int
foo(int len)18 foo (int len)
19 {
20   int i;
21   int result = 0;
22 
23   for (i = 0; i < len; i++)
24     result += abs (X[i] - Y[i]);
25 
26   return result;
27 }
28 
29 
30 int
main(void)31 main (void)
32 {
33   int i;
34   int sad;
35 
36   check_vect ();
37 
38   for (i = 0; i < N; i++)
39     {
40       X[i] = i;
41       Y[i] = N - i;
42       __asm__ volatile ("");
43     }
44 
45   sad = foo (N);
46   if (sad != SAD)
47     abort ();
48 
49   return 0;
50 }
51 
52 /* { dg-final { scan-tree-dump-times "vect_recog_sad_pattern: detected" 1 "vect" } } */
53 /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */
54 
55