[PATCH 1/2] aarch64: use macro trickery to automate feature array size replication

Hans-Peter Nilsson hp@bitrange.com
Sat Jun 7 02:56:24 GMT 2025


On Fri, 6 Jun 2025, Richard Earnshaw wrote:

> There are quite a few macros that need to be changed when we need to
> increase the number of words in the features data structure.  With
> some macro trickery we can automate most of this so that a single
> macro needs to be updated.
> 
> With C2X we could probably do even better by using recursion, but this
> is still a much better situation than we had previously.
> 
> I've also replaced the dynamic sizing of the array with a simple
> constant and then added an assertion that the number of features does
> not exceed this limit.  This should help catch situations where we
> accidentally run out of bits.
> ---
>  include/opcode/aarch64.h | 119 +++++++++++++++++++++++++++------------
>  1 file changed, 83 insertions(+), 36 deletions(-)
> 
> diff --git a/include/opcode/aarch64.h b/include/opcode/aarch64.h
> index df90bb76e56..98ceded2bcb 100644
> --- a/include/opcode/aarch64.h
> +++ b/include/opcode/aarch64.h
> @@ -290,13 +290,44 @@ enum aarch64_feature_bit {
>    AARCH64_NUM_FEATURES
>  };
>  
> +typedef uint64_t aarch64_feature_word;
> +#define AARCH64_BITS_PER_FEATURE_WORD 64
> +
> +/* Maximum number of features that we can currently support.  If you
> +   need to increase this value you will need to increase the number of
> +   replication statements in AA64_REPLICATE below.  */
> +#define AARCH64_MAX_FEATURES (AARCH64_BITS_PER_FEATURE_WORD * 2)
> +
> +static_assert (AARCH64_MAX_FEATURES > AARCH64_NUM_FEATURES,
> +	       "Insufficent capacity in AARCH64_MAX_FEATURES");

I don't think C11 is required yet (so static_assert shouldn't be 
used)?

See opcodes/i386-gen.c and opcodes/s390-opc.c for fallback 
definitions.  There's also _Static_assert as a gcc extension 
(unsure) that works at least as far back as gcc-4.7.2 (empirical 
observation).

brgds, H-P


More information about the Binutils mailing list