1 /*
2    Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef NDB_PREFETCH_H
26 #define NDB_PREFETCH_H
27 
28 #ifdef HAVE_SUN_PREFETCH_H
29 #include <sun_prefetch.h>
30 #if (defined(__SUNPRO_C) && __SUNPRO_C >= 0x590) \
31     || (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590)
32 /* Universal sun_prefetch* macros available with Sun Studio 5.9 */
33 #define USE_SUN_PREFETCH
34 #elif defined(__sparc)
35 /* Use sparc_prefetch* macros with older Sun Studio on sparc */
36 #define USE_SPARC_PREFETCH
37 #endif
38 #endif
39 
40 #ifdef HAVE_SUN_PREFETCH_H
41 #pragma optimize("", off)
42 #endif
43 
44 static inline
NDB_PREFETCH_READ(void * addr)45 void NDB_PREFETCH_READ(void* addr)
46 {
47 #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
48   __builtin_prefetch(addr, 0, 3);
49 #elif defined(USE_SUN_PREFETCH)
50   sun_prefetch_read_once(addr);
51 #elif defined(USE_SPARC_PREFETCH)
52   sparc_prefetch_read_once(addr);
53 #else
54   (void)addr;
55 #endif
56 }
57 
58 static inline
NDB_PREFETCH_WRITE(void * addr)59 void NDB_PREFETCH_WRITE(void* addr)
60 {
61 #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
62   __builtin_prefetch(addr, 1, 3);
63 #elif defined(USE_SUN_PREFETCH)
64   sun_prefetch_write_once(addr);
65 #elif defined(USE_SPARC_PREFETCH)
66   sparc_prefetch_write_once(addr);
67 #else
68   (void)addr;
69 #endif
70 }
71 
72 #ifdef HAVE_SUN_PREFETCH_H
73 #pragma optimize("", on)
74 #endif
75 
76 #endif
77 
78