diff options
| author | Sterling Augustine <saugustine@google.com> | 2022-10-14 11:17:46 -0700 |
|---|---|---|
| committer | Sterling Augustine <saugustine@google.com> | 2022-10-14 12:32:20 -0700 |
| commit | d8415b02a519f222ecf71b069c96cc85ac635de3 (patch) | |
| tree | d9377fe945b92f3898c7f2f168a18169a62b18c4 /libc/test/src/string/memory_utils/utils_test.cpp | |
| parent | ef774bec63b72a0e900b3ddf22da81efbecd99a9 (diff) | |
Revert "[libc] New version of the mem* framework"
This reverts commit https://reviews.llvm.org/D135134 (b3f1d58a131eb546aaf1ac165c77ccb89c40d758)
That revision appears to have broken Arm memcpy in some subtle
ways. Am communicating with the original author to get a
good reproduction.
Diffstat (limited to 'libc/test/src/string/memory_utils/utils_test.cpp')
| -rw-r--r-- | libc/test/src/string/memory_utils/utils_test.cpp | 79 |
1 files changed, 53 insertions, 26 deletions
diff --git a/libc/test/src/string/memory_utils/utils_test.cpp b/libc/test/src/string/memory_utils/utils_test.cpp index 5c7920c4960b..a20c0900b723 100644 --- a/libc/test/src/string/memory_utils/utils_test.cpp +++ b/libc/test/src/string/memory_utils/utils_test.cpp @@ -72,41 +72,55 @@ TEST(LlvmLibcUtilsTest, GEPowerOf2) { EXPECT_EQ(ge_power2(i), kExpectedValues[i]); } -using UINT = uintptr_t; +using I = intptr_t; // Converts an offset into a pointer. const void *forge(size_t offset) { return reinterpret_cast<const void *>(offset); } -TEST(LlvmLibcUtilsTest, DistanceToNextAligned) { - EXPECT_EQ(distance_to_next_aligned<16>(forge(0)), UINT(16)); - EXPECT_EQ(distance_to_next_aligned<16>(forge(1)), UINT(15)); - EXPECT_EQ(distance_to_next_aligned<16>(forge(16)), UINT(16)); - EXPECT_EQ(distance_to_next_aligned<16>(forge(15)), UINT(1)); - EXPECT_EQ(distance_to_next_aligned<32>(forge(16)), UINT(16)); +TEST(LlvmLibcUtilsTest, OffsetToNextAligned) { + EXPECT_EQ(offset_to_next_aligned<16>(forge(0)), I(0)); + EXPECT_EQ(offset_to_next_aligned<16>(forge(1)), I(15)); + EXPECT_EQ(offset_to_next_aligned<16>(forge(16)), I(0)); + EXPECT_EQ(offset_to_next_aligned<16>(forge(15)), I(1)); + EXPECT_EQ(offset_to_next_aligned<32>(forge(16)), I(16)); } -TEST(LlvmLibcUtilsTest, DistanceToAlignUp) { - EXPECT_EQ(distance_to_align_up<16>(forge(0)), UINT(0)); - EXPECT_EQ(distance_to_align_up<16>(forge(1)), UINT(15)); - EXPECT_EQ(distance_to_align_up<16>(forge(16)), UINT(0)); - EXPECT_EQ(distance_to_align_up<16>(forge(15)), UINT(1)); - EXPECT_EQ(distance_to_align_up<32>(forge(16)), UINT(16)); +TEST(LlvmLibcUtilsTest, OffsetFromLastAligned) { + EXPECT_EQ(offset_from_last_aligned<16>(forge(0)), I(0)); + EXPECT_EQ(offset_from_last_aligned<16>(forge(1)), I(1)); + EXPECT_EQ(offset_from_last_aligned<16>(forge(16)), I(0)); + EXPECT_EQ(offset_from_last_aligned<16>(forge(15)), I(15)); + EXPECT_EQ(offset_from_last_aligned<32>(forge(16)), I(16)); } -TEST(LlvmLibcUtilsTest, DistanceToAlignDown) { - EXPECT_EQ(distance_to_align_down<16>(forge(0)), UINT(0)); - EXPECT_EQ(distance_to_align_down<16>(forge(1)), UINT(1)); - EXPECT_EQ(distance_to_align_down<16>(forge(16)), UINT(0)); - EXPECT_EQ(distance_to_align_down<16>(forge(15)), UINT(15)); - EXPECT_EQ(distance_to_align_down<32>(forge(16)), UINT(16)); +TEST(LlvmLibcUtilsTest, OffsetToNextCacheLine) { + EXPECT_GT(LLVM_LIBC_CACHELINE_SIZE, 0); + EXPECT_EQ(offset_to_next_cache_line(forge(0)), I(0)); + EXPECT_EQ(offset_to_next_cache_line(forge(1)), + I(LLVM_LIBC_CACHELINE_SIZE - 1)); + EXPECT_EQ(offset_to_next_cache_line(forge(LLVM_LIBC_CACHELINE_SIZE)), I(0)); + EXPECT_EQ(offset_to_next_cache_line(forge(LLVM_LIBC_CACHELINE_SIZE - 1)), + I(1)); +} + +TEST(LlvmLibcUtilsTest, Adjust1) { + char a; + const size_t base_size = 10; + for (size_t I = -2; I < 2; ++I) { + auto *ptr = &a; + size_t size = base_size; + adjust(I, ptr, size); + EXPECT_EQ(intptr_t(ptr), intptr_t(&a + I)); + EXPECT_EQ(size, base_size - I); + } } TEST(LlvmLibcUtilsTest, Adjust2) { char a, b; const size_t base_size = 10; - for (ptrdiff_t I = -2; I < 2; ++I) { + for (size_t I = -2; I < 2; ++I) { auto *p1 = &a; auto *p2 = &b; size_t size = base_size; @@ -117,6 +131,19 @@ TEST(LlvmLibcUtilsTest, Adjust2) { } } +TEST(LlvmLibcUtilsTest, Align1) { + char a; + const size_t base_size = 10; + { + auto *ptr = &a; + size_t size = base_size; + align<128>(ptr, size); + EXPECT_TRUE(uintptr_t(ptr) % 128 == 0); + EXPECT_GE(ptr, &a); + EXPECT_EQ(size_t(ptr - &a), base_size - size); + } +} + TEST(LlvmLibcUtilsTest, Align2) { char a, b; const size_t base_size = 10; @@ -124,10 +151,10 @@ TEST(LlvmLibcUtilsTest, Align2) { auto *p1 = &a; auto *p2 = &b; size_t size = base_size; - align_to_next_boundary<128, Arg::P1>(p1, p2, size); + align<128, Arg::_1>(p1, p2, size); EXPECT_TRUE(uintptr_t(p1) % 128 == 0); - EXPECT_GT(p1, &a); - EXPECT_GT(p2, &b); + EXPECT_GE(p1, &a); + EXPECT_GE(p2, &b); EXPECT_EQ(size_t(p1 - &a), base_size - size); EXPECT_EQ(size_t(p2 - &b), base_size - size); } @@ -135,10 +162,10 @@ TEST(LlvmLibcUtilsTest, Align2) { auto *p1 = &a; auto *p2 = &b; size_t size = base_size; - align_to_next_boundary<128, Arg::P2>(p1, p2, size); + align<128, Arg::_2>(p1, p2, size); EXPECT_TRUE(uintptr_t(p2) % 128 == 0); - EXPECT_GT(p1, &a); - EXPECT_GT(p2, &b); + EXPECT_GE(p1, &a); + EXPECT_GE(p2, &b); EXPECT_EQ(size_t(p1 - &a), base_size - size); EXPECT_EQ(size_t(p2 - &b), base_size - size); } |
