Subject: [bug#53895] [PATCH 0/5] More CPU detection

From: Efraim Flashner <[email-masked]>
Date: Wed, 9 Feb 2022 12:54:14 +0200

On Wed, Feb 09, 2022 at 11:43:21AM +0100, Ludovic Courtès wrote:
> Efraim Flashner <[email-masked]> skribis:
> 
> > * guix/cpu.scm <cpu>: Add vendor field.
> > (current-cpu): Also fill in the 'vendor' field.
> > (cpu->gcc-architecture): Add detection logic for AMD CPUs.
> 
> [...]
> 
> > +         (and (equal? "AuthenticAMD" (cpu-vendor cpu))
> 
> Isn’t that equivalent to (= (cpu-family cpu) some-value)?

It looks to me like 'family' started as the prefix for iX86, so Intel is
mostly using family 6, except when a couple of other processors slip in.
I wasn't able to find a hard and fast rule for what family AMD typically
uses, on my machine its 23. In driver-i386.c it's sort by vendor first:
if (vendor == VENDOR_AMD)

> > +              (letrec-syntax ((if-flags (syntax-rules (=>)
> > +                                          ((_)
> > +                                           #f)
> > +                                          ((_ (flags ... => name) rest ...)
> > +                                           (if (every (lambda (flag)
> > +                                                        (set-contains? (cpu-flags cpu)
> > +                                                                       flag))
> > +                                                      '(flags ...))
> > +                                             name
> > +                                             (if-flags rest ...))))))
> > +
> > +                (when (= 22 (cpu-family cpu))
> > +                  (if-flags ("movbe" => "btver2")))
> > +                (when (= 6 (cpu-family cpu))
> > +                  (if-flags ("3dnowp" => "athalon")))
> 
> This has no effect (because ‘if-flags’ returns a value that is ignored
> since it’s not returned.)
> 
> What we could do is extend ‘if-flags’ so that it can optionally check
> for a family number:
> 
>   (if-flags ((family 22) "movbe" => "btver2")
>              …)

That sounds like a good idea.

> > +                (if-flags ("vaes" => "znver3")
> > +                          ("clwb" => "znver2")
> > +                          ("clzero" => "znver1")
> 
> However, the code in driver-i386.c seems to look at model IDs (the big
> “switch (processor)” thing) and not feature flags.  Or am I overlooking
> something?

switch (processor) comes after all the AMD chips are sorted. It looks
like all of Intel's i686 and x86_64 are PROCESSOR_PENTIUMPRO, while AMD
has a separate processor per chip design. The AMD chips are sorted about
90 lines above the switch (processor) line

> Thanks,
> Ludo’.

-- 
Efraim Flashner   <[email-masked]>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted