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