Re: [PATCH v1 07/12] tools/x86/kcpuid: Add rudimentary CPU vendor detection

From: Dave Hansen
Date: Thu Mar 06 2025 - 17:00:40 EST


On 3/6/25 12:49, Ahmed S. Darwish wrote:
> +/*
> + * Leaf 0x0 EDX output, CPU vendor ID string bytes 4 - 7.
> + */
> +enum {
> + EDX_INTEL = fourcc('i', 'n', 'e', 'I'), /* Genu_ineI_ntel */
> + EDX_AMD = fourcc('e', 'n', 't', 'i'), /* Auth_enti_cAMD */
> + EDX_HYGON = fourcc('n', 'G', 'e', 'n'), /* Hygo_nGen_uine */
> + EDX_TRANSMETA = fourcc('i', 'n', 'e', 'T'), /* Genu_ineT_Mx86 */
> + EDX_CENTAUR = fourcc('a', 'u', 'r', 'H'), /* Cent_aurH_auls */
> + EDX_ZHAOXIN = fourcc('a', 'n', 'g', 'h'), /* Sh_angh_ai */
> +};

So, this is cute and all. But isn't it a _wee_ bit too clever for its
own good?

Why not just have a dumb array:

{ INTEL, "GenuineIntel" },
{ AMD, "AuthenticAMD" ],
...

Are we really looking to save a few dozen CPU cycles in this thing? It
took me at least a minute or two of staring at this thing to figure out
what the heck it was doing.