diff --git a/libc/src/__support/CPP/array.h b/libc/src/__support/CPP/array.h --- a/libc/src/__support/CPP/array.h +++ b/libc/src/__support/CPP/array.h @@ -9,6 +9,8 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_CPP_ARRAY_H #define LLVM_LIBC_SRC_SUPPORT_CPP_ARRAY_H +#include "src/__support/macros/attributes.h" // LIBC_INLINE + #include // For size_t. namespace __llvm_libc { @@ -17,33 +19,39 @@ template struct array { static_assert(N != 0, "Cannot create a __llvm_libc::cpp::array of size 0."); + LIBC_INLINE constexpr array() = default; + LIBC_INLINE constexpr array(const array &) = default; + LIBC_INLINE ~array() = default; + T Data[N]; using iterator = T *; using const_iterator = const T *; - constexpr T *data() { return Data; } - constexpr const T *data() const { return Data; } + LIBC_INLINE constexpr T *data() { return Data; } + LIBC_INLINE constexpr const T *data() const { return Data; } - constexpr T &front() { return Data[0]; } - constexpr T &front() const { return Data[0]; } + LIBC_INLINE constexpr T &front() { return Data[0]; } + LIBC_INLINE constexpr T &front() const { return Data[0]; } - constexpr T &back() { return Data[N - 1]; } - constexpr T &back() const { return Data[N - 1]; } + LIBC_INLINE constexpr T &back() { return Data[N - 1]; } + LIBC_INLINE constexpr T &back() const { return Data[N - 1]; } - constexpr T &operator[](size_t Index) { return Data[Index]; } + LIBC_INLINE constexpr T &operator[](size_t Index) { return Data[Index]; } - constexpr const T &operator[](size_t Index) const { return Data[Index]; } + LIBC_INLINE constexpr const T &operator[](size_t Index) const { + return Data[Index]; + } - constexpr size_t size() const { return N; } + LIBC_INLINE constexpr size_t size() const { return N; } - constexpr bool empty() const { return N == 0; } + LIBC_INLINE constexpr bool empty() const { return N == 0; } - constexpr iterator begin() { return Data; } - constexpr const_iterator begin() const { return Data; } + LIBC_INLINE constexpr iterator begin() { return Data; } + LIBC_INLINE constexpr const_iterator begin() const { return Data; } - constexpr iterator end() { return Data + N; } - const_iterator end() const { return Data + N; } + LIBC_INLINE constexpr iterator end() { return Data + N; } + LIBC_INLINE const_iterator end() const { return Data + N; } }; } // namespace cpp diff --git a/libc/src/__support/CPP/bit.h b/libc/src/__support/CPP/bit.h --- a/libc/src/__support/CPP/bit.h +++ b/libc/src/__support/CPP/bit.h @@ -9,7 +9,8 @@ #ifndef LLVM_LIBC_SUPPORT_CPP_BIT_H #define LLVM_LIBC_SUPPORT_CPP_BIT_H -#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN +#include "src/__support/macros/attributes.h" // LIBC_INLINE +#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN namespace __llvm_libc::cpp { @@ -23,7 +24,8 @@ // This function guarantees the bitcast to be optimized away by the compiler for // GCC >= 8 and Clang >= 6. -template constexpr To bit_cast(const From &from) { +template +LIBC_INLINE constexpr To bit_cast(const From &from) { static_assert(sizeof(To) == sizeof(From), "To and From must be of same size"); #if defined(LLVM_LIBC_HAS_BUILTIN_BIT_CAST) return __builtin_bit_cast(To, from); diff --git a/libc/src/__support/CPP/bitset.h b/libc/src/__support/CPP/bitset.h --- a/libc/src/__support/CPP/bitset.h +++ b/libc/src/__support/CPP/bitset.h @@ -9,35 +9,41 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_CPP_BITSET_H #define LLVM_LIBC_SRC_SUPPORT_CPP_BITSET_H -#include // For size_t. +#include "src/__support/macros/attributes.h" // LIBC_INLINE +#include // For size_t. namespace __llvm_libc::cpp { template struct bitset { + + LIBC_INLINE constexpr bitset() = default; + LIBC_INLINE constexpr bitset(const bitset &) = default; + LIBC_INLINE ~bitset() = default; + static_assert(NumberOfBits != 0, "Cannot create a __llvm_libc::cpp::bitset of size 0."); - constexpr void set(size_t Index) { + LIBC_INLINE constexpr void set(size_t Index) { Data[Index / BITS_PER_UNIT] |= mask(Index); } - constexpr void reset() { + LIBC_INLINE constexpr void reset() { for (size_t i = 0; i < NUMBER_OF_UNITS; ++i) Data[i] = 0; } - constexpr bool test(size_t Index) const { + LIBC_INLINE constexpr bool test(size_t Index) const { return Data[Index / BITS_PER_UNIT] & mask(Index); } - constexpr void flip() { + LIBC_INLINE constexpr void flip() { for (size_t i = 0; i < NUMBER_OF_UNITS; ++i) Data[i] = ~Data[i]; } // This function sets all bits in the range from Start to End (inclusive) to // true. It assumes that Start <= End. - constexpr void set_range(size_t Start, size_t End) { + LIBC_INLINE constexpr void set_range(size_t Start, size_t End) { size_t start_index = Start / BITS_PER_UNIT; size_t end_index = End / BITS_PER_UNIT; @@ -64,7 +70,7 @@ } } - constexpr bool operator==(const bitset &other) { + LIBC_INLINE constexpr bool operator==(const bitset &other) { for (size_t i = 0; i < NUMBER_OF_UNITS; ++i) { if (Data[i] != other.Data[i]) return false; @@ -78,7 +84,7 @@ static constexpr size_t NUMBER_OF_UNITS = (NumberOfBits + BITS_PER_UNIT - 1) / BITS_PER_UNIT; - static constexpr size_t mask(size_t Index) { + LIBC_INLINE static constexpr size_t mask(size_t Index) { return size_t{1} << (Index % BITS_PER_UNIT); } size_t Data[NUMBER_OF_UNITS] = {0}; diff --git a/libc/src/__support/CPP/cstddef.h b/libc/src/__support/CPP/cstddef.h --- a/libc/src/__support/CPP/cstddef.h +++ b/libc/src/__support/CPP/cstddef.h @@ -9,52 +9,59 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_CPP_BYTE_H #define LLVM_LIBC_SRC_SUPPORT_CPP_BYTE_H -#include "type_traits.h" // For enable_if_t, is_integral_v. +#include "src/__support/macros/attributes.h" // LIBC_INLINE +#include "type_traits.h" // For enable_if_t, is_integral_v. namespace __llvm_libc::cpp { enum class byte : unsigned char {}; template -constexpr enable_if_t, byte> +LIBC_INLINE constexpr enable_if_t, byte> operator>>(byte b, IntegerType shift) noexcept { return static_cast(static_cast(b) >> shift); } template -constexpr enable_if_t, byte &> +LIBC_INLINE constexpr enable_if_t, byte &> operator>>=(byte &b, IntegerType shift) noexcept { return b = b >> shift; } template -constexpr enable_if_t, byte> +LIBC_INLINE constexpr enable_if_t, byte> operator<<(byte b, IntegerType shift) noexcept { return static_cast(static_cast(b) << shift); } template -constexpr enable_if_t, byte &> +LIBC_INLINE constexpr enable_if_t, byte &> operator<<=(byte &b, IntegerType shift) noexcept { return b = b << shift; } -constexpr byte operator|(byte l, byte r) noexcept { +LIBC_INLINE constexpr byte operator|(byte l, byte r) noexcept { return static_cast(static_cast(l) | static_cast(r)); } -constexpr byte &operator|=(byte &l, byte r) noexcept { return l = l | r; } -constexpr byte operator&(byte l, byte r) noexcept { +LIBC_INLINE constexpr byte &operator|=(byte &l, byte r) noexcept { + return l = l | r; +} +LIBC_INLINE constexpr byte operator&(byte l, byte r) noexcept { return static_cast(static_cast(l) & static_cast(r)); } -constexpr byte &operator&=(byte &l, byte r) noexcept { return l = l & r; } -constexpr byte operator^(byte l, byte r) noexcept { +LIBC_INLINE constexpr byte &operator&=(byte &l, byte r) noexcept { + return l = l & r; +} +LIBC_INLINE constexpr byte operator^(byte l, byte r) noexcept { return static_cast(static_cast(l) ^ static_cast(r)); } -constexpr byte &operator^=(byte &l, byte r) noexcept { return l = l ^ r; } -constexpr byte operator~(byte b) noexcept { +LIBC_INLINE constexpr byte &operator^=(byte &l, byte r) noexcept { + return l = l ^ r; +} +LIBC_INLINE constexpr byte operator~(byte b) noexcept { return static_cast(~static_cast(b)); } template -constexpr enable_if_t, IntegerType> +LIBC_INLINE constexpr enable_if_t, IntegerType> to_integer(byte b) noexcept { return static_cast(b); } diff --git a/libc/src/__support/CPP/type_traits.h b/libc/src/__support/CPP/type_traits.h --- a/libc/src/__support/CPP/type_traits.h +++ b/libc/src/__support/CPP/type_traits.h @@ -12,8 +12,14 @@ namespace __llvm_libc { namespace cpp { +// To avoid the linter requesting explicit constructors/destructors for these +// template-only classes, this file is marked as nolint. +// NOLINTBEGIN + template struct enable_if; -template struct enable_if { using type = T; }; +template struct enable_if { + using type = T; +}; template using enable_if_t = typename enable_if::type; @@ -24,7 +30,9 @@ using true_type = cpp::integral_constant; using false_type = cpp::integral_constant; -template struct type_identity { using type = T; }; +template struct type_identity { + using type = T; +}; template struct is_same : cpp::false_type {}; template struct is_same : cpp::true_type {}; @@ -114,26 +122,46 @@ inline constexpr bool is_unsigned_v = is_unsigned::value; template struct make_unsigned; -template <> struct make_unsigned { using type = unsigned char; }; -template <> struct make_unsigned { using type = unsigned char; }; -template <> struct make_unsigned { using type = unsigned short; }; -template <> struct make_unsigned { using type = unsigned int; }; -template <> struct make_unsigned { using type = unsigned long; }; +template <> struct make_unsigned { + using type = unsigned char; +}; +template <> struct make_unsigned { + using type = unsigned char; +}; +template <> struct make_unsigned { + using type = unsigned short; +}; +template <> struct make_unsigned { + using type = unsigned int; +}; +template <> struct make_unsigned { + using type = unsigned long; +}; template <> struct make_unsigned { using type = unsigned long long; }; -template <> struct make_unsigned { using type = unsigned char; }; +template <> struct make_unsigned { + using type = unsigned char; +}; template <> struct make_unsigned { using type = unsigned short; }; -template <> struct make_unsigned { using type = unsigned int; }; -template <> struct make_unsigned { using type = unsigned long; }; +template <> struct make_unsigned { + using type = unsigned int; +}; +template <> struct make_unsigned { + using type = unsigned long; +}; template <> struct make_unsigned { using type = unsigned long long; }; #ifdef __SIZEOF_INT128__ -template <> struct make_unsigned<__int128_t> { using type = __uint128_t; }; -template <> struct make_unsigned<__uint128_t> { using type = __uint128_t; }; +template <> struct make_unsigned<__int128_t> { + using type = __uint128_t; +}; +template <> struct make_unsigned<__uint128_t> { + using type = __uint128_t; +}; #endif template using make_unsigned_t = typename make_unsigned::type; @@ -147,6 +175,8 @@ template using conditional_t = typename conditional::type; +// NOLINTEND + } // namespace cpp } // namespace __llvm_libc diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h --- a/libc/src/__support/common.h +++ b/libc/src/__support/common.h @@ -35,7 +35,7 @@ namespace __llvm_libc { namespace internal { -constexpr bool same_string(char const *lhs, char const *rhs) { +LIBC_INLINE constexpr bool same_string(char const *lhs, char const *rhs) { for (; *lhs || *rhs; ++lhs, ++rhs) if (*lhs != *rhs) return false; diff --git a/libc/src/__support/endian.h b/libc/src/__support/endian.h --- a/libc/src/__support/endian.h +++ b/libc/src/__support/endian.h @@ -36,6 +36,8 @@ template static T to_little_endian(T value); }; +// NOLINTBEGIN + // Little Endian specializations template <> template <> @@ -136,6 +138,8 @@ return __builtin_bswap64(v); } +// NOLINTEND + } // namespace internal using Endian = internal::Endian<__BYTE_ORDER__>; diff --git a/libc/src/__support/macros/optimization.h b/libc/src/__support/macros/optimization.h --- a/libc/src/__support/macros/optimization.h +++ b/libc/src/__support/macros/optimization.h @@ -17,7 +17,7 @@ // accidentally pass an integer. namespace __llvm_libc::details { template -constexpr LIBC_INLINE bool expects_bool_condition(T value, T expected) { +LIBC_INLINE constexpr bool expects_bool_condition(T value, T expected) { return __builtin_expect(value, expected); } } // namespace __llvm_libc::details diff --git a/libc/src/string/memory_utils/op_generic.h b/libc/src/string/memory_utils/op_generic.h --- a/libc/src/string/memory_utils/op_generic.h +++ b/libc/src/string/memory_utils/op_generic.h @@ -58,7 +58,7 @@ }; // Helper to test if a type is void. -template inline constexpr bool is_void_v = cpp::is_same_v; +template inline constexpr bool IS_VOID_V = cpp::is_same_v; // Implements load, store and splat for unsigned integral types. template struct ScalarType { @@ -111,11 +111,11 @@ ::__llvm_libc::store(dst, value); } LIBC_INLINE static Type splat(uint8_t value) { - Type Out; + Type out; // This for loop is optimized out for vector types. for (size_t i = 0; i < Size; ++i) - Out[i] = static_cast(value); - return Out; + out[i] = static_cast(value); + return out; } }; @@ -145,37 +145,38 @@ // platform. SubType is either ScalarType or VectorType. template struct ArrayType { using Type = cpp::array; - static constexpr size_t SizeOfElement = sizeof(typename SubType::Type); + static constexpr size_t SIZE_OF_ELEMENT = sizeof(typename SubType::Type); LIBC_INLINE static Type load(CPtr src) { - Type Value; - for (size_t I = 0; I < ArraySize; ++I) - Value[I] = SubType::load(src + (I * SizeOfElement)); - return Value; + Type value; + for (size_t i = 0; i < ArraySize; ++i) + value[i] = SubType::load(src + (i * SIZE_OF_ELEMENT)); + return value; } - LIBC_INLINE static void store(Ptr dst, Type Value) { - for (size_t I = 0; I < ArraySize; ++I) - SubType::store(dst + (I * SizeOfElement), Value[I]); + LIBC_INLINE static void store(Ptr dst, Type value) { + for (size_t i = 0; i < ArraySize; ++i) + SubType::store(dst + (i * SIZE_OF_ELEMENT), value[i]); } LIBC_INLINE static Type splat(uint8_t value) { - Type Out; - for (size_t I = 0; I < ArraySize; ++I) - Out[I] = SubType::splat(value); - return Out; + Type out; + for (size_t i = 0; i < ArraySize; ++i) + out[i] = SubType::splat(value); + return out; } }; // Checks whether we should use an ArrayType. -template static constexpr bool useArrayType() { - return (Size > MaxSize) && ((Size % MaxSize) == 0) && - !is_void_v>; +template +LIBC_INLINE static constexpr bool use_array_type() { + return (Size > MAX_SIZE) && ((Size % MAX_SIZE) == 0) && + !IS_VOID_V>; } // Compute the type to handle an operation of Size bytes knowing that the -// underlying platform only support native types up to MaxSize bytes. -template +// underlying platform only support native types up to MAX_SIZE bytes. +template using getTypeFor = cpp::conditional_t< - useArrayType(), - ArrayType, Size / MaxSize>, + use_array_type(), + ArrayType, Size / MAX_SIZE>, NativeTypeMap::find_type>; /////////////////////////////////////////////////////////////////////////////// @@ -187,22 +188,22 @@ /////////////////////////////////////////////////////////////////////////////// // Memset -// The MaxSize template argument gives the maximum size handled natively by the +// The MAX_SIZE template argument gives the maximum size handled natively by the // platform. For instance on x86 with AVX support this would be 32. If a size -// greater than MaxSize is requested we break the operation down in smaller -// pieces of size MaxSize. +// greater than MAX_SIZE is requested we break the operation down in smaller +// pieces of size MAX_SIZE. /////////////////////////////////////////////////////////////////////////////// -template struct Memset { - static_assert(is_power2(MaxSize)); +template struct Memset { + static_assert(is_power2(MAX_SIZE)); static constexpr size_t SIZE = Size; LIBC_INLINE static void block(Ptr dst, uint8_t value) { if constexpr (Size == 3) { - Memset<1, MaxSize>::block(dst + 2, value); - Memset<2, MaxSize>::block(dst, value); + Memset<1, MAX_SIZE>::block(dst + 2, value); + Memset<2, MAX_SIZE>::block(dst, value); } else { - using T = getTypeFor; - if constexpr (is_void_v) { + using T = getTypeFor; + if constexpr (IS_VOID_V) { deferred_static_assert("Unimplemented Size"); } else { T::store(dst, T::splat(value)); @@ -235,9 +236,9 @@ /////////////////////////////////////////////////////////////////////////////// template struct Bcmp { static constexpr size_t SIZE = Size; - static constexpr size_t MaxSize = LLVM_LIBC_IS_DEFINED(LLVM_LIBC_HAS_UINT64) - ? sizeof(uint64_t) - : sizeof(uint32_t); + static constexpr size_t MAX_SIZE = LLVM_LIBC_IS_DEFINED(LLVM_LIBC_HAS_UINT64) + ? sizeof(uint64_t) + : sizeof(uint32_t); template LIBC_INLINE static uint32_t load_xor(CPtr p1, CPtr p2) { return load(p1) ^ load(p2); @@ -257,9 +258,9 @@ return load_xor(p1, p2); } else if constexpr (Size == 8) { return load_not_equal(p1, p2); - } else if constexpr (useArrayType()) { - for (size_t offset = 0; offset < Size; offset += MaxSize) - if (auto value = Bcmp::block(p1 + offset, p2 + offset)) + } else if constexpr (use_array_type()) { + for (size_t offset = 0; offset < Size; offset += MAX_SIZE) + if (auto value = Bcmp::block(p1 + offset, p2 + offset)) return value; } else { deferred_static_assert("Unimplemented Size"); @@ -293,9 +294,9 @@ /////////////////////////////////////////////////////////////////////////////// template struct Memcmp { static constexpr size_t SIZE = Size; - static constexpr size_t MaxSize = LLVM_LIBC_IS_DEFINED(LLVM_LIBC_HAS_UINT64) - ? sizeof(uint64_t) - : sizeof(uint32_t); + static constexpr size_t MAX_SIZE = LLVM_LIBC_IS_DEFINED(LLVM_LIBC_HAS_UINT64) + ? sizeof(uint64_t) + : sizeof(uint32_t); template LIBC_INLINE static T load_be(CPtr ptr) { return Endian::to_big_endian(load(ptr)); @@ -322,10 +323,10 @@ return load_be_cmp(p1, p2); } else if constexpr (Size == 8) { return load_be_cmp(p1, p2); - } else if constexpr (useArrayType()) { - for (size_t offset = 0; offset < Size; offset += MaxSize) - if (Bcmp::block(p1 + offset, p2 + offset)) - return Memcmp::block(p1 + offset, p2 + offset); + } else if constexpr (use_array_type()) { + for (size_t offset = 0; offset < Size; offset += MAX_SIZE) + if (Bcmp::block(p1 + offset, p2 + offset)) + return Memcmp::block(p1 + offset, p2 + offset); return MemcmpReturnType::ZERO(); } else if constexpr (Size == 3) { if (auto value = Memcmp<2>::block(p1, p2)) @@ -364,13 +365,13 @@ // Memmove /////////////////////////////////////////////////////////////////////////////// -template struct Memmove { - static_assert(is_power2(MaxSize)); - using T = getTypeFor; +template struct Memmove { + static_assert(is_power2(MAX_SIZE)); + using T = getTypeFor; static constexpr size_t SIZE = Size; LIBC_INLINE static void block(Ptr dst, CPtr src) { - if constexpr (is_void_v) { + if constexpr (IS_VOID_V) { deferred_static_assert("Unimplemented Size"); } else { T::store(dst, T::load(src)); @@ -379,7 +380,7 @@ LIBC_INLINE static void head_tail(Ptr dst, CPtr src, size_t count) { const size_t offset = count - Size; - if constexpr (is_void_v) { + if constexpr (IS_VOID_V) { deferred_static_assert("Unimplemented Size"); } else { // The load and store operations can be performed in any order as long as diff --git a/libc/src/string/memory_utils/op_x86.h b/libc/src/string/memory_utils/op_x86.h --- a/libc/src/string/memory_utils/op_x86.h +++ b/libc/src/string/memory_utils/op_x86.h @@ -49,7 +49,7 @@ /////////////////////////////////////////////////////////////////////////////// // Memcpy repmovsb implementation struct Memcpy { - static void repmovsb(void *dst, const void *src, size_t count) { + LIBC_INLINE static void repmovsb(void *dst, const void *src, size_t count) { asm volatile("rep movsb" : "+D"(dst), "+S"(src), "+c"(count) : : "memory"); } }; @@ -103,8 +103,8 @@ #if defined(__SSE2__) using T = char __attribute__((__vector_size__(16))); // A mask indicating which bytes differ after loading 16 bytes from p1 and p2. - const int mask = - _mm_movemask_epi8(cpp::bit_cast<__m128i>(load(p1) != load(p2))); + const int mask = _mm_movemask_epi8( // NOLINT + cpp::bit_cast<__m128i>(load(p1) != load(p2))); return static_cast(mask); #else (void)p1; @@ -120,8 +120,8 @@ #if defined(__AVX2__) using T = char __attribute__((__vector_size__(32))); // A mask indicating which bytes differ after loading 32 bytes from p1 and p2. - const int mask = - _mm256_movemask_epi8(cpp::bit_cast<__m256i>(load(p1) != load(p2))); + const int mask = _mm256_movemask_epi8( // NOLINT + cpp::bit_cast<__m256i>(load(p1) != load(p2))); // _mm256_movemask_epi8 returns an int but it is to be interpreted as a 32-bit // mask. return static_cast(mask); @@ -139,7 +139,7 @@ #if defined(__AVX512BW__) using T = char __attribute__((__vector_size__(64))); // A mask indicating which bytes differ after loading 64 bytes from p1 and p2. - const uint64_t mask = _mm512_cmpneq_epi8_mask( + const uint64_t mask = _mm512_cmpneq_epi8_mask( // NOLINT cpp::bit_cast<__m512i>(load(p1)), cpp::bit_cast<__m512i>(load(p2))); const bool mask_is_set = mask != 0; return static_cast(mask_is_set); @@ -217,8 +217,8 @@ #if defined(__SSE2__) using T = char __attribute__((__vector_size__(16))); // A mask indicating which bytes differ after loading 16 bytes from p1 and p2. - if (int mask = - _mm_movemask_epi8(cpp::bit_cast<__m128i>(load(p1) != load(p2)))) + if (int mask = _mm_movemask_epi8( // NOLINT + cpp::bit_cast<__m128i>(load(p1) != load(p2)))) return char_diff_no_zero(p1, p2, mask); return MemcmpReturnType::ZERO(); #else @@ -235,7 +235,7 @@ #if defined(__AVX2__) using T = char __attribute__((__vector_size__(32))); // A mask indicating which bytes differ after loading 32 bytes from p1 and p2. - if (int mask = _mm256_movemask_epi8( + if (int mask = _mm256_movemask_epi8( // NOLINT cpp::bit_cast<__m256i>(load(p1) != load(p2)))) return char_diff_no_zero(p1, p2, mask); return MemcmpReturnType::ZERO(); @@ -253,9 +253,9 @@ #if defined(__AVX512BW__) using T = char __attribute__((__vector_size__(64))); // A mask indicating which bytes differ after loading 64 bytes from p1 and p2. - if (uint64_t mask = - _mm512_cmpneq_epi8_mask(cpp::bit_cast<__m512i>(load(p1)), - cpp::bit_cast<__m512i>(load(p2)))) + if (uint64_t mask = _mm512_cmpneq_epi8_mask( // NOLINT + cpp::bit_cast<__m512i>(load(p1)), + cpp::bit_cast<__m512i>(load(p2)))) return char_diff_no_zero(p1, p2, mask); return MemcmpReturnType::ZERO(); #else diff --git a/libc/src/string/memory_utils/utils.h b/libc/src/string/memory_utils/utils.h --- a/libc/src/string/memory_utils/utils.h +++ b/libc/src/string/memory_utils/utils.h @@ -12,8 +12,8 @@ #include "src/__support/CPP/bit.h" #include "src/__support/CPP/cstddef.h" #include "src/__support/CPP/type_traits.h" -#include "src/__support/macros/attributes.h" //LIBC_INLINE -#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN +#include "src/__support/macros/attributes.h" // LIBC_INLINE +#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN #include // size_t #include // intptr_t / uintptr_t @@ -28,29 +28,29 @@ } // Return whether `value` is zero or a power of two. -static constexpr bool is_power2_or_zero(size_t value) { +LIBC_INLINE static constexpr bool is_power2_or_zero(size_t value) { return (value & (value - 1U)) == 0; } // Return whether `value` is a power of two. -static constexpr bool is_power2(size_t value) { +LIBC_INLINE static constexpr bool is_power2(size_t value) { return value && is_power2_or_zero(value); } // Compile time version of log2 that handles 0. -static constexpr size_t log2(size_t value) { +LIBC_INLINE static constexpr size_t log2(size_t value) { return (value == 0 || value == 1) ? 0 : 1 + log2(value / 2); } // Returns the first power of two preceding value or value if it is already a // power of two (or 0 when value is 0). -static constexpr size_t le_power2(size_t value) { +LIBC_INLINE static constexpr size_t le_power2(size_t value) { return value == 0 ? value : 1ULL << log2(value); } // Returns the first power of two following value or value if it is already a // power of two (or 0 when value is 0). -static constexpr size_t ge_power2(size_t value) { +LIBC_INLINE static constexpr size_t ge_power2(size_t value) { return is_power2_or_zero(value) ? value : 1ULL << (log2(value) + 1); } @@ -112,20 +112,22 @@ // Can only be constructed from a T. template , bool> = 0> - StrictIntegralType(U value) : value(value) {} + LIBC_INLINE StrictIntegralType(U value) : value(value) {} + LIBC_INLINE ~StrictIntegralType() = default; // Allows using the type in an if statement. - explicit operator bool() const { return value; } + LIBC_INLINE explicit operator bool() const { return value; } // If type is unsigned (bcmp) we allow bitwise OR operations. - StrictIntegralType operator|(const StrictIntegralType &Rhs) const { + LIBC_INLINE StrictIntegralType + operator|(const StrictIntegralType &Rhs) const { static_assert(!cpp::is_signed_v); return value | Rhs.value; } // For interation with the C API we allow explicit conversion back to the // `int` type. - explicit operator int() const { + LIBC_INLINE explicit operator int() const { // bit_cast makes sure that T and int have the same size. return cpp::bit_cast(value); } @@ -143,9 +145,9 @@ // Loads bytes from memory (possibly unaligned) and materializes them as // type. template LIBC_INLINE T load(CPtr ptr) { - T Out; - memcpy_inline(&Out, ptr); - return Out; + T out; + memcpy_inline(&out, ptr); + return out; } // Stores a value of type T in memory (possibly unaligned). diff --git a/libc/src/string/string_utils.h b/libc/src/string/string_utils.h --- a/libc/src/string/string_utils.h +++ b/libc/src/string/string_utils.h @@ -15,6 +15,7 @@ #define LIBC_SRC_STRING_STRING_UTILS_H #include "src/__support/CPP/bitset.h" +#include "src/__support/common.h" // LIBC_INLINE #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY #include "src/string/memory_utils/bzero_implementations.h" #include "src/string/memory_utils/memcpy_implementations.h" @@ -23,7 +24,7 @@ namespace __llvm_libc { namespace internal { -template constexpr Word repeat_byte(Word byte) { +template LIBC_INLINE constexpr Word repeat_byte(Word byte) { constexpr size_t BITS_IN_BYTE = 8; constexpr size_t BYTE_MASK = 0xff; Word result = 0; @@ -49,7 +50,7 @@ // with the inverse of the original byte. This means that any byte that had the // high bit set will no longer have it set, narrowing the list of bytes which // result in non-zero values to just the zero byte. -template constexpr bool has_zeroes(Word block) { +template LIBC_INLINE constexpr bool has_zeroes(Word block) { constexpr Word LOW_BITS = repeat_byte(0x01); constexpr Word HIGH_BITS = repeat_byte(0x80); Word subtracted = block - LOW_BITS; diff --git a/libc/utils/HdrGen/PublicAPICommand.cpp b/libc/utils/HdrGen/PublicAPICommand.cpp --- a/libc/utils/HdrGen/PublicAPICommand.cpp +++ b/libc/utils/HdrGen/PublicAPICommand.cpp @@ -68,6 +68,8 @@ } OS << '\n'; + OS << "// NOLINTBEGIN\n"; + if (G.Enumerations.size() != 0) OS << "enum {" << '\n'; for (const auto &Name : G.Enumerations) { @@ -124,6 +126,8 @@ OS << "extern " << Type << " " << Name << ";\n"; } OS << "__END_C_DECLS\n"; + + OS << "// NOLINTEND\n"; } void writePublicAPI(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {}