[libc] [llvm] [libc] Adding a version of memset with software prefetching (PR #70857)

Guillaume Chatelet via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 7 04:17:42 PST 2023


================
@@ -37,29 +40,55 @@ inline_memset_x86(Ptr dst, uint8_t value, size_t count) {
   using uint512_t = cpp::array<uint64_t, 8>;
 #endif
 
-  if (count == 0)
-    return;
-  if (count == 1)
-    return generic::Memset<uint8_t>::block(dst, value);
-  if (count == 2)
-    return generic::Memset<uint16_t>::block(dst, value);
-  if (count == 3)
-    return generic::MemsetSequence<uint16_t, uint8_t>::block(dst, value);
-  if (count <= 8)
-    return generic::Memset<uint32_t>::head_tail(dst, value, count);
-  if (count <= 16)
-    return generic::Memset<uint64_t>::head_tail(dst, value, count);
-  if (count <= 32)
-    return generic::Memset<uint128_t>::head_tail(dst, value, count);
-  if (count <= 64)
-    return generic::Memset<uint256_t>::head_tail(dst, value, count);
-  if (count <= 128)
-    return generic::Memset<uint512_t>::head_tail(dst, value, count);
-  // Aligned loop
-  generic::Memset<uint256_t>::block(dst, value);
-  align_to_next_boundary<32>(dst, count);
-  return generic::Memset<uint256_t>::loop_and_tail(dst, value, count);
-}
+  [[maybe_unused]] LIBC_INLINE static void
+  inline_memset_x86_sw_prefetching(Ptr dst, uint8_t value, size_t count) {
----------------
gchatelet wrote:

This function is quite tied to its caller. It is only valid if cases up to 64 have been handled beforehand.
Can you draw inspiration from `src/string/memory_utils/x86_64/inline_memcpy.h` and rename the function so the name conveys this information (e.g. `inline_memcpy_x86_sse2_ge64_sw_prefetching`).

https://github.com/llvm/llvm-project/pull/70857


More information about the llvm-commits mailing list