Skip to content

Commit 3a1f930

Browse files
authored
cpubits: add 64-bit only gating (#1400)
Useful for when things are only possible because the word size is sufficiently large, e.g. `From<u64> for Word`. Also adds some explanatory comments about the various clauses of the macro.
1 parent df664d4 commit 3a1f930

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cpubits/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
4242
#[macro_export]
4343
macro_rules! cpubits {
44+
// Select between 16-bit and 32-bit, where 64-bit targets will use the 32-bit option
4445
(
4546
16 => { $( $tokens16:tt )* }
4647
32 => { $( $tokens32:tt )* }
@@ -51,6 +52,18 @@ macro_rules! cpubits {
5152
}
5253
};
5354

55+
// Only run the given block if we have selected the 64-bit backend, i.e. the code will be
56+
// ignored on 16-bit and 32-bit platforms.
57+
(
58+
64 => { $( $tokens64:tt )* }
59+
) => {
60+
$crate::cpubits! {
61+
16 | 32 => { }
62+
64 => { $( $tokens64 )* }
63+
}
64+
};
65+
66+
// Select between 32-bit and 64-bit, where 16-bit targets will use the 32-bit option
5467
(
5568
32 => { $( $tokens32:tt )* }
5669
64 => { $( $tokens64:tt )* }
@@ -61,6 +74,7 @@ macro_rules! cpubits {
6174
}
6275
};
6376

77+
// Same as `16`/`32` above, but more explicit
6478
(
6579
16 => { $( $tokens16:tt )* }
6680
32 | 64 => { $( $tokens32:tt )* }
@@ -72,6 +86,7 @@ macro_rules! cpubits {
7286
}
7387
};
7488

89+
// Same as `32`/`64` above, but more explicit
7590
(
7691
16 | 32 => { $( $tokens32:tt )* }
7792
64 => { $( $tokens64:tt )* }
@@ -83,6 +98,7 @@ macro_rules! cpubits {
8398
}
8499
};
85100

101+
// The general API which runs a different block for each possible word size
86102
(
87103
16 => { $( $tokens16:tt )* }
88104
32 => { $( $tokens32:tt )* }
@@ -99,6 +115,8 @@ macro_rules! cpubits {
99115
}
100116
};
101117

118+
// Same API as immediately above, but with a pseudo-attribute we use to pass the `cfg` overrides
119+
// for `target_pointer_width` that promote a 32-bit target into a 64-bit one.
102120
(
103121
#[enable_64bit( $($enable_64bit:tt)+ )]
104122
16 => { $( $tokens16:tt )* }

0 commit comments

Comments
 (0)