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  #define NO_TEMPORAL_LOCALITY 0
       7  #define LOW_TEMPORAL_LOCALITY 1
       8  #define MODERATE_TEMPORAL_LOCALITY 1
       9  #define HIGH_TEMPORAL_LOCALITY 3
      10  
      11  #define WRITE_ACCESS 1
      12  #define READ_ACCESS 0
      13  
      14  enum locality { none, low, moderate, high };
      15  enum rw { read, write };
      16  
      17  int arr[10];
      18  
      19  void
      20  good_const (const int *p)
      21  {
      22    __builtin_prefetch (p, 0, 0);
      23    __builtin_prefetch (p, 0, 1);
      24    __builtin_prefetch (p, 0, 2);
      25    __builtin_prefetch (p, READ_ACCESS, 3);
      26    __builtin_prefetch (p, 1, NO_TEMPORAL_LOCALITY);
      27    __builtin_prefetch (p, 1, LOW_TEMPORAL_LOCALITY);
      28    __builtin_prefetch (p, 1, MODERATE_TEMPORAL_LOCALITY);
      29    __builtin_prefetch (p, WRITE_ACCESS, HIGH_TEMPORAL_LOCALITY);
      30  }
      31  
      32  void
      33  good_enum (const int *p)
      34  {
      35      __builtin_prefetch (p, read, none);
      36      __builtin_prefetch (p, read, low);
      37      __builtin_prefetch (p, read, moderate);
      38      __builtin_prefetch (p, read, high);
      39      __builtin_prefetch (p, write, none);
      40      __builtin_prefetch (p, write, low);
      41      __builtin_prefetch (p, write, moderate);
      42      __builtin_prefetch (p, write, high);
      43  }
      44  
      45  void
      46  good_expr (const int *p)
      47  {
      48    __builtin_prefetch (p, 1 - 1, 6 - (2 * 3));
      49    __builtin_prefetch (p, 1 + 0, 1 + 2);
      50  }
      51  
      52  void
      53  good_vararg (const int *p)
      54  {
      55    __builtin_prefetch (p, 0, 3);
      56    __builtin_prefetch (p, 0);
      57    __builtin_prefetch (p, 1);
      58    __builtin_prefetch (p);
      59  }
      60  
      61  int
      62  main ()
      63  {
      64    good_const (arr);
      65    good_enum (arr);
      66    good_expr (arr);
      67    good_vararg (arr);
      68    exit (0);
      69  }