1 /* Test that __builtin_prefetch does no harm.
2 
3    Use addresses that are unlikely to be word-aligned.  Some targets
4    have alignment requirements for prefetch addresses, so make sure the
5    compiler takes care of that.  This fails if it aborts, anything else
6    is OK.  */
7 
8 struct S {
9   short a;
10   short b;
11   char c[8];
12 } s;
13 
14 char arr[100];
15 char *ptr = arr;
16 int idx = 3;
17 
18 void
arg_ptr(char * p)19 arg_ptr (char *p)
20 {
21   __builtin_prefetch (p, 0, 0);
22 }
23 
24 void
arg_idx(char * p,int i)25 arg_idx (char *p, int i)
26 {
27   __builtin_prefetch (&p[i], 0, 0);
28 }
29 
30 void
glob_ptr(void)31 glob_ptr (void)
32 {
33   __builtin_prefetch (ptr, 0, 0);
34 }
35 
36 void
glob_idx(void)37 glob_idx (void)
38 {
39   __builtin_prefetch (&ptr[idx], 0, 0);
40 }
41 
42 int
main()43 main ()
44 {
45   __builtin_prefetch (&s.b, 0, 0);
46   __builtin_prefetch (&s.c[1], 0, 0);
47 
48   arg_ptr (&s.c[1]);
49   arg_ptr (ptr+3);
50   arg_idx (ptr, 3);
51   arg_idx (ptr+1, 2);
52   idx = 3;
53   glob_ptr ();
54   glob_idx ();
55   ptr++;
56   idx = 2;
57   glob_ptr ();
58   glob_idx ();
59   exit (0);
60 }
61