[libc-commits] [libc] [libc] Refactor getL1DataCacheSize for const correctness (PR #85924)

via libc-commits libc-commits at lists.llvm.org
Wed Mar 20 05:09:02 PDT 2024


https://github.com/0x00006000 created https://github.com/llvm/llvm-project/pull/85924

None

>From 33a0d380da7c6a6e7cbc9e32754da3bdb17b69d7 Mon Sep 17 00:00:00 2001
From: 0x00006000 <160333148+0x00006000 at users.noreply.github.com>
Date: Wed, 20 Mar 2024 12:08:30 +0000
Subject: [PATCH] [libc] Refactor getL1DataCacheSize for const correctness

---
 libc/benchmarks/LibcMemoryBenchmark.cpp | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/libc/benchmarks/LibcMemoryBenchmark.cpp b/libc/benchmarks/LibcMemoryBenchmark.cpp
index 3ced306584d151..71cb24b359b01f 100644
--- a/libc/benchmarks/LibcMemoryBenchmark.cpp
+++ b/libc/benchmarks/LibcMemoryBenchmark.cpp
@@ -62,14 +62,18 @@ MismatchOffsetDistribution::MismatchOffsetDistribution(size_t BufferSize,
 }
 
 static size_t getL1DataCacheSize() {
-  const std::vector<CacheInfo> &CacheInfos = HostState::get().Caches;
-  const auto IsL1DataCache = [](const CacheInfo &CI) {
-    return CI.Type == "Data" && CI.Level == 1;
-  };
-  const auto CacheIt = find_if(CacheInfos, IsL1DataCache);
-  if (CacheIt != CacheInfos.end())
-    return CacheIt->Size;
-  report_fatal_error("Unable to read L1 Cache Data Size");
+    const std::vector<CacheInfo> &CacheInfos = HostState::get().Caches;
+
+    const auto IsL1DataCache = [](const CacheInfo &CI) constexpr {
+        return CI.Type == "Data" && CI.Level == 1;
+    };
+
+    const auto CacheIt = std::find_if(CacheInfos.begin(), CacheInfos.end(), IsL1DataCache);
+
+    if (CacheIt != CacheInfos.end())
+        return CacheIt->Size;
+
+    report_fatal_error("Unable to read L1 Cache Data Size");
 }
 
 static constexpr int64_t KiB = 1024;



More information about the libc-commits mailing list