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

Richard Earnshaw (lists) Richard.Earnshaw@arm.com
Mon Jun 9 10:28:25 GMT 2025


On 07/06/2025 03:56, Hans-Peter Nilsson wrote:
> 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)?
> 

Whilst pre-C11 might be needed to support users trying to build on such old systems, no developer should be using a compiler that old by now.  I think the easiest solution is to just wrap the assert in

/* static_assert requires C11.  */
#if __STDC_VERSION__ >= 201112L
static_assert (AARCH64...
#endif

> 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).
> 

In C23, static_assert is a keyword (in C11 the keyword was _Static_assert and assert.h defined static_assert in terms of that), so I'm not sure I really understand what the code in these files is trying to do - it's overriding the keyword when it exists.


> brgds, H-P

R.


More information about the Binutils mailing list