| 1 |
/* Test that __builtin_prefetch does no harm. |
| 2 |
|
| 3 |
Prefetch data using a variety of storage classes and address |
| 4 |
expressions with volatile variables and pointers. */ |
| 5 |
|
| 6 |
void exit (int); |
| 7 |
|
| 8 |
int glob_int_arr[100]; |
| 9 |
int glob_int = 4; |
| 10 |
volatile int glob_vol_int_arr[100]; |
| 11 |
int * volatile glob_vol_ptr_int = glob_int_arr; |
| 12 |
volatile int *glob_ptr_vol_int = glob_vol_int_arr; |
| 13 |
volatile int * volatile glob_vol_ptr_vol_int = glob_vol_int_arr; |
| 14 |
volatile int glob_vol_int; |
| 15 |
|
| 16 |
static int stat_int_arr[100]; |
| 17 |
static volatile int stat_vol_int_arr[100]; |
| 18 |
static int * volatile stat_vol_ptr_int = stat_int_arr; |
| 19 |
static volatile int *stat_ptr_vol_int = stat_vol_int_arr; |
| 20 |
static volatile int * volatile stat_vol_ptr_vol_int = stat_vol_int_arr; |
| 21 |
static volatile int stat_vol_int; |
| 22 |
|
| 23 |
struct S { |
| 24 |
int a; |
| 25 |
short b, c; |
| 26 |
char d[8]; |
| 27 |
struct S *next; |
| 28 |
}; |
| 29 |
|
| 30 |
struct S str; |
| 31 |
volatile struct S vol_str; |
| 32 |
struct S * volatile vol_ptr_str = &str; |
| 33 |
volatile struct S *ptr_vol_str = &vol_str; |
| 34 |
volatile struct S * volatile vol_ptr_vol_str = &vol_str; |
| 35 |
|
| 36 |
/* Prefetch volatile global variables using the address of the variable. */ |
| 37 |
|
| 38 |
void |
| 39 |
simple_vol_global () |
| 40 |
{ |
| 41 |
__builtin_prefetch (glob_vol_int_arr, 0, 0); |
| 42 |
__builtin_prefetch (glob_vol_ptr_int, 0, 0); |
| 43 |
__builtin_prefetch (glob_ptr_vol_int, 0, 0); |
| 44 |
__builtin_prefetch (glob_vol_ptr_vol_int, 0, 0); |
| 45 |
__builtin_prefetch (&glob_vol_int, 0, 0); |
| 46 |
} |
| 47 |
|
| 48 |
/* Prefetch volatile static variables using the address of the variable. */ |
| 49 |
|
| 50 |
void |
| 51 |
simple_vol_file () |
| 52 |
{ |
| 53 |
__builtin_prefetch (stat_vol_int_arr, 0, 0); |
| 54 |
__builtin_prefetch (stat_vol_ptr_int, 0, 0); |
| 55 |
__builtin_prefetch (stat_ptr_vol_int, 0, 0); |
| 56 |
__builtin_prefetch (stat_vol_ptr_vol_int, 0, 0); |
| 57 |
__builtin_prefetch (&stat_vol_int, 0, 0); |
| 58 |
} |
| 59 |
|
| 60 |
/* Prefetch using address expressions involving volatile global variables. */ |
| 61 |
|
| 62 |
void |
| 63 |
expr_vol_global (void) |
| 64 |
{ |
| 65 |
__builtin_prefetch (&vol_str, 0, 0); |
| 66 |
__builtin_prefetch (ptr_vol_str, 0, 0); |
| 67 |
__builtin_prefetch (vol_ptr_str, 0, 0); |
| 68 |
__builtin_prefetch (vol_ptr_vol_str, 0, 0); |
| 69 |
__builtin_prefetch (&vol_str.b, 0, 0); |
| 70 |
__builtin_prefetch (&ptr_vol_str->b, 0, 0); |
| 71 |
__builtin_prefetch (&vol_ptr_str->b, 0, 0); |
| 72 |
__builtin_prefetch (&vol_ptr_vol_str->b, 0, 0); |
| 73 |
__builtin_prefetch (&vol_str.d, 0, 0); |
| 74 |
__builtin_prefetch (&vol_ptr_str->d, 0, 0); |
| 75 |
__builtin_prefetch (&ptr_vol_str->d, 0, 0); |
| 76 |
__builtin_prefetch (&vol_ptr_vol_str->d, 0, 0); |
| 77 |
__builtin_prefetch (vol_str.next, 0, 0); |
| 78 |
__builtin_prefetch (vol_ptr_str->next, 0, 0); |
| 79 |
__builtin_prefetch (ptr_vol_str->next, 0, 0); |
| 80 |
__builtin_prefetch (vol_ptr_vol_str->next, 0, 0); |
| 81 |
__builtin_prefetch (vol_str.next->d, 0, 0); |
| 82 |
__builtin_prefetch (vol_ptr_str->next->d, 0, 0); |
| 83 |
__builtin_prefetch (ptr_vol_str->next->d, 0, 0); |
| 84 |
__builtin_prefetch (vol_ptr_vol_str->next->d, 0, 0); |
| 85 |
|
| 86 |
__builtin_prefetch (&glob_vol_int_arr, 0, 0); |
| 87 |
__builtin_prefetch (glob_vol_ptr_int, 0, 0); |
| 88 |
__builtin_prefetch (glob_ptr_vol_int, 0, 0); |
| 89 |
__builtin_prefetch (glob_vol_ptr_vol_int, 0, 0); |
| 90 |
__builtin_prefetch (&glob_vol_int_arr[2], 0, 0); |
| 91 |
__builtin_prefetch (&glob_vol_ptr_int[3], 0, 0); |
| 92 |
__builtin_prefetch (&glob_ptr_vol_int[3], 0, 0); |
| 93 |
__builtin_prefetch (&glob_vol_ptr_vol_int[3], 0, 0); |
| 94 |
__builtin_prefetch (glob_vol_int_arr+3, 0, 0); |
| 95 |
__builtin_prefetch (glob_vol_int_arr+glob_vol_int, 0, 0); |
| 96 |
__builtin_prefetch (glob_vol_ptr_int+5, 0, 0); |
| 97 |
__builtin_prefetch (glob_ptr_vol_int+5, 0, 0); |
| 98 |
__builtin_prefetch (glob_vol_ptr_vol_int+5, 0, 0); |
| 99 |
__builtin_prefetch (glob_vol_ptr_int+glob_vol_int, 0, 0); |
| 100 |
__builtin_prefetch (glob_ptr_vol_int+glob_vol_int, 0, 0); |
| 101 |
__builtin_prefetch (glob_vol_ptr_vol_int+glob_vol_int, 0, 0); |
| 102 |
} |
| 103 |
|
| 104 |
int |
| 105 |
main () |
| 106 |
{ |
| 107 |
simple_vol_global (); |
| 108 |
simple_vol_file (); |
| 109 |
|
| 110 |
str.next = &str; |
| 111 |
vol_str.next = &str; |
| 112 |
expr_vol_global (); |
| 113 |
|
| 114 |
exit (0); |
| 115 |
} |