1 /* { dg-do run { target { powerpc*-*-linux* && { lp64 && p9vector_hw } } } } */
2 /* { dg-require-effective-target powerpc_p9vector_ok } */
3 /* { dg-options "-O3 -mdejagnu-cpu=power9" } */
4 
5 /* Verify that we get correct code when we vectorize this SAD loop using
6    vabsdub. */
7 
8 extern void abort ();
9 extern int abs (int __x) __attribute__ ((__nothrow__, __leaf__)) __attribute__ ((__const__));
10 
11 static int
foo(unsigned char * w,int i,unsigned char * x,int j)12 foo (unsigned char *w, int i, unsigned char *x, int j)
13 {
14   int tot = 0;
15   for (int a = 0; a < 16; a++)
16     {
17       for (int b = 0; b < 16; b++)
18 	tot += abs (w[b] - x[b]);
19       w += i;
20       x += j;
21     }
22   return tot;
23 }
24 
25 void
bar(unsigned char * w,unsigned char * x,int i,int * result)26 bar (unsigned char *w, unsigned char *x, int i, int *result)
27 {
28   *result = foo (w, 16, x, i);
29 }
30 
31 int
main()32 main ()
33 {
34   unsigned char m[256];
35   unsigned char n[256];
36   int sum, i;
37 
38   for (i = 0; i < 256; ++i)
39     if (i % 2 == 0)
40       {
41 	m[i] = (i % 8) * 2 + 1;
42 	n[i] = -(i % 8);
43       }
44     else
45       {
46 	m[i] = -((i % 8) * 2 + 2);
47 	n[i] = -((i % 8) >> 1);
48       }
49 
50   bar (m, n, 16, &sum);
51 
52   if (sum != 32384)
53     abort ();
54 
55   return 0;
56 }
57