2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / builtin-prefetch-1.c
blob4ee05a94d9f63c159cca72583109eb2f95ed10bb
1 /* Test that __builtin_prefetch does no harm.
3 Prefetch using all valid combinations of rw and locality values.
4 These must be compile-time constants. */
6 #define NO_TEMPORAL_LOCALITY 0
7 #define LOW_TEMPORAL_LOCALITY 1
8 #define MODERATE_TEMPORAL_LOCALITY 1
9 #define HIGH_TEMPORAL_LOCALITY 3
11 #define WRITE_ACCESS 1
12 #define READ_ACCESS 0
14 enum locality { none, low, moderate, high };
15 enum rw { read, write };
17 int arr[10];
19 void
20 good_const (const int *p)
22 __builtin_prefetch (p, 0, 0);
23 __builtin_prefetch (p, 0, 1);
24 __builtin_prefetch (p, 0, 2);
25 __builtin_prefetch (p, READ_ACCESS, 3);
26 __builtin_prefetch (p, 1, NO_TEMPORAL_LOCALITY);
27 __builtin_prefetch (p, 1, LOW_TEMPORAL_LOCALITY);
28 __builtin_prefetch (p, 1, MODERATE_TEMPORAL_LOCALITY);
29 __builtin_prefetch (p, WRITE_ACCESS, HIGH_TEMPORAL_LOCALITY);
32 void
33 good_enum (const int *p)
35 __builtin_prefetch (p, read, none);
36 __builtin_prefetch (p, read, low);
37 __builtin_prefetch (p, read, moderate);
38 __builtin_prefetch (p, read, high);
39 __builtin_prefetch (p, write, none);
40 __builtin_prefetch (p, write, low);
41 __builtin_prefetch (p, write, moderate);
42 __builtin_prefetch (p, write, high);
45 void
46 good_expr (const int *p)
48 __builtin_prefetch (p, 1 - 1, 6 - (2 * 3));
49 __builtin_prefetch (p, 1 + 0, 1 + 2);
52 void
53 good_vararg (const int *p)
55 __builtin_prefetch (p, 0, 3);
56 __builtin_prefetch (p, 0);
57 __builtin_prefetch (p, 1);
58 __builtin_prefetch (p);
61 int
62 main ()
64 good_const (arr);
65 good_enum (arr);
66 good_expr (arr);
67 good_vararg (arr);
68 exit (0);