| 1 |
/* Test that __builtin_prefetch does no harm. |
| 2 |
|
| 3 |
Prefetch data using a variety of storage classes and address |
| 4 |
expressions. */ |
| 5 |
|
| 6 |
void exit (int); |
| 7 |
|
| 8 |
int glob_int_arr[100]; |
| 9 |
int *glob_ptr_int = glob_int_arr; |
| 10 |
int glob_int = 4; |
| 11 |
|
| 12 |
static int stat_int_arr[100]; |
| 13 |
static int *stat_ptr_int = stat_int_arr; |
| 14 |
static int stat_int; |
| 15 |
|
| 16 |
struct S { |
| 17 |
int a; |
| 18 |
short b, c; |
| 19 |
char d[8]; |
| 20 |
struct S *next; |
| 21 |
}; |
| 22 |
|
| 23 |
struct S str; |
| 24 |
struct S *ptr_str = &str; |
| 25 |
|
| 26 |
/* Prefetch global variables using the address of the variable. */ |
| 27 |
|
| 28 |
void |
| 29 |
simple_global () |
| 30 |
{ |
| 31 |
__builtin_prefetch (glob_int_arr, 0, 0); |
| 32 |
__builtin_prefetch (glob_ptr_int, 0, 0); |
| 33 |
__builtin_prefetch (&glob_int, 0, 0); |
| 34 |
} |
| 35 |
|
| 36 |
/* Prefetch file-level static variables using the address of the variable. */ |
| 37 |
|
| 38 |
void |
| 39 |
simple_file () |
| 40 |
{ |
| 41 |
__builtin_prefetch (stat_int_arr, 0, 0); |
| 42 |
__builtin_prefetch (stat_ptr_int, 0, 0); |
| 43 |
__builtin_prefetch (&stat_int, 0, 0); |
| 44 |
} |
| 45 |
|
| 46 |
/* Prefetch local static variables using the address of the variable. */ |
| 47 |
|
| 48 |
void |
| 49 |
simple_static_local () |
| 50 |
{ |
| 51 |
static int gx[100]; |
| 52 |
static int *hx = gx; |
| 53 |
static int ix; |
| 54 |
__builtin_prefetch (gx, 0, 0); |
| 55 |
__builtin_prefetch (hx, 0, 0); |
| 56 |
__builtin_prefetch (&ix, 0, 0); |
| 57 |
} |
| 58 |
|
| 59 |
/* Prefetch local stack variables using the address of the variable. */ |
| 60 |
|
| 61 |
void |
| 62 |
simple_local () |
| 63 |
{ |
| 64 |
int gx[100]; |
| 65 |
int *hx = gx; |
| 66 |
int ix; |
| 67 |
__builtin_prefetch (gx, 0, 0); |
| 68 |
__builtin_prefetch (hx, 0, 0); |
| 69 |
__builtin_prefetch (&ix, 0, 0); |
| 70 |
} |
| 71 |
|
| 72 |
/* Prefetch arguments using the address of the variable. */ |
| 73 |
|
| 74 |
void |
| 75 |
simple_arg (int g[100], int *h, int i) |
| 76 |
{ |
| 77 |
__builtin_prefetch (g, 0, 0); |
| 78 |
__builtin_prefetch (h, 0, 0); |
| 79 |
__builtin_prefetch (&i, 0, 0); |
| 80 |
} |
| 81 |
|
| 82 |
/* Prefetch using address expressions involving global variables. */ |
| 83 |
|
| 84 |
void |
| 85 |
expr_global (void) |
| 86 |
{ |
| 87 |
__builtin_prefetch (&str, 0, 0); |
| 88 |
__builtin_prefetch (ptr_str, 0, 0); |
| 89 |
__builtin_prefetch (&str.b, 0, 0); |
| 90 |
__builtin_prefetch (&ptr_str->b, 0, 0); |
| 91 |
__builtin_prefetch (&str.d, 0, 0); |
| 92 |
__builtin_prefetch (&ptr_str->d, 0, 0); |
| 93 |
__builtin_prefetch (str.next, 0, 0); |
| 94 |
__builtin_prefetch (ptr_str->next, 0, 0); |
| 95 |
__builtin_prefetch (str.next->d, 0, 0); |
| 96 |
__builtin_prefetch (ptr_str->next->d, 0, 0); |
| 97 |
|
| 98 |
__builtin_prefetch (&glob_int_arr, 0, 0); |
| 99 |
__builtin_prefetch (glob_ptr_int, 0, 0); |
| 100 |
__builtin_prefetch (&glob_int_arr[2], 0, 0); |
| 101 |
__builtin_prefetch (&glob_ptr_int[3], 0, 0); |
| 102 |
__builtin_prefetch (glob_int_arr+3, 0, 0); |
| 103 |
__builtin_prefetch (glob_int_arr+glob_int, 0, 0); |
| 104 |
__builtin_prefetch (glob_ptr_int+5, 0, 0); |
| 105 |
__builtin_prefetch (glob_ptr_int+glob_int, 0, 0); |
| 106 |
} |
| 107 |
|
| 108 |
/* Prefetch using address expressions involving local variables. */ |
| 109 |
|
| 110 |
void |
| 111 |
expr_local (void) |
| 112 |
{ |
| 113 |
int b[10]; |
| 114 |
int *pb = b; |
| 115 |
struct S t; |
| 116 |
struct S *pt = &t; |
| 117 |
int j = 4; |
| 118 |
|
| 119 |
__builtin_prefetch (&t, 0, 0); |
| 120 |
__builtin_prefetch (pt, 0, 0); |
| 121 |
__builtin_prefetch (&t.b, 0, 0); |
| 122 |
__builtin_prefetch (&pt->b, 0, 0); |
| 123 |
__builtin_prefetch (&t.d, 0, 0); |
| 124 |
__builtin_prefetch (&pt->d, 0, 0); |
| 125 |
__builtin_prefetch (t.next, 0, 0); |
| 126 |
__builtin_prefetch (pt->next, 0, 0); |
| 127 |
__builtin_prefetch (t.next->d, 0, 0); |
| 128 |
__builtin_prefetch (pt->next->d, 0, 0); |
| 129 |
|
| 130 |
__builtin_prefetch (&b, 0, 0); |
| 131 |
__builtin_prefetch (pb, 0, 0); |
| 132 |
__builtin_prefetch (&b[2], 0, 0); |
| 133 |
__builtin_prefetch (&pb[3], 0, 0); |
| 134 |
__builtin_prefetch (b+3, 0, 0); |
| 135 |
__builtin_prefetch (b+j, 0, 0); |
| 136 |
__builtin_prefetch (pb+5, 0, 0); |
| 137 |
__builtin_prefetch (pb+j, 0, 0); |
| 138 |
} |
| 139 |
|
| 140 |
int |
| 141 |
main () |
| 142 |
{ |
| 143 |
simple_global (); |
| 144 |
simple_file (); |
| 145 |
simple_static_local (); |
| 146 |
simple_local (); |
| 147 |
simple_arg (glob_int_arr, glob_ptr_int, glob_int); |
| 148 |
|
| 149 |
str.next = &str; |
| 150 |
expr_global (); |
| 151 |
expr_local (); |
| 152 |
|
| 153 |
exit (0); |
| 154 |
} |