[llvm] [orc-rt] Implement Windows target triple detection (PR #224514)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 20 06:06:18 PDT 2026


================
@@ -125,9 +126,31 @@ template <typename T, typename _ = std::enable_if_t<std::is_unsigned_v<T>>>
   return ZeroBits;
 }
 
-template <typename T, typename _ = std::enable_if_t<std::is_unsigned_v<T>>>
-[[nodiscard]] constexpr int bit_width(T x) noexcept {
-  return std::numeric_limits<T>::digits - countl_zero(x);
+/// Returns the number of bits needed to represent Value if Value is nonzero.
+/// Returns 0 otherwise.
+///
+/// Ex. bit_width(5) == 3.
+template <typename T> [[nodiscard]] int bit_width(T Value) {
+  static_assert(std::is_unsigned_v<T>,
+                "Only unsigned integral types are allowed.");
+  return std::numeric_limits<T>::digits - orc_rt::countl_zero(Value);
+}
+
+/// Returns the number of bits needed to represent Value if Value is nonzero.
+/// Returns 0 otherwise.
+///
+/// A constexpr version of bit_width.
+///
+/// Ex. bit_width_constexpr(5) == 3.
+template <typename T> [[nodiscard]] constexpr int bit_width_constexpr(T Value) {
+  static_assert(std::is_unsigned_v<T>,
+                "Only unsigned integral types are allowed.");
+  int Width = 0;
+  while (Value > 0) {
+    Value >>= 1;
+    ++Width;
+  }
+  return Width;
----------------
lhames wrote:

Can the version that was there just be annotated with `constexpr`? If not go for your function body, but the signature should stay the same (SFINAE, noexcept)

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


More information about the llvm-commits mailing list