[llvm-branch-commits] [libc] ab57780 - [libc] Refresh benchmark progress bar when needed.

2021-01-13 Thread Guillaume Chatelet via llvm-branch-commits

Author: Guillaume Chatelet
Date: 2021-01-13T14:06:51Z
New Revision: ab577807165c45abfbadc117125ec7275cdcc0cf

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

LOG: [libc] Refresh benchmark progress bar when needed.

Added: 


Modified: 
libc/benchmarks/LibcMemoryBenchmarkMain.cpp

Removed: 




diff  --git a/libc/benchmarks/LibcMemoryBenchmarkMain.cpp 
b/libc/benchmarks/LibcMemoryBenchmarkMain.cpp
index 99c5879397d9..770336e3205c 100644
--- a/libc/benchmarks/LibcMemoryBenchmarkMain.cpp
+++ b/libc/benchmarks/LibcMemoryBenchmarkMain.cpp
@@ -262,17 +262,21 @@ template  struct MemfunctionBenchmark 
: IBenchmark {
 };
   }
 
-  void reportProgress(BenchmarkStatus BS) {
+  void reportProgress() {
+static size_t LastPercent = -1;
 const size_t TotalSteps = Study.Measurements.capacity();
 const size_t Steps = Study.Measurements.size();
 const size_t Percent = 100 * Steps / TotalSteps;
+if (Percent == LastPercent)
+  return;
+LastPercent = Percent;
 size_t I = 0;
 errs() << '[';
 for (; I <= Percent; ++I)
   errs() << '#';
 for (; I <= 100; ++I)
   errs() << '_';
-errs() << "] " << Percent << "%\r";
+errs() << "] " << Percent << '%' << '\r';
   }
 
   void runTrials(const BenchmarkOptions &Options,
@@ -283,7 +287,7 @@ template  struct MemfunctionBenchmark : 
IBenchmark {
 for (size_t i = 0; i < NumTrials; ++i) {
   const BenchmarkResult Result = benchmark(Options, B, B.functor());
   Study.Measurements.push_back(Result.BestGuess);
-  reportProgress(Result.TerminationStatus);
+  reportProgress();
 }
   }
 
@@ -330,6 +334,7 @@ void writeStudy(const Study &S) {
.concat(Output));
   json::OStream JOS(FOS);
   serializeToJson(S, JOS);
+  FOS << "\n";
 }
 
 void main() {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] a10300a - [libc] Allow customization of memcpy via flags.

2021-01-15 Thread Guillaume Chatelet via llvm-branch-commits

Author: Guillaume Chatelet
Date: 2021-01-15T09:26:45Z
New Revision: a10300a2b27c426556f9266364337d5d546a3c14

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

LOG: [libc] Allow customization of memcpy via flags.

 - Adds LLVM_LIBC_IS_DEFINED macro to libc/src/__support/common.h
 - Adds a few knobs to memcpy to help with experimentations:
   - LLVM_LIBC_MEMCPY_X86_USE_ONLY_REPMOVSB replaces the implementation with a 
single call to rep;movsb
   - LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE customizes where the usage of 
rep;movsb

Differential Revision: https://reviews.llvm.org/D94692

Added: 


Modified: 
libc/src/__support/common.h
libc/src/string/x86/memcpy.cpp

Removed: 




diff  --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index 208c8bdfea41..53a63fc2e917 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -29,4 +29,27 @@
 #define LLVM_LIBC_FUNCTION(type, name, arglist) type name arglist
 #endif
 
+namespace __llvm_libc {
+namespace internal {
+constexpr bool same_string(char const *lhs, char const *rhs) {
+  for (; *lhs || *rhs; ++lhs, ++rhs)
+if (*lhs != *rhs)
+  return false;
+  return true;
+}
+} // namespace internal
+} // namespace __llvm_libc
+
+// LLVM_LIBC_IS_DEFINED checks whether a particular macro is defined.
+// Usage: constexpr bool kUseAvx = LLVM_LIBC_IS_DEFINED(__AVX__);
+//
+// This works by comparing the stringified version of the macro with and 
without
+// evaluation. If FOO is not undefined both stringifications yield "FOO". If 
FOO
+// is defined, one stringification yields "FOO" while the other yields its
+// stringified value "1".
+#define LLVM_LIBC_IS_DEFINED(macro)
\
+  !__llvm_libc::internal::same_string( 
\
+  LLVM_LIBC_IS_DEFINED__EVAL_AND_STRINGIZE(macro), #macro)
+#define LLVM_LIBC_IS_DEFINED__EVAL_AND_STRINGIZE(s) #s
+
 #endif // LLVM_LIBC_SUPPORT_COMMON_H

diff  --git a/libc/src/string/x86/memcpy.cpp b/libc/src/string/x86/memcpy.cpp
index 7c5740ba00e8..b9163d978bef 100644
--- a/libc/src/string/x86/memcpy.cpp
+++ b/libc/src/string/x86/memcpy.cpp
@@ -12,6 +12,26 @@
 
 namespace __llvm_libc {
 
+// Whether to use only rep;movsb.
+constexpr bool kUseOnlyRepMovsb =
+LLVM_LIBC_IS_DEFINED(LLVM_LIBC_MEMCPY_X86_USE_ONLY_REPMOVSB);
+
+// kRepMovsBSize == -1 : Only CopyAligned is used.
+// kRepMovsBSize ==  0 : Only RepMovsb is used.
+// else CopyAligned is used up to kRepMovsBSize and then RepMovsb.
+constexpr size_t kRepMovsBSize =
+#ifdef LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE
+LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE;
+#else
+-1;
+#endif // LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE
+
+// Whether target supports AVX instructions.
+constexpr bool kHasAvx = LLVM_LIBC_IS_DEFINED(__AVX__);
+
+// The chunk size used for the loop copy strategy.
+constexpr size_t kLoopCopyBlockSize = kHasAvx ? 64 : 32;
+
 static void CopyRepMovsb(char *__restrict dst, const char *__restrict src,
  size_t count) {
   // FIXME: Add MSVC support with
@@ -21,12 +41,6 @@ static void CopyRepMovsb(char *__restrict dst, const char 
*__restrict src,
   asm volatile("rep movsb" : "+D"(dst), "+S"(src), "+c"(count) : : "memory");
 }
 
-#if defined(__AVX__)
-#define BEST_SIZE 64
-#else
-#define BEST_SIZE 32
-#endif
-
 // Design rationale
 // 
 //
@@ -47,6 +61,9 @@ static void CopyRepMovsb(char *__restrict dst, const char 
*__restrict src,
 //   with little change on the code side.
 static void memcpy_x86(char *__restrict dst, const char *__restrict src,
size_t count) {
+  if (kUseOnlyRepMovsb)
+return CopyRepMovsb(dst, src, count);
+
   if (count == 0)
 return;
   if (count == 1)
@@ -67,16 +84,10 @@ static void memcpy_x86(char *__restrict dst, const char 
*__restrict src,
 return CopyBlockOverlap<32>(dst, src, count);
   if (count < 128)
 return CopyBlockOverlap<64>(dst, src, count);
-#if defined(__AVX__)
-  if (count < 256)
+  if (kHasAvx && count < 256)
 return CopyBlockOverlap<128>(dst, src, count);
-#endif
-  // kRepMovsBSize == -1 : Only CopyAligned is used.
-  // kRepMovsBSize ==  0 : Only RepMovsb is used.
-  // else CopyAligned is used to to kRepMovsBSize and then RepMovsb.
-  constexpr size_t kRepMovsBSize = -1;
   if (count <= kRepMovsBSize)
-return CopyAlignedBlocks(dst, src, count);
+return CopyAlignedBlocks(dst, src, count);
   return CopyRepMovsb(dst, src, count);
 }
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] 5bf47e1 - [libc] CopyAlignedBlocks can now specify alignment on top of block size

2021-01-15 Thread Guillaume Chatelet via llvm-branch-commits

Author: Guillaume Chatelet
Date: 2021-01-15T15:32:02Z
New Revision: 5bf47e142b6ebe1baf0cab257800c27a1a3bbde7

URL: 
https://github.com/llvm/llvm-project/commit/5bf47e142b6ebe1baf0cab257800c27a1a3bbde7
DIFF: 
https://github.com/llvm/llvm-project/commit/5bf47e142b6ebe1baf0cab257800c27a1a3bbde7.diff

LOG: [libc] CopyAlignedBlocks can now specify alignment on top of block size

This has been requested in D92236

Differential Revision: https://reviews.llvm.org/D94770

Added: 


Modified: 
libc/src/string/memory_utils/memcpy_utils.h
libc/src/string/memory_utils/utils.h
libc/test/src/string/memory_utils/memcpy_utils_test.cpp

Removed: 




diff  --git a/libc/src/string/memory_utils/memcpy_utils.h 
b/libc/src/string/memory_utils/memcpy_utils.h
index 1e7d907d2333..44b88374e20f 100644
--- a/libc/src/string/memory_utils/memcpy_utils.h
+++ b/libc/src/string/memory_utils/memcpy_utils.h
@@ -72,28 +72,35 @@ static void CopyBlockOverlap(char *__restrict dst, const 
char *__restrict src,
 
 // Copies `count` bytes by blocks of `kBlockSize` bytes.
 // Copies at the start and end of the buffer are unaligned.
-// Copies in the middle of the buffer are aligned to `kBlockSize`.
+// Copies in the middle of the buffer are aligned to `kAlignment`.
 //
 // e.g. with
 // [12345678123456781234567812345678]
-// [__XXX___]
-// [____]
-// []
-// []
-// [____]
+// [_____]
+// [_____]
+// [_]
+// [_]
+// [_]
+// [_____]
 //
-// Precondition: `count > 2 * kBlockSize` for efficiency.
-//   `count >= kBlockSize` for correctness.
-template 
+// Precondition: `kAlignment <= kBlockSize`
+//   `count > 2 * kBlockSize` for efficiency.
+//   `count >= kAlignment` for correctness.
+template 
 static void CopyAlignedBlocks(char *__restrict dst, const char *__restrict src,
   size_t count) {
-  CopyBlock(dst, src); // Copy first block
+  static_assert(is_power2(kAlignment), "kAlignment must be a power of two");
+  static_assert(is_power2(kBlockSize), "kBlockSize must be a power of two");
+  static_assert(kAlignment <= kBlockSize,
+"kAlignment must be less or equal to block size");
+  CopyBlock(dst, src); // Copy first block
 
   // Copy aligned blocks
-  const size_t ofla = offset_from_last_aligned(src);
+  const size_t ofla = offset_from_last_aligned(src);
   const size_t limit = count + ofla - kBlockSize;
-  for (size_t offset = kBlockSize; offset < limit; offset += kBlockSize)
-CopyBlock(dst - ofla + offset, src - ofla + offset);
+  for (size_t offset = kAlignment; offset < limit; offset += kBlockSize)
+CopyBlock(dst - ofla + offset,
+  assume_aligned(src - ofla + offset));
 
   CopyLastBlock(dst, src, count); // Copy last block
 }

diff  --git a/libc/src/string/memory_utils/utils.h 
b/libc/src/string/memory_utils/utils.h
index 401c7767a59e..c2472c20ab78 100644
--- a/libc/src/string/memory_utils/utils.h
+++ b/libc/src/string/memory_utils/utils.h
@@ -60,6 +60,10 @@ static inline intptr_t offset_to_next_cache_line(const void 
*ptr) {
   return offset_to_next_aligned(ptr);
 }
 
+template  static T *assume_aligned(T *ptr) {
+  return reinterpret_cast(__builtin_assume_aligned(ptr, alignment));
+}
+
 } // namespace __llvm_libc
 
 #endif // LLVM_LIBC_SRC_MEMORY_UTILS_H

diff  --git a/libc/test/src/string/memory_utils/memcpy_utils_test.cpp 
b/libc/test/src/string/memory_utils/memcpy_utils_test.cpp
index d466495357c2..d45794710862 100644
--- a/libc/test/src/string/memory_utils/memcpy_utils_test.cpp
+++ b/libc/test/src/string/memory_utils/memcpy_utils_test.cpp
@@ -211,7 +211,24 @@ TEST(MemcpyUtilsTest, CopyAlignedBlocks) {
   EXPECT_STREQ(trace.Read(), "01112111");
 }
 
-TEST(MemcpyUtilsTest, MaxReloads) {
+TEST(MemcpyUtilsTest, CopyAlignedBlocksWithAlignment) {
+  auto &trace = GetTrace();
+  // Source is aligned and multiple of alignment.
+  //   ""
+  trace.Clear();
+  CopyAlignedBlocks<8, 4>(I(0), I(0), 8);
+  EXPECT_STREQ(trace.Write(), "");
+  EXPECT_STREQ(trace.Read(), "");
+
+  // Source is aligned and multiple of alignment.
+  //   "1"
+  trace.Clear();
+  CopyAlignedBlocks<8, 4>(I(0), I(0), 9);
+  EXPECT_STREQ(trace.Write(), "12221");
+  EXPECT_STREQ(trace.Read(), "12221");
+}
+
+TEST(MemcpyUtilsTest, CopyAlignedBlocksMaxReloads) {
   auto &trace = GetTrace();
   for (size_t alignment = 0; alignment < 32; ++alignment) {
 for (size_t count = 64; count < 768; ++count) {
@@ -231,4 +248,24 @@ TEST(MemcpyUtilsTest, MaxReloads) {
   }
 }
 
+TEST(MemcpyUtilsTest, CopyAlignedBlocks

[llvm-branch-commits] [libc] d4bb3ef - [libc][NFC] Remove dead code

2021-01-19 Thread Guillaume Chatelet via llvm-branch-commits

Author: Guillaume Chatelet
Date: 2021-01-19T08:11:45Z
New Revision: d4bb3ef53276213d3ba8987da5f76f423b86160d

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

LOG: [libc][NFC] Remove dead code

Added: 


Modified: 
libc/benchmarks/JSON.cpp
libc/benchmarks/LibcMemoryBenchmarkMain.cpp

Removed: 




diff  --git a/libc/benchmarks/JSON.cpp b/libc/benchmarks/JSON.cpp
index 24e41b3bf86a..f2a9d8b27f48 100644
--- a/libc/benchmarks/JSON.cpp
+++ b/libc/benchmarks/JSON.cpp
@@ -136,11 +136,6 @@ static Error fromJson(const json::Value &V, std::vector 
&Out) {
   return vectorFromJsonTemplate(V, Out);
 }
 
-template 
-static Error fromJson(const json::Value &V, SmallVectorImpl &Out) {
-  return vectorFromJsonTemplate(V, Out);
-}
-
 // Same as llvm::json::ObjectMapper but adds a finer error reporting mechanism.
 class JsonObjectMapper {
   const json::Object *O;

diff  --git a/libc/benchmarks/LibcMemoryBenchmarkMain.cpp 
b/libc/benchmarks/LibcMemoryBenchmarkMain.cpp
index 770336e3205c..02b62bc74029 100644
--- a/libc/benchmarks/LibcMemoryBenchmarkMain.cpp
+++ b/libc/benchmarks/LibcMemoryBenchmarkMain.cpp
@@ -120,7 +120,6 @@ template  struct Harness : Benchmark {
   std::function SizeSampler,
   std::function OffsetSampler)
   : Benchmark(BufferSize), BufferSize(BufferSize),
-BatchParameterCount(BatchParameterCount),
 Parameters(BatchParameterCount), SizeSampler(SizeSampler),
 OffsetSampler(OffsetSampler) {}
 
@@ -136,7 +135,6 @@ template  struct Harness : Benchmark {
 
 private:
   const size_t BufferSize;
-  const size_t BatchParameterCount;
   std::vector Parameters;
   std::function SizeSampler;
   std::function OffsetSampler;



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] e517dff - [libc][NFC] remove dependency on non standard ssize_t

2021-01-19 Thread Guillaume Chatelet via llvm-branch-commits

Author: Guillaume Chatelet
Date: 2021-01-19T08:12:38Z
New Revision: e517dff50a4f933d0729026901b14c7c1112a359

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

LOG: [libc][NFC] remove dependency on non standard ssize_t

`ssize_t` is from POSIX and is not standard unfortunately.
Rewritting the code so it doesn't depend on it.

Differential Revision: https://reviews.llvm.org/D94760

Added: 


Modified: 
libc/src/string/memmove.cpp

Removed: 




diff  --git a/libc/src/string/memmove.cpp b/libc/src/string/memmove.cpp
index 8958027d1d58..0d4d3d174839 100644
--- a/libc/src/string/memmove.cpp
+++ b/libc/src/string/memmove.cpp
@@ -11,21 +11,25 @@
 #include "src/stdlib/abs_utils.h"
 #include "src/string/memcpy.h"
 #include  // size_t, ptr
diff _t
-#include  // ssize_t
 
 namespace __llvm_libc {
 
-// src_m and dest_m might be the beginning or end.
-static inline void move_byte(unsigned char *dest_m, const unsigned char *src_m,
- size_t count, ssize_t direction) {
-  for (ssize_t offset = 0; count; --count, offset += direction)
+static inline void move_byte_forward(char *dest_m, const char *src_m,
+ size_t count) {
+  for (size_t offset = 0; count; --count, ++offset)
+dest_m[offset] = src_m[offset];
+}
+
+static inline void move_byte_backward(char *dest_m, const char *src_m,
+  size_t count) {
+  for (size_t offset = count - 1; count; --count, --offset)
 dest_m[offset] = src_m[offset];
 }
 
 LLVM_LIBC_FUNCTION(void *, memmove,
(void *dest, const void *src, size_t count)) {
-  unsigned char *dest_c = reinterpret_cast(dest);
-  const unsigned char *src_c = reinterpret_cast(src);
+  char *dest_c = reinterpret_cast(dest);
+  const char *src_c = reinterpret_cast(src);
 
   // If the distance between src_c and dest_c is equal to or greater
   // than count (integer_abs(src_c - dest_c) >= count), they would not overlap.
@@ -50,11 +54,11 @@ LLVM_LIBC_FUNCTION(void *, memmove,
   // src_c : [___abcde_]  [_abcde___]
   // dest_c: [_abc--___]  [___--cde_]
 
-  // TODO: Optimize `move_byte(...)` function.
+  // TODO: Optimize `move_byte_xxx(...)` functions.
   if (dest_c < src_c)
-move_byte(dest_c, src_c, count, /*pointer add*/ 1);
+move_byte_forward(dest_c, src_c, count);
   if (dest_c > src_c)
-move_byte(dest_c + count - 1, src_c + count - 1, count, /*pointer add*/ 
-1);
+move_byte_backward(dest_c, src_c, count);
   return dest;
 }
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] 223a6f9 - [libc] remove modulo from CircularArrayRef iterator

2021-01-06 Thread Guillaume Chatelet via llvm-branch-commits

Author: Guillaume Chatelet
Date: 2021-01-06T12:03:52Z
New Revision: 223a6f94c59c00733763bacc43f5b9458b4cc6f4

URL: 
https://github.com/llvm/llvm-project/commit/223a6f94c59c00733763bacc43f5b9458b4cc6f4
DIFF: 
https://github.com/llvm/llvm-project/commit/223a6f94c59c00733763bacc43f5b9458b4cc6f4.diff

LOG: [libc] remove modulo from CircularArrayRef iterator

Added: 


Modified: 
libc/benchmarks/LibcBenchmark.h

Removed: 




diff  --git a/libc/benchmarks/LibcBenchmark.h b/libc/benchmarks/LibcBenchmark.h
index 6516e5f8be94..af6173ab41a0 100644
--- a/libc/benchmarks/LibcBenchmark.h
+++ b/libc/benchmarks/LibcBenchmark.h
@@ -275,17 +275,21 @@ template  class CircularArrayRef {
   : public std::iterator {
 llvm::ArrayRef Array;
 size_t Index;
+size_t Offset;
 
   public:
 explicit const_iterator(llvm::ArrayRef Array, size_t Index = 0)
-: Array(Array), Index(Index) {}
+: Array(Array), Index(Index), Offset(Index % Array.size()) {}
 const_iterator &operator++() {
   ++Index;
+  ++Offset;
+  if (Offset == Array.size())
+Offset = 0;
   return *this;
 }
 bool operator==(const_iterator Other) const { return Index == Other.Index; 
}
 bool operator!=(const_iterator Other) const { return !(*this == Other); }
-const T &operator*() const { return Array[Index % Array.size()]; }
+const T &operator*() const { return Array[Offset]; }
   };
 
   CircularArrayRef(llvm::ArrayRef Array, size_t Size)



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] aa9db51 - [libc] Align src buffer instead of dst buffer

2021-01-06 Thread Guillaume Chatelet via llvm-branch-commits

Author: Guillaume Chatelet
Date: 2021-01-06T12:04:53Z
New Revision: aa9db51ef69f36775e9babd2f4b23142967784ee

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

LOG: [libc] Align src buffer instead of dst buffer

We used to align destination buffer instead of source buffer for the loop of 
block copy.
This is a mistake.

Differential Revision: https://reviews.llvm.org/D93457

Added: 


Modified: 
libc/src/string/memory_utils/memcpy_utils.h
libc/test/src/string/memory_utils/memcpy_utils_test.cpp

Removed: 




diff  --git a/libc/src/string/memory_utils/memcpy_utils.h 
b/libc/src/string/memory_utils/memcpy_utils.h
index aa27b3c38dbd..1e7d907d2333 100644
--- a/libc/src/string/memory_utils/memcpy_utils.h
+++ b/libc/src/string/memory_utils/memcpy_utils.h
@@ -90,7 +90,7 @@ static void CopyAlignedBlocks(char *__restrict dst, const 
char *__restrict src,
   CopyBlock(dst, src); // Copy first block
 
   // Copy aligned blocks
-  const size_t ofla = offset_from_last_aligned(dst);
+  const size_t ofla = offset_from_last_aligned(src);
   const size_t limit = count + ofla - kBlockSize;
   for (size_t offset = kBlockSize; offset < limit; offset += kBlockSize)
 CopyBlock(dst - ofla + offset, src - ofla + offset);

diff  --git a/libc/test/src/string/memory_utils/memcpy_utils_test.cpp 
b/libc/test/src/string/memory_utils/memcpy_utils_test.cpp
index 93c0c48c8976..d466495357c2 100644
--- a/libc/test/src/string/memory_utils/memcpy_utils_test.cpp
+++ b/libc/test/src/string/memory_utils/memcpy_utils_test.cpp
@@ -162,14 +162,14 @@ TEST(MemcpyUtilsTest, CopyBlockOverlap) {
 
 TEST(MemcpyUtilsTest, CopyAlignedBlocks) {
   auto &trace = GetTrace();
-  // Destination is aligned and multiple of alignment.
+  // Source is aligned and multiple of alignment.
   //   ""
   trace.Clear();
   CopyAlignedBlocks<4>(I(0), I(0), 4);
   EXPECT_STREQ(trace.Write(), "");
   EXPECT_STREQ(trace.Read(), "");
 
-  // Destination is aligned and multiple of alignment.
+  // Source is aligned and multiple of alignment.
   //   ""
   // + ""
   // = ""
@@ -178,7 +178,7 @@ TEST(MemcpyUtilsTest, CopyAlignedBlocks) {
   EXPECT_STREQ(trace.Write(), "");
   EXPECT_STREQ(trace.Read(), "");
 
-  // Destination is aligned already overlap at end.
+  // Source is aligned already overlap at end.
   //   "0"
   // + "0"
   // + "0"
@@ -189,26 +189,26 @@ TEST(MemcpyUtilsTest, CopyAlignedBlocks) {
   EXPECT_STREQ(trace.Write(), "12221");
   EXPECT_STREQ(trace.Read(), "12221");
 
-  // Misaligned destination.
+  // Misaligned source.
   //   "00"
   // + "00"
   // + "00"
   // + "00"
   // = "0111212211"
   trace.Clear();
-  CopyAlignedBlocks<4>(I(1), I(0), 13);
-  EXPECT_STREQ(trace.Write(), "0111212211");
-  EXPECT_STREQ(trace.Read(), "111212211");
+  CopyAlignedBlocks<4>(I(0), I(1), 13);
+  EXPECT_STREQ(trace.Write(), "111212211");
+  EXPECT_STREQ(trace.Read(), "0111212211");
 
-  // Misaligned destination aligned at end.
+  // Misaligned source aligned at end.
   //   "0000"
   // + ""
   // + ""
   // = "01112111"
   trace.Clear();
-  CopyAlignedBlocks<4>(I(1), I(0), 11);
-  EXPECT_STREQ(trace.Write(), "01112111");
-  EXPECT_STREQ(trace.Read(), "1112111");
+  CopyAlignedBlocks<4>(I(0), I(1), 11);
+  EXPECT_STREQ(trace.Write(), "1112111");
+  EXPECT_STREQ(trace.Read(), "01112111");
 }
 
 TEST(MemcpyUtilsTest, MaxReloads) {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] d899f99 - Fix case mismatch between definition and declaration

2020-11-25 Thread Guillaume Chatelet via llvm-branch-commits

Author: Guillaume Chatelet
Date: 2020-11-25T14:23:31Z
New Revision: d899f9970e51cb80114abdc4efb5c0d9ce435f80

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

LOG: Fix case mismatch between definition and declaration

Added: 


Modified: 
libc/benchmarks/MemorySizeDistributions.cpp

Removed: 




diff  --git a/libc/benchmarks/MemorySizeDistributions.cpp 
b/libc/benchmarks/MemorySizeDistributions.cpp
index 02c3d6414a66..02c8103d6980 100644
--- a/libc/benchmarks/MemorySizeDistributions.cpp
+++ b/libc/benchmarks/MemorySizeDistributions.cpp
@@ -28,7 +28,7 @@ static constexpr double kMemsetGoogleQ[] = {0, 0, 0.0043, 
0.0055, 0.0033, 0.0025
 static constexpr double kMemsetGoogleU[] = {0.1064, 0.0986, 0.0201, 0.0042, 
0.1506, 0.0276, 0.0028, 0.0033, 0.3233, 0.1282, 0.011, 0.0035, 0.0015, 0.0019, 
0.0005, 0.0007, 0.0143, 0.0152, 0.0005, 0.0146, 0.0013, 0.0001, 0.0001, 0.0067, 
0.0054, 0, 0.0001, 0, 0.0006, 0, 0.0002, 0.0062, 0.0005, 0, 0, 0, 0.0004, 0, 0, 
0.0001, 0.0003, 0, 0.0001, 0, 0.0001, 0.0001, 0, 0.0021, 0.0002, 0, 0, 0.0001, 
0.0001, 0.0001, 0, 0, 0.0001, 0.0001, 0, 0.0001, 0.0001, 0, 0.0001, 0, 0.0092, 
0, 0, 0, 0.0002, 0, 0, 0, 0.007, 0, 0, 0, 0, 0, 0, 0.0015, 0.0001, 0.0001, 0, 
0, 0.0001, 0, 0, 0, 0.0001, 0, 0, 0.0001, 0, 0, 0, 0.0001, 0.0001, 0, 0, 
0.0001, 0, 0, 0, 0, 0.0001, 0.0001, 0.0053, 0, 0.0001, 0, 0, 0, 0.0002, 0, 0, 
0, 0.0001, 0, 0, 0.0001, 0, 0, 0, 0.0001, 0, 0, 0, 0, 0.0001, 0, 0, 0, 0.0001, 
0, 0, 0, 0.0001, 0, 0, 0, 0, 0.0001, 0, 0.0012, 0.0001, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0.0001, 0, 0, 0, 0, 0, 0.0001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0.0001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0.0001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0001, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0.0001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0.0003, 0.0001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0.0002, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0.0001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0001, 
0, 0, 0, 0, 0, 0, 0, 0.0006, 0, 0, 0, 0, 0, 0, 0, 0.0001, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0.0001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0.0001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0001, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0.0001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0136, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0002, 0, 0, 0, 0, 0, 0, 0, 0, 0.0001, 0, 0, 
0, 0, 0, 0, 0, 0.0002, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0001, 0, 
0, 0, 0, 0, 0, 0, 0.0002, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0001, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0001};
 // clang-format on
 
-ArrayRef GetMemcpySizeDistributions() {
+ArrayRef getMemcpySizeDistributions() {
   static constexpr MemorySizeDistribution kDistributions[] = {
   {"memcpy Google A", kMemcpyGoogleA}, {"memcpy Google B", kMemcpyGoogleB},
   {"memcpy Google D", kMemcpyGoogleD}, {"memcpy Google L", kMemcpyGoogleL},
@@ -39,7 +39,7 @@ ArrayRef GetMemcpySizeDistributions() 
{
   return kDistributions;
 }
 
-ArrayRef GetMemsetSizeDistributions() {
+ArrayRef getMemsetSizeDistributions() {
   static constexpr MemorySizeDistribution kDistributions[] = {
   {"memset Google B", kMemsetGoogleB},
   {"memset Google D", kMemsetGoogleD},
@@ -49,7 +49,7 @@ ArrayRef GetMemsetSizeDistributions() 
{
   return kDistributions;
 }
 
-ArrayRef GetMemcmpSizeDistributions() {
+ArrayRef getMemcmpSizeDistributions() {
   static constexpr MemorySizeDistribution kDistributions[] = {
   {"memcmp Google A", kMemcmpGoogleA}, {"memcmp Google B", kMemcmpGoogleB},
   {"memcmp Google D", kMemcmpGoogleD}, {"memcmp Google L", kMemcmpGoogleL},



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libc] 699d17d - [libc] Improve memcpy copy loop

2020-11-30 Thread Guillaume Chatelet via llvm-branch-commits

Author: Guillaume Chatelet
Date: 2020-11-30T08:24:10Z
New Revision: 699d17d4d64e9b1cf6db0443e87a700104e94aca

URL: 
https://github.com/llvm/llvm-project/commit/699d17d4d64e9b1cf6db0443e87a700104e94aca
DIFF: 
https://github.com/llvm/llvm-project/commit/699d17d4d64e9b1cf6db0443e87a700104e94aca.diff

LOG: [libc] Improve memcpy copy loop

Rewriting loop so the terminating condition does not depend on the loop body

Differential Revision: https://reviews.llvm.org/D91976

Added: 


Modified: 
libc/src/string/memory_utils/memcpy_utils.h
libc/test/src/string/memory_utils/memcpy_utils_test.cpp

Removed: 




diff  --git a/libc/src/string/memory_utils/memcpy_utils.h 
b/libc/src/string/memory_utils/memcpy_utils.h
index a0e5ccc81c9e..aa27b3c38dbd 100644
--- a/libc/src/string/memory_utils/memcpy_utils.h
+++ b/libc/src/string/memory_utils/memcpy_utils.h
@@ -90,9 +90,10 @@ static void CopyAlignedBlocks(char *__restrict dst, const 
char *__restrict src,
   CopyBlock(dst, src); // Copy first block
 
   // Copy aligned blocks
-  size_t offset = kBlockSize - offset_from_last_aligned(dst);
-  for (; offset + kBlockSize < count; offset += kBlockSize)
-CopyBlock(dst + offset, src + offset);
+  const size_t ofla = offset_from_last_aligned(dst);
+  const size_t limit = count + ofla - kBlockSize;
+  for (size_t offset = kBlockSize; offset < limit; offset += kBlockSize)
+CopyBlock(dst - ofla + offset, src - ofla + offset);
 
   CopyLastBlock(dst, src, count); // Copy last block
 }

diff  --git a/libc/test/src/string/memory_utils/memcpy_utils_test.cpp 
b/libc/test/src/string/memory_utils/memcpy_utils_test.cpp
index 7e32fb4f3080..93c0c48c8976 100644
--- a/libc/test/src/string/memory_utils/memcpy_utils_test.cpp
+++ b/libc/test/src/string/memory_utils/memcpy_utils_test.cpp
@@ -162,7 +162,23 @@ TEST(MemcpyUtilsTest, CopyBlockOverlap) {
 
 TEST(MemcpyUtilsTest, CopyAlignedBlocks) {
   auto &trace = GetTrace();
-  // Destination is aligned already.
+  // Destination is aligned and multiple of alignment.
+  //   ""
+  trace.Clear();
+  CopyAlignedBlocks<4>(I(0), I(0), 4);
+  EXPECT_STREQ(trace.Write(), "");
+  EXPECT_STREQ(trace.Read(), "");
+
+  // Destination is aligned and multiple of alignment.
+  //   ""
+  // + ""
+  // = ""
+  trace.Clear();
+  CopyAlignedBlocks<4>(I(0), I(0), 8);
+  EXPECT_STREQ(trace.Write(), "");
+  EXPECT_STREQ(trace.Read(), "");
+
+  // Destination is aligned already overlap at end.
   //   "0"
   // + "0"
   // + "0"
@@ -173,7 +189,7 @@ TEST(MemcpyUtilsTest, CopyAlignedBlocks) {
   EXPECT_STREQ(trace.Write(), "12221");
   EXPECT_STREQ(trace.Read(), "12221");
 
-  // Misaligned destination
+  // Misaligned destination.
   //   "00"
   // + "00"
   // + "00"
@@ -183,6 +199,16 @@ TEST(MemcpyUtilsTest, CopyAlignedBlocks) {
   CopyAlignedBlocks<4>(I(1), I(0), 13);
   EXPECT_STREQ(trace.Write(), "0111212211");
   EXPECT_STREQ(trace.Read(), "111212211");
+
+  // Misaligned destination aligned at end.
+  //   "0000"
+  // + ""
+  // + ""
+  // = "01112111"
+  trace.Clear();
+  CopyAlignedBlocks<4>(I(1), I(0), 11);
+  EXPECT_STREQ(trace.Write(), "01112111");
+  EXPECT_STREQ(trace.Read(), "1112111");
 }
 
 TEST(MemcpyUtilsTest, MaxReloads) {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits