OSDN Git Service

2008-07-27 Victor Kaplansky <victork@il.ibm.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / vect / vect-reduc-dot-u8b.c
1 /* { dg-require-effective-target vect_int } */
2
3 #include <stdarg.h>
4 #include "tree-vect.h"
5
6 #define N 64
7
8 #define DOT 43680
9
10 unsigned char X[N] __attribute__ ((__aligned__(16)));
11 unsigned char Y[N] __attribute__ ((__aligned__(16)));
12
13 /* char->short->short dot product. 
14    Detected as a dot-product pattern.
15    Should be vectorized on targets that support dot-product for unsigned chars,
16    but currently this test cannot be vectorized as a dot-product on targets
17    that support char->short->int dot-product. 
18    Alternatively, this test can be vectorized using vect_widen_mult_qi (or
19    vect_unpack and non-widening multplication: vect_unpack && vect_short_mult).
20    */
21 __attribute__ ((noinline)) unsigned short
22 foo (int len) {
23   int i;
24   unsigned short result = 0;
25
26   for (i=0; i<len; i++) {
27     result += (unsigned short)(X[i] * Y[i]);
28   }
29   return result;
30 }
31
32 int main (void)
33 {
34   unsigned short dot;
35   int i;
36
37   check_vect ();
38
39   for (i=0; i<N; i++) {
40     X[i] = i;
41     Y[i] = 64-i;
42   }
43
44   dot = foo (N);
45   if (dot != DOT)
46     abort ();
47
48   return 0;
49 }
50
51 /* { dg-final { scan-tree-dump-times "vect_recog_dot_prod_pattern: detected" 1 "vect" } } */
52
53 /* When the vectorizer is enhanced to vectorize accumulation into short for 
54    targets that support accumulation into int (powerpc, ia64) we'd have:
55 dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { target vect_udot_qi || vect_widen_mult_qi_to_hi } }
56 */
57 /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" {target vect_widen_mult_qi_to_hi} } } */
58
59 /* { dg-final { cleanup-tree-dump "vect" } } */
60