1 // Copyright 2017 The CRC32C Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 5 #ifndef CRC32C_CRC32C_PREFETCH_H_ 6 #define CRC32C_CRC32C_PREFETCH_H_ 7 8 #include <cstddef> 9 #include <cstdint> 10 11 #include "crc32c/crc32c_config.h" 12 13 #if HAVE_MM_PREFETCH 14 15 #if defined(_MSC_VER) 16 #include <intrin.h> 17 #else // !defined(_MSC_VER) 18 #include <xmmintrin.h> 19 #endif // defined(_MSC_VER) 20 21 #endif // HAVE_MM_PREFETCH 22 23 namespace crc32c { 24 25 // Ask the hardware to prefetch the data at the given address into the L1 cache. RequestPrefetch(const uint8_t * address)26inline void RequestPrefetch(const uint8_t* address) { 27 #if HAVE_BUILTIN_PREFETCH 28 // Clang and GCC implement the __builtin_prefetch non-standard extension, 29 // which maps to the best instruction on the target architecture. 30 __builtin_prefetch(reinterpret_cast<const char*>(address), 0 /* Read only. */, 31 0 /* No temporal locality. */); 32 #elif HAVE_MM_PREFETCH 33 // Visual Studio doesn't implement __builtin_prefetch, but exposes the 34 // PREFETCHNTA instruction via the _mm_prefetch intrinsic. 35 _mm_prefetch(reinterpret_cast<const char*>(address), _MM_HINT_NTA); 36 #else 37 // No prefetch support. Silence compiler warnings. 38 (void)address; 39 #endif // HAVE_BUILTIN_PREFETCH 40 } 41 42 } // namespace crc32c 43 44 #endif // CRC32C_CRC32C_ROUND_UP_H_ 45