Skip to content

Commit

Permalink
[libc][NFC] Fix some issues with LIBC_INLINE
Browse files Browse the repository at this point in the history
We define LIBC_INLINE to include [[clang::internal_linkage]], and these
must appear before other specifiers. Additionally, there was also a
missing cast that was causing warnings.

Differential Revision: https://reviews.llvm.org/D152865
  • Loading branch information
abrachet committed Jun 14, 2023
1 parent 6a6c7ed commit 10e7b45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 6 additions & 4 deletions libc/src/string/memory_utils/op_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,13 @@ template <typename T> LIBC_INLINE static T load_be(CPtr ptr, size_t offset) {

// Equality: returns true iff values at locations (p1 + offset) and (p2 +
// offset) compare equal.
template <typename T> static bool eq(CPtr p1, CPtr p2, size_t offset);
template <typename T>
LIBC_INLINE static bool eq(CPtr p1, CPtr p2, size_t offset);

// Not equals: returns non-zero iff values at locations (p1 + offset) and (p2 +
// offset) differ.
template <typename T> static uint32_t neq(CPtr p1, CPtr p2, size_t offset);
template <typename T>
LIBC_INLINE static uint32_t neq(CPtr p1, CPtr p2, size_t offset);

// Lexicographic comparison:
// - returns 0 iff values at locations (p1 + offset) and (p2 + offset) compare
Expand All @@ -345,15 +347,15 @@ template <typename T> static uint32_t neq(CPtr p1, CPtr p2, size_t offset);
// - returns a positive value if value at location (p1 + offset) is
// lexicographically greater than value at (p2 + offset).
template <typename T>
static MemcmpReturnType cmp(CPtr p1, CPtr p2, size_t offset);
LIBC_INLINE static MemcmpReturnType cmp(CPtr p1, CPtr p2, size_t offset);

// Lexicographic comparison of non-equal values:
// - returns a negative value if value at location (p1 + offset) is
// lexicographically less than value at (p2 + offset).
// - returns a positive value if value at location (p1 + offset) is
// lexicographically greater than value at (p2 + offset).
template <typename T>
static MemcmpReturnType cmp_neq(CPtr p1, CPtr p2, size_t offset);
LIBC_INLINE static MemcmpReturnType cmp_neq(CPtr p1, CPtr p2, size_t offset);

///////////////////////////////////////////////////////////////////////////////
// Memcmp implementation
Expand Down
15 changes: 8 additions & 7 deletions libc/src/string/memory_utils/op_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
namespace __llvm_libc::x86 {

// A set of constants to check compile time features.
static LIBC_INLINE constexpr bool kSse2 = LLVM_LIBC_IS_DEFINED(__SSE2__);
static LIBC_INLINE constexpr bool kSse41 = LLVM_LIBC_IS_DEFINED(__SSE4_1__);
static LIBC_INLINE constexpr bool kAvx = LLVM_LIBC_IS_DEFINED(__AVX__);
static LIBC_INLINE constexpr bool kAvx2 = LLVM_LIBC_IS_DEFINED(__AVX2__);
static LIBC_INLINE constexpr bool kAvx512F = LLVM_LIBC_IS_DEFINED(__AVX512F__);
static LIBC_INLINE constexpr bool kAvx512BW =
LIBC_INLINE static constexpr bool kSse2 = LLVM_LIBC_IS_DEFINED(__SSE2__);
LIBC_INLINE static constexpr bool kSse41 = LLVM_LIBC_IS_DEFINED(__SSE4_1__);
LIBC_INLINE static constexpr bool kAvx = LLVM_LIBC_IS_DEFINED(__AVX__);
LIBC_INLINE static constexpr bool kAvx2 = LLVM_LIBC_IS_DEFINED(__AVX2__);
LIBC_INLINE static constexpr bool kAvx512F = LLVM_LIBC_IS_DEFINED(__AVX512F__);
LIBC_INLINE static constexpr bool kAvx512BW =
LLVM_LIBC_IS_DEFINED(__AVX512BW__);

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -130,7 +130,8 @@ LIBC_INLINE __m128i bytewise_reverse(__m128i value) {
8, 9, 10, 11, 12, 13, 14, 15));
}
LIBC_INLINE uint16_t big_endian_cmp_mask(__m128i max, __m128i value) {
return _mm_movemask_epi8(bytewise_reverse(_mm_cmpeq_epi8(max, value)));
return static_cast<uint16_t>(
_mm_movemask_epi8(bytewise_reverse(_mm_cmpeq_epi8(max, value))));
}
template <> LIBC_INLINE bool eq<__m128i>(CPtr p1, CPtr p2, size_t offset) {
const auto a = load<__m128i>(p1, offset);
Expand Down

0 comments on commit 10e7b45

Please sign in to comment.