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

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 26 07:50:58 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)
----------------
teresajohnson wrote:

Can this be moved out of the function and made a constexpr like the other Max values above?

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


More information about the llvm-commits mailing list