From 397905d29faa542e612538c7e52bddf24c6a224f Mon Sep 17 00:00:00 2001 From: Benjamin Aitchison Date: Tue, 10 Feb 2026 19:10:48 +1300 Subject: [PATCH] Fix exponential macro expansion in const_max! --- crates/rhdl-core/src/bitx/dyn_bit_manip.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/rhdl-core/src/bitx/dyn_bit_manip.rs b/crates/rhdl-core/src/bitx/dyn_bit_manip.rs index fef9eb96..25695493 100644 --- a/crates/rhdl-core/src/bitx/dyn_bit_manip.rs +++ b/crates/rhdl-core/src/bitx/dyn_bit_manip.rs @@ -141,16 +141,17 @@ pub fn move_nbits_to_msb(a: &[T], n: usize) -> Vec { [right, left].concat() } +/// Const helper to compute maximum of two usize values. +pub const fn const_max2(a: usize, b: usize) -> usize { + if a > b { a } else { b } +} + #[macro_export] /// Macro to compute the maximum of a list of constant expressions at compile time. macro_rules! const_max { ($x: expr) => ($x); ($x: expr, $($z: expr), +) => ( - if $x > const_max!($($z), +) { - $x - } else { - const_max!($($z), +) - } + $crate::bitx::dyn_bit_manip::const_max2($x, const_max!($($z),+)) ); }