Path: blob/main/contrib/llvm-project/libc/src/__support/macros/optimization.h
213799 views
//===-- Portable optimization macros ----------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7// This header file defines portable macros for performance optimization.89#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_OPTIMIZATION_H10#define LLVM_LIBC_SRC___SUPPORT_MACROS_OPTIMIZATION_H1112#include "src/__support/macros/attributes.h" // LIBC_INLINE13#include "src/__support/macros/config.h"14#include "src/__support/macros/properties/compiler.h" // LIBC_COMPILER_IS_CLANG1516// We use a template to implement likely/unlikely to make sure that we don't17// accidentally pass an integer.18namespace LIBC_NAMESPACE_DECL {19namespace details {20template <typename T>21LIBC_INLINE constexpr bool expects_bool_condition(T value, T expected) {22return __builtin_expect(value, expected);23}24} // namespace details25} // namespace LIBC_NAMESPACE_DECL26#define LIBC_LIKELY(x) LIBC_NAMESPACE::details::expects_bool_condition(x, true)27#define LIBC_UNLIKELY(x) \28LIBC_NAMESPACE::details::expects_bool_condition(x, false)2930#if defined(LIBC_COMPILER_IS_CLANG)31#define LIBC_LOOP_NOUNROLL _Pragma("nounroll")32#define LIBC_LOOP_UNROLL _Pragma("unroll")33#elif defined(LIBC_COMPILER_IS_GCC)34#define LIBC_LOOP_NOUNROLL _Pragma("GCC unroll 0")35#define LIBC_LOOP_UNROLL _Pragma("GCC unroll 2048")36#else37#error "Unhandled compiler"38#endif3940// Defining optimization options for math functions.41// TODO: Exporting this to public generated headers?42#define LIBC_MATH_SKIP_ACCURATE_PASS 0x0143#define LIBC_MATH_SMALL_TABLES 0x0244#define LIBC_MATH_NO_ERRNO 0x0445#define LIBC_MATH_NO_EXCEPT 0x0846#define LIBC_MATH_FAST \47(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | \48LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)49#define LIBC_MATH_INTERMEDIATE_COMP_IN_FLOAT 0x105051#ifndef LIBC_MATH52#define LIBC_MATH 053#endif // LIBC_MATH5455#if (LIBC_MATH & LIBC_MATH_SKIP_ACCURATE_PASS)56#define LIBC_MATH_HAS_SKIP_ACCURATE_PASS57#endif5859#if (LIBC_MATH & LIBC_MATH_SMALL_TABLES)60#define LIBC_MATH_HAS_SMALL_TABLES61#endif6263#if (LIBC_MATH & LIBC_MATH_INTERMEDIATE_COMP_IN_FLOAT)64#define LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT65#endif6667#if (LIBC_MATH & LIBC_MATH_NO_ERRNO)68#define LIBC_MATH_HAS_NO_ERRNO69#endif7071#if (LIBC_MATH & LIBC_MATH_NO_EXCEPT)72#define LIBC_MATH_HAS_NO_EXCEPT73#endif7475#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_OPTIMIZATION_H767778