[PATCH 1/2] aarch64: use macro trickery to automate feature array size replication
Richard Earnshaw (lists)
Richard.Earnshaw@arm.com
Fri Jun 6 13:46:52 GMT 2025
On 06/06/2025 14:08, Jan Beulich wrote:
> On 06.06.2025 14:27, Richard Earnshaw wrote:
>> --- 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)
>
> Maybe you can get away without this (and hence without any need to keep
> two things in sync)?
>
>> +static_assert (AARCH64_MAX_FEATURES > AARCH64_NUM_FEATURES,
>
> (As an aside - isn't >= sufficient here?)
>
>> + "Insufficent capacity in AARCH64_MAX_FEATURES");
>> +
>> +#define AA64_REPLICATE(SEP, BODY, ...) \
>> + BODY (0, __VA_ARGS__) SEP \
>> + BODY (1, __VA_ARGS__)
>
> Move the static_assert() further down and use
>
> #define XYZ_BODY(x, ...) [x] = (x)
>
> static_assert (AARCH64_BITS_PER_FEATURE_WORD
> * sizeof ((char[]){ AA64_REPLICATE (REP_COMMA, XYZ_BODY) })
> >= AARCH64_NUM_FEATURES,
> "Insufficient repetitions in AA64_REPLICATE()");
>
> Jan
I don't think we need anything that complicated.
static_assert ((AA64_REPLICATE (REP_PLUS, AA64_REPVAL, AARCH64_BITS_PER_FEATURE_WORD))
>= AARCH64_NUM_FEATURES,
"Insufficient repetitions in AA64_REPLICATE()");
Is perfectly adequate (where REP_PLUS is simply '+' of course).
Thanks for the suggestion.
R.
More information about the Binutils
mailing list