[libc-commits] [libc] 10e7b45 - [libc][NFC] Fix some issues with LIBC_INLINE

Alex Brachet via libc-commits libc-commits at lists.llvm.org
Wed Jun 14 07:09:18 PDT 2023


Author: Alex Brachet
Date: 2023-06-14T14:09:11Z
New Revision: 10e7b451ada5ff87adb2e04cc6a21b5305e90b12

URL: https://github.com/llvm/llvm-project/commit/10e7b451ada5ff87adb2e04cc6a21b5305e90b12
DIFF: https://github.com/llvm/llvm-project/commit/10e7b451ada5ff87adb2e04cc6a21b5305e90b12.diff

LOG: [libc][NFC] Fix some issues with LIBC_INLINE

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

Added: 
    

Modified: 
    libc/src/string/memory_utils/op_generic.h
    libc/src/string/memory_utils/op_x86.h

Removed: 
    


################################################################################
diff  --git a/libc/src/string/memory_utils/op_generic.h b/libc/src/string/memory_utils/op_generic.h
index b2c8fa2c599a9..3e296857a05a3 100644
--- a/libc/src/string/memory_utils/op_generic.h
+++ b/libc/src/string/memory_utils/op_generic.h
@@ -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) 
diff er.
-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
@@ -345,7 +347,7 @@ 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
@@ -353,7 +355,7 @@ static MemcmpReturnType cmp(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_neq(CPtr p1, CPtr p2, size_t offset);
+LIBC_INLINE static MemcmpReturnType cmp_neq(CPtr p1, CPtr p2, size_t offset);
 
 ///////////////////////////////////////////////////////////////////////////////
 // Memcmp implementation

diff  --git a/libc/src/string/memory_utils/op_x86.h b/libc/src/string/memory_utils/op_x86.h
index 1d82706eef49c..a0c8d3aba4e80 100644
--- a/libc/src/string/memory_utils/op_x86.h
+++ b/libc/src/string/memory_utils/op_x86.h
@@ -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__);
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -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);


        


More information about the libc-commits mailing list