Re: [RESEND v1 2/3] x86/cpufeatures: Generate a feature mask header based on build config

From: H. Peter Anvin
Date: Mon Jun 17 2024 - 11:38:21 EST


On June 16, 2024 12:26:48 AM PDT, Xin Li <xin@xxxxxxxxx> wrote:
>On 5/9/2024 1:53 PM, Xin Li (Intel) wrote:
>> From: "H. Peter Anvin (Intel)" <hpa@xxxxxxxxx>
>>
>> Introduce an AWK script to auto-generate a header with required and
>> disabled feature masks based on <asm/cpufeatures.h> and current build
>> config. Thus for any CPU feature with a build config, e.g., X86_FRED,
>> simply add
>
>...
>
>> +
>> + printf "\n#define %s_MASKS ", s;
>> + pfx = "{";
>> + for (i = 0; i < ncapints; i++) {
>> + printf "%s \\\n\t%s_MASK_%d", pfx, s, i;
>> + pfx = ",";
>> + }
>> + printf " \\\n}\n\n";
>> +
>> + printf "#define %s_FEATURE(x) \\\n", s;
>> + printf "\t((( ";
>> + for (i = 0; i < ncapints; i++) {
>> + if (masks[i]) {
>> + printf "\\\n\t\t((x) >> 5) == %2d ? %s_MASK%-3d : ", i, s, i;
>> + }
>> + }
>> + printf "0 \\\n";
>> + printf "\t) >> ((x) & 31)) & 1)\n\n";
>
>This code generates macros {REQUIRED,DISABLED}_FEATURE(x) to tell if a
>CPU feature, e.g., X86_FEATURE_FRED, is a required or disabled feature
>for this particular compile-time configuration.
>
>But they are NOT currently used, so I prefer to remove them for now.
>
>Thanks!
> Xin

The goal with these is that it can eliminate the handwritten code that tests a long list of masks. Again, automation.