all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#53895] [PATCH 0/5] More CPU detection
@ 2022-02-09 10:16 Efraim Flashner
  2022-02-09 10:21 ` [bug#53895] [PATCH 1/5] guix: cpu: Rewrite based on feature flags Efraim Flashner
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Efraim Flashner @ 2022-02-09 10:16 UTC (permalink / raw)
  To: 53895; +Cc: Efraim Flashner

I noticed that my AMD CPU was showing up as bonnell, which was clearly
wrong. I ended up rewriting parts of the x86_64 section (and considered
having it also serve for i686) and then tried to add some bits for
aarch64. IMO it's worth having the compiler-cpu-architectures for
aarch64/armhf, at least until (guix transformations) is taught that for
aarch64/armhf to use -mtune in place of -march.

Efraim Flashner (5):
  guix: cpu: Rewrite based on feature flags.
  gnu: cpu: Add detection for AMD CPUs.
  gnu: gcc: Add compiler-cpu-architectures for aarch64.
  gnu: gcc: Add compiler-cpu-architectures for armhf.
  WIP: guix: cpu: Add detection for aarch64 CPUs.

 gnu/packages/gcc.scm |  33 +++++++-
 guix/cpu.scm         | 186 +++++++++++++++++++++++++++++++++++--------
 2 files changed, 186 insertions(+), 33 deletions(-)


base-commit: 71438cd4222a02b1f89152437c1ea20499baa6a2
-- 
2.34.0





^ permalink raw reply	[flat|nested] 14+ messages in thread

* [bug#53895] [PATCH 1/5] guix: cpu: Rewrite based on feature flags.
  2022-02-09 10:16 [bug#53895] [PATCH 0/5] More CPU detection Efraim Flashner
@ 2022-02-09 10:21 ` Efraim Flashner
  2022-02-09 10:35   ` [bug#53895] [PATCH 0/5] More CPU detection Ludovic Courtès
  2022-02-09 10:21 ` [bug#53895] [PATCH 2/5] gnu: cpu: Add detection for AMD CPUs Efraim Flashner
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Efraim Flashner @ 2022-02-09 10:21 UTC (permalink / raw)
  To: 53895; +Cc: Efraim Flashner

* guix/cpu.scm (cpu->gcc-architecture): Rewrite detection based on
detected feature flags.
---
 guix/cpu.scm | 56 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 34 insertions(+), 22 deletions(-)

diff --git a/guix/cpu.scm b/guix/cpu.scm
index e1911f52a8..5bb3fa9d2f 100644
--- a/guix/cpu.scm
+++ b/guix/cpu.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2022 Efraim Flashner <efraim@flashner.co.il>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -87,28 +88,39 @@ (define (cpu->gcc-architecture cpu)
     ("x86_64"
      ;; Transcribed from GCC's 'host_detect_local_cpu' in driver-i386.c.
      (or (and (= 6 (cpu-family cpu))              ;the "Pentium Pro" family
-              (letrec-syntax ((model (syntax-rules (=>)
-                                       ((_) #f)
-                                       ((_ (candidate => integers ...) rest
-                                           ...)
-                                        (or (and (= (cpu-model cpu) integers)
-                                                 candidate)
-                                            ...
-                                            (model rest ...))))))
-                (model ("bonnel" => #x1c #x26)
-                       ("silvermont" => #x37 #x4a #x4d #x5a #x5d)
-                       ("core2" => #x0f #x17 #x1d)
-                       ("nehalem" => #x1a #x1e #x1f #x2e)
-                       ("westmere" => #x25 #x2c #x2f)
-                       ("sandybridge" => #x2a #x2d)
-                       ("ivybridge" => #x3a #x3e)
-                       ("haswell" => #x3c #x3f #x45 #x46)
-                       ("broadwell" => #x3d #x47 #x4f #x56)
-                       ("skylake" => #x4e #x5e #x8e #x9e)
-                       ("skylake-avx512" => #x55) ;TODO: cascadelake
-                       ("knl" => #x57)
-                       ("cannonlake" => #x66)
-                       ("knm" => #x85))))
+              (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 ...))))))
+
+                (if-flags ("avx" "avx512vp2intersect" "tsxldtrk" => "sapphirerapids")
+                          ("avx" "avx512vp2intersect" => "tigerlake")
+                          ("avx" "avx512bf16" => "cooperlake")
+                          ("avx" "wbnoinvd" => "icelake-server")
+                          ("avx" "avx512bitalg" => "icelake-client")
+                          ("avx" "avx512vbmi" => "cannonlake")
+                          ("avx" "avx5124vnniw" => "knm")
+                          ("avx" "avx512er" => "knl")
+                          ("avx" "avx512f" => "skylake-avx512")
+                          ("avx" "serialize" => "alderlake")
+                          ("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
          ;; recognized above.
-- 
2.34.0





^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [bug#53895] [PATCH 2/5] gnu: cpu: Add detection for AMD CPUs.
  2022-02-09 10:16 [bug#53895] [PATCH 0/5] More CPU detection Efraim Flashner
  2022-02-09 10:21 ` [bug#53895] [PATCH 1/5] guix: cpu: Rewrite based on feature flags Efraim Flashner
@ 2022-02-09 10:21 ` Efraim Flashner
  2022-02-09 10:43   ` [bug#53895] [PATCH 0/5] More CPU detection Ludovic Courtès
  2022-02-09 10:21 ` [bug#53895] [PATCH 3/5] gnu: gcc: Add compiler-cpu-architectures for aarch64 Efraim Flashner
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Efraim Flashner @ 2022-02-09 10:21 UTC (permalink / raw)
  To: 53895; +Cc: Efraim Flashner

* guix/cpu.scm <cpu>: Add vendor field.
(current-cpu): Also fill in the 'vendor' field.
(cpu->gcc-architecture): Add detection logic for AMD CPUs.
---
 guix/cpu.scm | 60 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 51 insertions(+), 9 deletions(-)

diff --git a/guix/cpu.scm b/guix/cpu.scm
index 5bb3fa9d2f..6d44599822 100644
--- a/guix/cpu.scm
+++ b/guix/cpu.scm
@@ -27,6 +27,7 @@ (define-module (guix cpu)
   #:export (current-cpu
             cpu?
             cpu-architecture
+            cpu-vendor
             cpu-family
             cpu-model
             cpu-flags
@@ -42,9 +43,10 @@ (define-module (guix cpu)
 
 ;; CPU description.
 (define-record-type <cpu>
-  (cpu architecture family model flags)
+  (cpu architecture vendor family model flags)
   cpu?
   (architecture cpu-architecture)                 ;string, from 'uname'
+  (vendor       cpu-vendor)                       ;string
   (family       cpu-family)                       ;integer
   (model        cpu-model)                        ;integer
   (flags        cpu-flags))                       ;set of strings
@@ -58,28 +60,33 @@ (define (prefix? prefix)
 
     (call-with-input-file "/proc/cpuinfo"
       (lambda (port)
-        (let loop ((family #f)
+        (let loop ((vendor #f)
+                   (family #f)
                    (model #f))
           (match (read-line port)
             ((? eof-object?)
              #f)
+            ((? (prefix? "vendor_id") str)
+             (match (string-tokenize str)
+               (("vendor_id" ":" vendor)
+                (loop vendor family model))))
             ((? (prefix? "cpu family") str)
              (match (string-tokenize str)
                (("cpu" "family" ":" family)
-                (loop (string->number family) model))))
+                (loop vendor (string->number family) model))))
             ((? (prefix? "model") str)
              (match (string-tokenize str)
                (("model" ":" model)
-                (loop family (string->number model)))
+                (loop vendor family (string->number model)))
                (_
-                (loop family model))))
+                (loop vendor family model))))
             ((? (prefix? "flags") str)
              (match (string-tokenize str)
                (("flags" ":" flags ...)
                 (cpu (utsname:machine (uname))
-                     family model (list->set flags)))))
+                     vendor family model (list->set flags)))))
             (_
-             (loop family model))))))))
+             (loop vendor family model))))))))
 
 (define (cpu->gcc-architecture cpu)
   "Return the architecture name, suitable for GCC's '-march' flag, that
@@ -87,7 +94,8 @@ (define (cpu->gcc-architecture cpu)
   (match (cpu-architecture cpu)
     ("x86_64"
      ;; Transcribed from GCC's 'host_detect_local_cpu' in driver-i386.c.
-     (or (and (= 6 (cpu-family cpu))              ;the "Pentium Pro" family
+     (or (and (equal? "GenuineIntel" (cpu-vendor cpu))
+              (= 6 (cpu-family cpu))              ;the "Pentium Pro" family
               (letrec-syntax ((if-flags (syntax-rules (=>)
                                           ((_)
                                            #f)
@@ -122,6 +130,40 @@ (define (cpu->gcc-architecture cpu)
                           ("ssse3" => "core2")
                           ("longmode" => "x86-64"))))
 
+         (and (equal? "AuthenticAMD" (cpu-vendor cpu))
+              (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")))
+
+                (if-flags ("vaes" => "znver3")
+                          ("clwb" => "znver2")
+                          ("clzero" => "znver1")
+                          ("avx2" => "bdver4")
+                          ("xsaveopt" => "bdver3")
+                          ("bmi" => "bdver2")
+                          ("xop" => "bdver1")
+                          ("sse4a" "has_ssse3" => "btver1")
+                          ("sse4a" => "amdfam10")
+                          ("sse2" "sse3" => "k8-sse3")
+                          ("longmode" "sse3" => "k8-sse3")
+                          ("sse2" => "k8")
+                          ("longmode" => "k8")
+                          ("mmx" "3dnow" => "k6-3")
+                          ("mmx" => "k6")
+                          (_ => "pentium"))))
+
          ;; Fallback case for non-Intel processors or for Intel processors not
          ;; recognized above.
          (letrec-syntax ((if-flags (syntax-rules (=>)
@@ -147,7 +189,7 @@ (define (cpu->gcc-architecture cpu)
                      ("ssse3" "movbe" => "bonnell")
                      ("ssse3" => "core2")))
 
-         ;; TODO: Recognize AMD models (bdver*, znver*, etc.)?
+         ;; TODO: Recognize CENTAUR/CYRIX/NSC?
 
          "x86_64"))
     (architecture
-- 
2.34.0





^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [bug#53895] [PATCH 3/5] gnu: gcc: Add compiler-cpu-architectures for aarch64.
  2022-02-09 10:16 [bug#53895] [PATCH 0/5] More CPU detection Efraim Flashner
  2022-02-09 10:21 ` [bug#53895] [PATCH 1/5] guix: cpu: Rewrite based on feature flags Efraim Flashner
  2022-02-09 10:21 ` [bug#53895] [PATCH 2/5] gnu: cpu: Add detection for AMD CPUs Efraim Flashner
@ 2022-02-09 10:21 ` Efraim Flashner
  2022-02-09 10:21 ` [bug#53895] [PATCH 4/5] gnu: gcc: Add compiler-cpu-architectures for armhf Efraim Flashner
  2022-02-09 10:21 ` [bug#53895] [PATCH 5/5] WIP: guix: cpu: Add detection for aarch64 CPUs Efraim Flashner
  4 siblings, 0 replies; 14+ messages in thread
From: Efraim Flashner @ 2022-02-09 10:21 UTC (permalink / raw)
  To: 53895; +Cc: Efraim Flashner

* gnu/packages/gcc.scm (%gcc-7.5-aarch64-micro-architectures,
%gcc-10-aarch64-micro-architectures): New variables.
(gcc-7, gcc-10)[properties]: Add aarch64 compiler-cpu-architectures.
---
 gnu/packages/gcc.scm | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/gcc.scm b/gnu/packages/gcc.scm
index efa0baeaa1..726c0eed89 100644
--- a/gnu/packages/gcc.scm
+++ b/gnu/packages/gcc.scm
@@ -3,7 +3,7 @@
 ;;; Copyright © 2014, 2015, 2018 Mark H Weaver <mhw@netris.org>
 ;;; Copyright © 2014, 2015, 2016, 2017, 2019, 2021 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
-;;; Copyright © 2015, 2016, 2017, 2018, 2020, 2021 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2015, 2016, 2017, 2018, 2020, 2021, 2022 Efraim Flashner <efraim@flashner.co.il>
 ;;; Copyright © 2016 Carlos Sánchez de La Lama <csanchezdll@gmail.com>
 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2018, 2020 Marius Bakke <mbakke@fastmail.com>
@@ -525,6 +525,11 @@ (define-public gcc-6
 
        ,@(package-inputs gcc-4.7)))))
 
+(define %gcc-7.5-aarch64-micro-architectures
+  ;; Suitable '-march' values for GCC 7.5.
+  ;; TODO: Allow dynamically adding feature flags.
+  '("armv8-a" "armv8.1-a" "armv8.2-a" "armv8.3-a"))
+
 (define %gcc-7.5-x86_64-micro-architectures
   ;; Suitable '-march' values for GCC 7.5 (info "(gcc) x86 Options").
   '("core2" "nehalem" "westmere" "sandybridge" "ivybridge"
@@ -536,6 +541,12 @@ (define %gcc-7.5-x86_64-micro-architectures
     "znver1"
     "btver1" "btver2" "geode"))
 
+(define %gcc-10-aarch64-micro-architectures
+  ;; Suitable '-march' values for GCC 10.
+  ;; TODO: Allow dynamically adding feature flags.
+  (append %gcc-7.5-aarch64-micro-architectures
+          '("armv8.4-a" "armv8.5-a" "armv8.6-a")))
+
 (define %gcc-10-x86_64-micro-architectures
   ;; Suitable '-march' values for GCC 10.
   (append %gcc-7.5-x86_64-micro-architectures
@@ -545,7 +556,6 @@ (define %gcc-10-x86_64-micro-architectures
 
         "znver2" "znver3")))
 
-
 (define-public gcc-7
   (package
     (inherit gcc-6)
@@ -566,6 +576,7 @@ (define-public gcc-7
 It also includes runtime support libraries for these languages.")
     (properties
      `((compiler-cpu-architectures
+        ("aarch64" ,@%gcc-7.5-aarch64-micro-architectures)
         ("x86_64" ,@%gcc-7.5-x86_64-micro-architectures))))))
 
 (define-public gcc-8
@@ -619,6 +630,7 @@ (define-public gcc-10
             (snippet gcc-canadian-cross-objdump-snippet)))
    (properties
     `((compiler-cpu-architectures
+       ("aarch64" ,@%gcc-10-aarch64-micro-architectures)
        ("x86_64" ,@%gcc-10-x86_64-micro-architectures))))))
 
 (define-public gcc-11
-- 
2.34.0





^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [bug#53895] [PATCH 4/5] gnu: gcc: Add compiler-cpu-architectures for armhf.
  2022-02-09 10:16 [bug#53895] [PATCH 0/5] More CPU detection Efraim Flashner
                   ` (2 preceding siblings ...)
  2022-02-09 10:21 ` [bug#53895] [PATCH 3/5] gnu: gcc: Add compiler-cpu-architectures for aarch64 Efraim Flashner
@ 2022-02-09 10:21 ` Efraim Flashner
  2022-02-09 10:21 ` [bug#53895] [PATCH 5/5] WIP: guix: cpu: Add detection for aarch64 CPUs Efraim Flashner
  4 siblings, 0 replies; 14+ messages in thread
From: Efraim Flashner @ 2022-02-09 10:21 UTC (permalink / raw)
  To: 53895; +Cc: Efraim Flashner

* gnu/packages/gcc.scm (%gcc-7.5-armhf-micro-architectures,
%gcc-10-armhf-micro-architectures): New variables.
(gcc-7, gcc-10)[properties]: Add armhf compiler-cpu-architectures.
---
 gnu/packages/gcc.scm | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/gnu/packages/gcc.scm b/gnu/packages/gcc.scm
index 726c0eed89..e0a431a0ff 100644
--- a/gnu/packages/gcc.scm
+++ b/gnu/packages/gcc.scm
@@ -530,6 +530,14 @@ (define %gcc-7.5-aarch64-micro-architectures
   ;; TODO: Allow dynamically adding feature flags.
   '("armv8-a" "armv8.1-a" "armv8.2-a" "armv8.3-a"))
 
+(define %gcc-7.5-armhf-micro-architectures
+  ;; Suitable '-march' values for GCC 7.5.
+  ;; TODO: Allow dynamically adding feature flags.
+  '("armv7" "armv7-a" "armv7-m" "armv7-r" "armv7e-m" "armv7ve"
+    "armv8-a" "armv8-a+crc" "armv8.1-a" "armv8.1-a+crc"
+    "armv8-m.base" "armv8-m.main" "armv8-m.main+dsp"
+    "iwmmxt" "iwmmxt2"))
+
 (define %gcc-7.5-x86_64-micro-architectures
   ;; Suitable '-march' values for GCC 7.5 (info "(gcc) x86 Options").
   '("core2" "nehalem" "westmere" "sandybridge" "ivybridge"
@@ -547,6 +555,13 @@ (define %gcc-10-aarch64-micro-architectures
   (append %gcc-7.5-aarch64-micro-architectures
           '("armv8.4-a" "armv8.5-a" "armv8.6-a")))
 
+(define %gcc-10-armhf-micro-architectures
+  ;; Suitable '-march' values for GCC 10.
+  ;; TODO: Allow dynamically adding feature flags.
+  (append %gcc-7.5-armhf-micro-architectures
+          '("armv8.2-a" "armv8.3-a" "armv8.4-a" "armv8.5-a" "armv8.6-a"
+            "armv8-r" "armv8.1-m.main")))
+
 (define %gcc-10-x86_64-micro-architectures
   ;; Suitable '-march' values for GCC 10.
   (append %gcc-7.5-x86_64-micro-architectures
@@ -577,6 +592,7 @@ (define-public gcc-7
     (properties
      `((compiler-cpu-architectures
         ("aarch64" ,@%gcc-7.5-aarch64-micro-architectures)
+        ("armhf" ,@%gcc-7.5-armhf-micro-architectures)
         ("x86_64" ,@%gcc-7.5-x86_64-micro-architectures))))))
 
 (define-public gcc-8
@@ -631,6 +647,7 @@ (define-public gcc-10
    (properties
     `((compiler-cpu-architectures
        ("aarch64" ,@%gcc-10-aarch64-micro-architectures)
+       ("armhf" ,@%gcc-10-armhf-micro-architectures)
        ("x86_64" ,@%gcc-10-x86_64-micro-architectures))))))
 
 (define-public gcc-11
-- 
2.34.0





^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [bug#53895] [PATCH 5/5] WIP: guix: cpu: Add detection for aarch64 CPUs.
  2022-02-09 10:16 [bug#53895] [PATCH 0/5] More CPU detection Efraim Flashner
                   ` (3 preceding siblings ...)
  2022-02-09 10:21 ` [bug#53895] [PATCH 4/5] gnu: gcc: Add compiler-cpu-architectures for armhf Efraim Flashner
@ 2022-02-09 10:21 ` Efraim Flashner
  4 siblings, 0 replies; 14+ messages in thread
From: Efraim Flashner @ 2022-02-09 10:21 UTC (permalink / raw)
  To: 53895; +Cc: Efraim Flashner

* guix/cpu.scm (current-cpu): Extend existing implementation to also
read cpuinfo from aarch64 machines.
(cpu->gcc-architecture): Add case for aarch64.
---
 guix/cpu.scm | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/guix/cpu.scm b/guix/cpu.scm
index 6d44599822..d4dbd5f6b8 100644
--- a/guix/cpu.scm
+++ b/guix/cpu.scm
@@ -66,25 +66,47 @@ (define (prefix? prefix)
           (match (read-line port)
             ((? eof-object?)
              #f)
+            ;; vendor for x86_64 and i686
             ((? (prefix? "vendor_id") str)
              (match (string-tokenize str)
                (("vendor_id" ":" vendor)
                 (loop vendor family model))))
+            ;; vendor for aarch64 and armhf
+            ((? (prefix? "CPU implementer") str)
+             (match (string-tokenize str)
+               (("CPU" "implementer" ":" vendor)
+                (loop vendor family model))))
+            ;; family for x86_64 and i686
             ((? (prefix? "cpu family") str)
              (match (string-tokenize str)
                (("cpu" "family" ":" family)
                 (loop vendor (string->number family) model))))
+            ;; model for x86_64 and i686
             ((? (prefix? "model") str)
              (match (string-tokenize str)
                (("model" ":" model)
                 (loop vendor family (string->number model)))
                (_
                 (loop vendor family model))))
+            ;; model for aarch64 and armhf
+            ((? (prefix? "CPU part") str)
+             (match (string-tokenize str)
+               (("CPU" "part" ":" model)
+                (loop vendor family (string->number (string-append "#x" (string-drop model 2)))))
+               (_
+                (loop vendor family model))))
+            ;; flags for x86_64 and i686
             ((? (prefix? "flags") str)
              (match (string-tokenize str)
                (("flags" ":" flags ...)
                 (cpu (utsname:machine (uname))
                      vendor family model (list->set flags)))))
+            ;; flags for aarch64 and armhf
+            ((? (prefix? "Features") str)
+             (match (string-tokenize str)
+               (("Features" ":" flags ...)
+                (cpu (utsname:machine (uname))
+                     vendor family model (list->set flags)))))
             (_
              (loop vendor family model))))))))
 
@@ -192,6 +214,54 @@ (define (cpu->gcc-architecture cpu)
          ;; TODO: Recognize CENTAUR/CYRIX/NSC?
 
          "x86_64"))
+    ("aarch64"
+     (pk (cpu-architecture cpu)(cpu-vendor cpu)(cpu-family cpu) (cpu-model cpu)(cpu-flags cpu))
+     ;; Currently returns ("aarch64" #f #f #f #<<set> vhash: #<vhash 329666c0 9 pairs> insert: #<procedure %insert (t-5ce36f5c768e728-317 t-5ce36f5c768e728-319)> ref: #<procedure vhash-assoc (key vhash #:optional equal? hash)>>)
+     ;; Transcribed from GCC's list of aarch64 processors in aarch64-cores.def
+     (match (cpu-vendor cpu)
+       ("0x41"
+        (match (cpu-model cpu)
+          ((or #xd02 #xd04 #xd03 #xd07 #xd08 #xd09)
+           "armv8-a")
+          ((or #xd05 #xd0a #xd0b #xd0e #xd0d #xd41 #xd42 #xd4b #xd46 #xd43 #xd44 #xd41 #xd0c #xd4a)
+           "armv8.2-a")
+          (#xd40
+           "armv8.4-a")
+          (#xd15
+           "armv8-r")
+          ((or #xd46 #xd47 #xd48)
+           "armv9-a")))
+       ("0x42"
+        "armv8.1-a")
+       ("0x43"
+        (match (cpu-model cpu)
+          ((or #x0a0 #x0a1 #x0a2 #x0a3)
+           "armv8-a")
+          ((or #x0b0 #x0b1 #x0b2 #x0b3 #x0b4 #x0b5)
+           "armv8.2-a")
+          (#x0b8
+           "armv8.3-a")))
+       ("0x46"
+        "armv8.2-a")
+       ("0x48"
+        "armv8.2-a")
+       ("0x50"
+        "armv8-a")
+       ("0x51"
+        (match (cpu-model cpu)
+          (#xC00
+           "armv8-a")
+          (#x516
+           "armv8.1-a")
+          (#xC01
+           "armv8.4-a")))
+       ("0x53"
+        "armv8-a")
+       ("0x68"
+        "armv8-a")
+       (_
+        "armv8-a"))
+     "armv8-a")
     (architecture
      ;; TODO: AArch64.
      architecture)))
-- 
2.34.0





^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [bug#53895] [PATCH 0/5] More CPU detection
  2022-02-09 10:21 ` [bug#53895] [PATCH 1/5] guix: cpu: Rewrite based on feature flags Efraim Flashner
@ 2022-02-09 10:35   ` Ludovic Courtès
  2022-02-09 10:45     ` Efraim Flashner
  0 siblings, 1 reply; 14+ messages in thread
From: Ludovic Courtès @ 2022-02-09 10:35 UTC (permalink / raw)
  To: Efraim Flashner; +Cc: 53895

Hi!

Efraim Flashner <efraim@flashner.co.il> skribis:

> * guix/cpu.scm (cpu->gcc-architecture): Rewrite detection based on
> detected feature flags.

[...]

>       ;; Transcribed from GCC's 'host_detect_local_cpu' in driver-i386.c.
>       (or (and (= 6 (cpu-family cpu))              ;the "Pentium Pro" family
> -              (letrec-syntax ((model (syntax-rules (=>)
> -                                       ((_) #f)
> -                                       ((_ (candidate => integers ...) rest
> -                                           ...)
> -                                        (or (and (= (cpu-model cpu) integers)
> -                                                 candidate)
> -                                            ...
> -                                            (model rest ...))))))
> -                (model ("bonnel" => #x1c #x26)
> -                       ("silvermont" => #x37 #x4a #x4d #x5a #x5d)
> -                       ("core2" => #x0f #x17 #x1d)
> -                       ("nehalem" => #x1a #x1e #x1f #x2e)
> -                       ("westmere" => #x25 #x2c #x2f)
> -                       ("sandybridge" => #x2a #x2d)
> -                       ("ivybridge" => #x3a #x3e)
> -                       ("haswell" => #x3c #x3f #x45 #x46)
> -                       ("broadwell" => #x3d #x47 #x4f #x56)
> -                       ("skylake" => #x4e #x5e #x8e #x9e)
> -                       ("skylake-avx512" => #x55) ;TODO: cascadelake
> -                       ("knl" => #x57)
> -                       ("cannonlake" => #x66)
> -                       ("knm" => #x85))))
> +              (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 ...))))))
> +
> +                (if-flags ("avx" "avx512vp2intersect" "tsxldtrk" => "sapphirerapids")
> +                          ("avx" "avx512vp2intersect" => "tigerlake")
> +                          ("avx" "avx512bf16" => "cooperlake")
> +                          ("avx" "wbnoinvd" => "icelake-server")
> +                          ("avx" "avx512bitalg" => "icelake-client")
> +                          ("avx" "avx512vbmi" => "cannonlake")

In current master, the logic is:

  if it’s an intel
  then pick the model ID
  if that didn’t work
  then do feature-based detection

Here you’re removing the first part (using the Intel model ID) and
extending the second part.  Perhaps we could extend the second part but
still keep the first one?

The AMD detection code would have to go before the generic fallback case
though.

WDYT?

Ludo’.




^ permalink raw reply	[flat|nested] 14+ messages in thread

* [bug#53895] [PATCH 0/5] More CPU detection
  2022-02-09 10:21 ` [bug#53895] [PATCH 2/5] gnu: cpu: Add detection for AMD CPUs Efraim Flashner
@ 2022-02-09 10:43   ` Ludovic Courtès
  2022-02-09 10:54     ` Efraim Flashner
  2022-02-09 11:41     ` Efraim Flashner
  0 siblings, 2 replies; 14+ messages in thread
From: Ludovic Courtès @ 2022-02-09 10:43 UTC (permalink / raw)
  To: Efraim Flashner; +Cc: 53895

Efraim Flashner <efraim@flashner.co.il> 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)?

> +              (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")
             …)

> +                (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?

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 14+ messages in thread

* [bug#53895] [PATCH 0/5] More CPU detection
  2022-02-09 10:35   ` [bug#53895] [PATCH 0/5] More CPU detection Ludovic Courtès
@ 2022-02-09 10:45     ` Efraim Flashner
  2022-02-10 20:42       ` Ludovic Courtès
  0 siblings, 1 reply; 14+ messages in thread
From: Efraim Flashner @ 2022-02-09 10:45 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 53895

[-- Attachment #1: Type: text/plain, Size: 3836 bytes --]

On Wed, Feb 09, 2022 at 11:35:22AM +0100, Ludovic Courtès wrote:
> Hi!
> 
> Efraim Flashner <efraim@flashner.co.il> skribis:
> 
> > * guix/cpu.scm (cpu->gcc-architecture): Rewrite detection based on
> > detected feature flags.
> 
> [...]
> 
> >       ;; Transcribed from GCC's 'host_detect_local_cpu' in driver-i386.c.
> >       (or (and (= 6 (cpu-family cpu))              ;the "Pentium Pro" family
> > -              (letrec-syntax ((model (syntax-rules (=>)
> > -                                       ((_) #f)
> > -                                       ((_ (candidate => integers ...) rest
> > -                                           ...)
> > -                                        (or (and (= (cpu-model cpu) integers)
> > -                                                 candidate)
> > -                                            ...
> > -                                            (model rest ...))))))
> > -                (model ("bonnel" => #x1c #x26)
> > -                       ("silvermont" => #x37 #x4a #x4d #x5a #x5d)
> > -                       ("core2" => #x0f #x17 #x1d)
> > -                       ("nehalem" => #x1a #x1e #x1f #x2e)
> > -                       ("westmere" => #x25 #x2c #x2f)
> > -                       ("sandybridge" => #x2a #x2d)
> > -                       ("ivybridge" => #x3a #x3e)
> > -                       ("haswell" => #x3c #x3f #x45 #x46)
> > -                       ("broadwell" => #x3d #x47 #x4f #x56)
> > -                       ("skylake" => #x4e #x5e #x8e #x9e)
> > -                       ("skylake-avx512" => #x55) ;TODO: cascadelake
> > -                       ("knl" => #x57)
> > -                       ("cannonlake" => #x66)
> > -                       ("knm" => #x85))))
> > +              (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 ...))))))
> > +
> > +                (if-flags ("avx" "avx512vp2intersect" "tsxldtrk" => "sapphirerapids")
> > +                          ("avx" "avx512vp2intersect" => "tigerlake")
> > +                          ("avx" "avx512bf16" => "cooperlake")
> > +                          ("avx" "wbnoinvd" => "icelake-server")
> > +                          ("avx" "avx512bitalg" => "icelake-client")
> > +                          ("avx" "avx512vbmi" => "cannonlake")
> 
> In current master, the logic is:
> 
>   if it’s an intel
>   then pick the model ID
>   if that didn’t work
>   then do feature-based detection
> 
> Here you’re removing the first part (using the Intel model ID) and
> extending the second part.  Perhaps we could extend the second part but
> still keep the first one?
> 
> The AMD detection code would have to go before the generic fallback case
> though.
> 
> WDYT?
> 
> Ludo’.

in gcc-11 driver-i386.c is modified to use the 'vendor' to choose the
'processor', and then using the processor flag it runs through a list of
if statements to check feature flags, so that's what I was following.

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [bug#53895] [PATCH 0/5] More CPU detection
  2022-02-09 10:43   ` [bug#53895] [PATCH 0/5] More CPU detection Ludovic Courtès
@ 2022-02-09 10:54     ` Efraim Flashner
  2022-02-09 11:41     ` Efraim Flashner
  1 sibling, 0 replies; 14+ messages in thread
From: Efraim Flashner @ 2022-02-09 10:54 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 53895

[-- Attachment #1: Type: text/plain, Size: 2856 bytes --]

On Wed, Feb 09, 2022 at 11:43:21AM +0100, Ludovic Courtès wrote:
> Efraim Flashner <efraim@flashner.co.il> 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   <efraim@flashner.co.il>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [bug#53895] [PATCH 0/5] More CPU detection
  2022-02-09 10:43   ` [bug#53895] [PATCH 0/5] More CPU detection Ludovic Courtès
  2022-02-09 10:54     ` Efraim Flashner
@ 2022-02-09 11:41     ` Efraim Flashner
  2022-02-10 20:42       ` Ludovic Courtès
  1 sibling, 1 reply; 14+ messages in thread
From: Efraim Flashner @ 2022-02-09 11:41 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 53895

[-- Attachment #1: Type: text/plain, Size: 1674 bytes --]

On Wed, Feb 09, 2022 at 11:43:21AM +0100, Ludovic Courtès wrote:
> Efraim Flashner <efraim@flashner.co.il> skribis:
> 
> > +              (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")
>              …)

Another option would be to just move it to the bottom of the if-flags so
it should take effect then.


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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [bug#53895] [PATCH 0/5] More CPU detection
  2022-02-09 10:45     ` Efraim Flashner
@ 2022-02-10 20:42       ` Ludovic Courtès
  0 siblings, 0 replies; 14+ messages in thread
From: Ludovic Courtès @ 2022-02-10 20:42 UTC (permalink / raw)
  To: Efraim Flashner; +Cc: 53895

Hi,

Efraim Flashner <efraim@flashner.co.il> skribis:

> in gcc-11 driver-i386.c is modified to use the 'vendor' to choose the
> 'processor', and then using the processor flag it runs through a list of
> if statements to check feature flags, so that's what I was following.

Oh OK, so maybe it’s all fine after all.  Sorry for the confusion!

Ludo’.




^ permalink raw reply	[flat|nested] 14+ messages in thread

* [bug#53895] [PATCH 0/5] More CPU detection
  2022-02-09 11:41     ` Efraim Flashner
@ 2022-02-10 20:42       ` Ludovic Courtès
  2022-02-13 13:04         ` bug#53895: " Efraim Flashner
  0 siblings, 1 reply; 14+ messages in thread
From: Ludovic Courtès @ 2022-02-10 20:42 UTC (permalink / raw)
  To: Efraim Flashner; +Cc: 53895

Efraim Flashner <efraim@flashner.co.il> skribis:

>> What we could do is extend ‘if-flags’ so that it can optionally check
>> for a family number:
>> 
>>   (if-flags ((family 22) "movbe" => "btver2")
>>              …)
>
> Another option would be to just move it to the bottom of the if-flags so
> it should take effect then.

Yes, your call!

Ludo’.




^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#53895: [PATCH 0/5] More CPU detection
  2022-02-10 20:42       ` Ludovic Courtès
@ 2022-02-13 13:04         ` Efraim Flashner
  0 siblings, 0 replies; 14+ messages in thread
From: Efraim Flashner @ 2022-02-13 13:04 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 53895-done

[-- Attachment #1: Type: text/plain, Size: 1075 bytes --]

On Thu, Feb 10, 2022 at 09:42:44PM +0100, Ludovic Courtès wrote:
> Efraim Flashner <efraim@flashner.co.il> skribis:
> 
> >> What we could do is extend ‘if-flags’ so that it can optionally check
> >> for a family number:
> >> 
> >>   (if-flags ((family 22) "movbe" => "btver2")
> >>              …)
> >
> > Another option would be to just move it to the bottom of the if-flags so
> > it should take effect then.
> 
> Yes, your call!

Just moving it to the end didn't end up being enough to make it work, my
processor was determined to be <unspecified>. I changed it to an 'or'
which seemed to make it work, and my testing seemed to show that it
would work (alternating substituting junk and my processor flags to make
it obviously one or the other).

Thanks for the review and the feedback. And for doing the work in the
first place!

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-02-13 13:08 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 10:16 [bug#53895] [PATCH 0/5] More CPU detection Efraim Flashner
2022-02-09 10:21 ` [bug#53895] [PATCH 1/5] guix: cpu: Rewrite based on feature flags Efraim Flashner
2022-02-09 10:35   ` [bug#53895] [PATCH 0/5] More CPU detection Ludovic Courtès
2022-02-09 10:45     ` Efraim Flashner
2022-02-10 20:42       ` Ludovic Courtès
2022-02-09 10:21 ` [bug#53895] [PATCH 2/5] gnu: cpu: Add detection for AMD CPUs Efraim Flashner
2022-02-09 10:43   ` [bug#53895] [PATCH 0/5] More CPU detection Ludovic Courtès
2022-02-09 10:54     ` Efraim Flashner
2022-02-09 11:41     ` Efraim Flashner
2022-02-10 20:42       ` Ludovic Courtès
2022-02-13 13:04         ` bug#53895: " Efraim Flashner
2022-02-09 10:21 ` [bug#53895] [PATCH 3/5] gnu: gcc: Add compiler-cpu-architectures for aarch64 Efraim Flashner
2022-02-09 10:21 ` [bug#53895] [PATCH 4/5] gnu: gcc: Add compiler-cpu-architectures for armhf Efraim Flashner
2022-02-09 10:21 ` [bug#53895] [PATCH 5/5] WIP: guix: cpu: Add detection for aarch64 CPUs Efraim Flashner

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.