Debian Codegraph @

gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-1.c

raw
1 /* Test that __builtin_prefetch does no harm.
2
3 Prefetch using all valid combinations of rw and locality values.
4 These must be compile-time constants. */
5
6 void exit (int);
7
8 #define NO_TEMPORAL_LOCALITY 0
9 #define LOW_TEMPORAL_LOCALITY 1
10 #define MODERATE_TEMPORAL_LOCALITY 1
11 #define HIGH_TEMPORAL_LOCALITY 3
12
13 #define READ_SHARED 2
14 #define WRITE_ACCESS 1
15 #define READ_ACCESS 0
16
17 enum locality { none, low, moderate, high };
18 enum rws { read, write, read_shared };
19
20 int arr[10];
21
22 void
23 good_const (const int *p)
24 {
25 __builtin_prefetch (p, 0, 0);
26 __builtin_prefetch (p, 0, 1);
27 __builtin_prefetch (p, 0, 2);
28 __builtin_prefetch (p, READ_ACCESS, 3);
29 __builtin_prefetch (p, 1, NO_TEMPORAL_LOCALITY);
30 __builtin_prefetch (p, 1, LOW_TEMPORAL_LOCALITY);
31 __builtin_prefetch (p, 1, MODERATE_TEMPORAL_LOCALITY);
32 __builtin_prefetch (p, WRITE_ACCESS, HIGH_TEMPORAL_LOCALITY);
33 }
34
35 void
36 good_enum (const int *p)
37 {
38 __builtin_prefetch (p, read, none);
39 __builtin_prefetch (p, read, low);
40 __builtin_prefetch (p, read, moderate);
41 __builtin_prefetch (p, read, high);
42 __builtin_prefetch (p, write, none);
43 __builtin_prefetch (p, write, low);
44 __builtin_prefetch (p, write, moderate);
45 __builtin_prefetch (p, write, high);
46 }
47
48 void
49 good_expr (const int *p)
50 {
51 __builtin_prefetch (p, 1 - 1, 6 - (2 * 3));
52 __builtin_prefetch (p, 1 + 0, 1 + 2);
53 }
54
55 void
56 good_vararg (const int *p)
57 {
58 __builtin_prefetch (p, 0, 3);
59 __builtin_prefetch (p, 0);
60 __builtin_prefetch (p, 1);
61 __builtin_prefetch (p);
62 }
63
64 int
65 main ()
66 {
67 good_const (arr);
68 good_enum (arr);
69 good_expr (arr);
70 good_vararg (arr);
71 exit (0);
72 }