Prefetch.h#
Fully qualified name: carb/Prefetch.h
File members: carb/Prefetch.h
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
//
// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
// property and proprietary rights in and to this material, related
// documentation and any modifications thereto. Any use, reproduction,
// disclosure or distribution of this material and related documentation
// without an express license agreement from NVIDIA CORPORATION or
// its affiliates is strictly prohibited.
#pragma once
#include "Architecture.h"
#include "Compiler.h"
#if CARB_COMPILER_MSC || defined(DOXYGEN_BUILD)
# if defined(DOXYGEN_BUILD)
# define CARB_PREFETCH(addr, write, level)
# elif CARB_X86_64
extern "C" void _mm_prefetch(char const* _A, int _Sel); // From winnt.h/intrin.h
# pragma intrinsic(_mm_prefetch)
# define CARB_PREFETCH(addr, write, level) _mm_prefetch(reinterpret_cast<char*>(addr), int(level))
# elif CARB_AARCH64
# pragma intrinsic(__prefetch)
# define CARB_PREFETCH(addr, write, level) __prefetch(reinterpret_cast<void*>(addr))
# endif
#elif CARB_COMPILER_GNUC
# define CARB_PREFETCH(addr, write, level) __builtin_prefetch((addr), (write), int(level))
#else
CARB_UNSUPPORTED_PLATFORM();
#endif
namespace carb
{
#if defined DOXYGEN_BUILD || CARB_COMPILER_MSC
enum class PrefetchLevel
{
kHintNonTemporal = 0,
kHintL1 = 1,
kHintL2 = 2,
kHintL3 = 3,
};
#else
enum class PrefetchLevel
{
kHintNonTemporal = 0,
kHintL1 = 3,
kHintL2 = 2,
kHintL3 = 1,
};
#endif
} // namespace carb