| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-O3 -mdejagnu-cpu=power9 -mvsx" } */ |
| 3 |
/* { dg-require-effective-target powerpc_vsx } */ |
| 4 |
|
| 5 |
/* Verify that we vectorize this SAD loop using vabsdub. */ |
| 6 |
|
| 7 |
extern int abs (int __x) __attribute__ ((__nothrow__, __leaf__)) __attribute__ ((__const__)); |
| 8 |
|
| 9 |
static int |
| 10 |
foo (unsigned char *w, int i, unsigned char *x, int j) |
| 11 |
{ |
| 12 |
int tot = 0; |
| 13 |
for (int a = 0; a < 16; a++) |
| 14 |
{ |
| 15 |
for (int b = 0; b < 16; b++) |
| 16 |
tot += abs (w[b] - x[b]); |
| 17 |
w += i; |
| 18 |
x += j; |
| 19 |
} |
| 20 |
return tot; |
| 21 |
} |
| 22 |
|
| 23 |
void |
| 24 |
bar (unsigned char *w, unsigned char *x, int i, int *result) |
| 25 |
{ |
| 26 |
*result = foo (w, 16, x, i); |
| 27 |
} |
| 28 |
|
| 29 |
/* { dg-final { scan-assembler-times "vabsdub" 16 } } */ |
| 30 |
/* { dg-final { scan-assembler-times "vsum4ubs" 16 } } */ |
| 31 |
/* { dg-final { scan-assembler-times "vadduwm" 17 } } */ |
| 32 |
|
| 33 |
/* Note: One of the 16 adds is optimized out (add with zero), |
| 34 |
leaving 15. The extra two adds are for the final reduction. */ |