fixed PREFETCH() macro
for corner cases and platforms without this instruction
This commit is contained in:
+11
-9
@@ -91,25 +91,27 @@
|
|||||||
/* prefetch
|
/* prefetch
|
||||||
* can be disabled, by declaring NO_PREFETCH macro */
|
* can be disabled, by declaring NO_PREFETCH macro */
|
||||||
#if defined(NO_PREFETCH)
|
#if defined(NO_PREFETCH)
|
||||||
# define PREFETCH(ptr) /* disabled */
|
# define PREFETCH(ptr) (void)(ptr) /* disabled */
|
||||||
#else
|
#else
|
||||||
# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
|
# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
|
||||||
# include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
|
# include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
|
||||||
# define PREFETCH(ptr) _mm_prefetch((const char*)ptr, _MM_HINT_T1)
|
# define PREFETCH(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1)
|
||||||
# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
|
# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
|
||||||
# define PREFETCH(ptr) __builtin_prefetch(ptr, 0 /* rw==read */, 2 /* locality */)
|
# define PREFETCH(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
|
||||||
# else
|
# else
|
||||||
# define PREFETCH(ptr) /* disabled */
|
# define PREFETCH(ptr) (void)(ptr) /* disabled */
|
||||||
# endif
|
# endif
|
||||||
#endif /* NO_PREFETCH */
|
#endif /* NO_PREFETCH */
|
||||||
|
|
||||||
#define CACHELINE_SIZE 64
|
#define CACHELINE_SIZE 64
|
||||||
|
|
||||||
#define PREFETCH_AREA(ptr, size) { \
|
#define PREFETCH_AREA(p, s) { \
|
||||||
size_t pos; \
|
const char* const _ptr = (const char*)(p); \
|
||||||
for (pos=0; pos<size; pos+=CACHELINE_SIZE) { \
|
size_t const _size = (size_t)(s); \
|
||||||
PREFETCH( (const char*)ptr + pos); \
|
size_t _pos; \
|
||||||
} \
|
for (_pos=0; _pos<_size; _pos+=CACHELINE_SIZE) { \
|
||||||
|
PREFETCH(_ptr + _pos); \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* disable warnings */
|
/* disable warnings */
|
||||||
|
|||||||
Reference in New Issue
Block a user