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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: None (0x00006000)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/85924.diff


1 Files Affected:

- (modified) libc/benchmarks/LibcMemoryBenchmark.cpp (+12-8) 


``````````diff
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;

``````````

</details>


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


More information about the libc-commits mailing list