[compiler-rt] [llvm] [MemProf] Change histogram storage from uint64_t to uint16_t (PR #147854)

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 29 13:46:02 PDT 2025


================
@@ -229,6 +228,41 @@ void Merge(const MemInfoBlock &newMIB) {
 } __attribute__((__packed__));
 #endif
 
+constexpr int MantissaBits = 12;
+constexpr int ExponentBits = 4;
+constexpr uint16_t MaxMantissa = (1U << MantissaBits) - 1;
+constexpr uint16_t MaxExponent = (1U << ExponentBits) - 1;
+
+// Encodes a 64-bit unsigned integer into a 16-bit scaled integer format.
+inline uint16_t encodeHistogramCount(uint64_t Count) {
+  if (Count == 0)
+    return 0;
+
+  const uint64_t MaxRepresentableValue = static_cast<uint64_t>(MaxMantissa)
----------------
snehasish wrote:

Done.

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


More information about the llvm-commits mailing list