guix: cpu: Rewrite based on feature flags.

* guix/cpu.scm (cpu->gcc-architecture): Rewrite detection based on
detected feature flags.
This commit is contained in:
Efraim Flashner 2022-02-08 17:15:01 +02:00
parent 1ddef634b0
commit 73373ce5f8
No known key found for this signature in database
GPG key ID: 41AAE7DCCA3D8351

View file

@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2022 Efraim Flashner <efraim@flashner.co.il>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -87,28 +88,39 @@ (define (cpu->gcc-architecture cpu)
("x86_64" ("x86_64"
;; Transcribed from GCC's 'host_detect_local_cpu' in driver-i386.c. ;; Transcribed from GCC's 'host_detect_local_cpu' in driver-i386.c.
(or (and (= 6 (cpu-family cpu)) ;the "Pentium Pro" family (or (and (= 6 (cpu-family cpu)) ;the "Pentium Pro" family
(letrec-syntax ((model (syntax-rules (=>) (letrec-syntax ((if-flags (syntax-rules (=>)
((_) #f) ((_)
((_ (candidate => integers ...) rest #f)
...) ((_ (flags ... => name) rest ...)
(or (and (= (cpu-model cpu) integers) (if (every (lambda (flag)
candidate) (set-contains? (cpu-flags cpu)
... flag))
(model rest ...)))))) '(flags ...))
(model ("bonnel" => #x1c #x26) name
("silvermont" => #x37 #x4a #x4d #x5a #x5d) (if-flags rest ...))))))
("core2" => #x0f #x17 #x1d)
("nehalem" => #x1a #x1e #x1f #x2e) (if-flags ("avx" "avx512vp2intersect" "tsxldtrk" => "sapphirerapids")
("westmere" => #x25 #x2c #x2f) ("avx" "avx512vp2intersect" => "tigerlake")
("sandybridge" => #x2a #x2d) ("avx" "avx512bf16" => "cooperlake")
("ivybridge" => #x3a #x3e) ("avx" "wbnoinvd" => "icelake-server")
("haswell" => #x3c #x3f #x45 #x46) ("avx" "avx512bitalg" => "icelake-client")
("broadwell" => #x3d #x47 #x4f #x56) ("avx" "avx512vbmi" => "cannonlake")
("skylake" => #x4e #x5e #x8e #x9e) ("avx" "avx5124vnniw" => "knm")
("skylake-avx512" => #x55) ;TODO: cascadelake ("avx" "avx512er" => "knl")
("knl" => #x57) ("avx" "avx512f" => "skylake-avx512")
("cannonlake" => #x66) ("avx" "serialize" => "alderlake")
("knm" => #x85)))) ("avx" "clflushopt" => "skylake")
("avx" "adx" => "broadwell")
("avx" "avx2" => "haswell")
("avx" => "sandybridge")
("sse4_2" "gfni" => "tremont")
("sse4_2" "sgx" => "goldmont-plus")
("sse4_2" "xsave" => "goldmont")
("sse4_2" "movbe" => "silvermont")
("sse4_2" => "nehalem")
("ssse3" "movbe" => "bonnell")
("ssse3" => "core2")
("longmode" => "x86-64"))))
;; Fallback case for non-Intel processors or for Intel processors not ;; Fallback case for non-Intel processors or for Intel processors not
;; recognized above. ;; recognized above.