From ce34afd844590c3a62a03d9ad7e63350e941706e Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sun, 1 Feb 2026 17:16:25 -0700 Subject: [PATCH] cpubits: add 16 vs 32 and 32 vs 64-bit patterns For use cases where one of the three sizes won't be supported (either 16-bit or 64-bit), allows matching against only two of the three options --- cpubits/src/lib.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/cpubits/src/lib.rs b/cpubits/src/lib.rs index 78ed49ad..183428c8 100644 --- a/cpubits/src/lib.rs +++ b/cpubits/src/lib.rs @@ -197,6 +197,30 @@ macro_rules! cpubits { } }; + // Select between 16-bit and 32-bit options, where no code will be generated for 64-bit targets + ( + 16 => { $( $tokens16:tt )* } + 32 => { $( $tokens32:tt )* } + ) => { + $crate::cpubits! { + 16 => { $( $tokens16 )* } + 32 => { $( $tokens32 )* } + 64 => { } + } + }; + + // Select between 32-bit and 64-bit options, where no code will be generated for 16-bit targets + ( + 32 => { $( $tokens32:tt )* } + 64 => { $( $tokens64:tt )* } + ) => { + $crate::cpubits! { + 16 => { } + 32 => { $( $tokens32 )* } + 64 => { $( $tokens64 )* } + } + }; + // Select between 16-bit and 32-bit options, where 64-bit will use the 32-bit option ( 16 => { $( $tokens16:tt )* } @@ -253,7 +277,7 @@ macro_rules! cpubits { @__items () ; // The following are effectively `if`/`else` clauses in a Lispy syntax, where each // 2-tuple is `( ( predicate ) ( body ) )`. The first clause with a matching predicate - // is taken and the rest are ignored just like `if`/`else`. + // is taken and its body executed and the rest are ignored just like `if`/`else`. // // We first match on each of the explicit overrides, and if none of them are configured // apply our heuristic logic which allows certain targets to be overridden to use