diff mbox series

[bug#69581,05/11] guix: cpu: Enable tuning for i686-linux.

Message ID 33a8d78738553f464f5974a0d2cba981e65ced78.1709722620.git.efraim@flashner.co.il
State New
Headers show
Series CPU tuning patches | expand

Commit Message

Efraim Flashner March 6, 2024, 11:06 a.m. UTC
* gnu/packages/gcc.scm (gcc-7, gcc-10, gcc-11, gcc-12, gcc-13)
[properties]: In compiler-cpu-architectures use the
x86_64-micro-architectures list for i686.
* guix/cpu.scm (cpu->gcc-architecture): Expand the x86_64 case to also
support i686.

Change-Id: I0b820ceb715960db5e702814fa278dc8c619a836
---
 gnu/packages/gcc.scm | 5 +++++
 guix/cpu.scm         | 6 ++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

Comments

Ludovic Courtès March 6, 2024, 6:05 p.m. UTC | #1
Efraim Flashner <efraim@flashner.co.il> skribis:

> * gnu/packages/gcc.scm (gcc-7, gcc-10, gcc-11, gcc-12, gcc-13)
> [properties]: In compiler-cpu-architectures use the
> x86_64-micro-architectures list for i686.
> * guix/cpu.scm (cpu->gcc-architecture): Expand the x86_64 case to also
> support i686.

[...]

> +++ b/gnu/packages/gcc.scm
> @@ -673,6 +673,7 @@ (define-public gcc-7
>       `((compiler-cpu-architectures
>          ("aarch64" ,@%gcc-7.5-aarch64-micro-architectures)
>          ("armhf" ,@%gcc-7.5-armhf-micro-architectures)
> +        ("i686" ,@%gcc-7.5-x86_64-micro-architectures)
>          ("x86_64" ,@%gcc-7.5-x86_64-micro-architectures))

Wait, that wouldn’t work on an actual i686 CPU, right?

I was surprised to see that GCC built for i686 accepts those flags:

  guix shell -s i686-linux gcc-toolchain -- gcc -march=skylake /tmp/t.c
  guix shell -s i686-linux gcc-toolchain -- gcc -march=x86-64-v4 /tmp/t.c

If GCC agrees, so be it.  LGTM!
Efraim Flashner March 7, 2024, 9:09 a.m. UTC | #2
On Wed, Mar 06, 2024 at 07:05:03PM +0100, Ludovic Courtès wrote:
> Efraim Flashner <efraim@flashner.co.il> skribis:
> 
> > * gnu/packages/gcc.scm (gcc-7, gcc-10, gcc-11, gcc-12, gcc-13)
> > [properties]: In compiler-cpu-architectures use the
> > x86_64-micro-architectures list for i686.
> > * guix/cpu.scm (cpu->gcc-architecture): Expand the x86_64 case to also
> > support i686.
> 
> [...]
> 
> > +++ b/gnu/packages/gcc.scm
> > @@ -673,6 +673,7 @@ (define-public gcc-7
> >       `((compiler-cpu-architectures
> >          ("aarch64" ,@%gcc-7.5-aarch64-micro-architectures)
> >          ("armhf" ,@%gcc-7.5-armhf-micro-architectures)
> > +        ("i686" ,@%gcc-7.5-x86_64-micro-architectures)
> >          ("x86_64" ,@%gcc-7.5-x86_64-micro-architectures))
> 
> Wait, that wouldn’t work on an actual i686 CPU, right?
> 
> I was surprised to see that GCC built for i686 accepts those flags:
> 
>   guix shell -s i686-linux gcc-toolchain -- gcc -march=skylake /tmp/t.c
>   guix shell -s i686-linux gcc-toolchain -- gcc -march=x86-64-v4 /tmp/t.c
> 
> If GCC agrees, so be it.  LGTM!

I checked with `guix build foo --system=i686-linux --tune=znver2` and
everything just worked. That's definitely a Guix special, since we don't
have multilib support.
diff mbox series

Patch

diff --git a/gnu/packages/gcc.scm b/gnu/packages/gcc.scm
index 3555d12c44..c8902de6a0 100644
--- a/gnu/packages/gcc.scm
+++ b/gnu/packages/gcc.scm
@@ -673,6 +673,7 @@  (define-public gcc-7
      `((compiler-cpu-architectures
         ("aarch64" ,@%gcc-7.5-aarch64-micro-architectures)
         ("armhf" ,@%gcc-7.5-armhf-micro-architectures)
+        ("i686" ,@%gcc-7.5-x86_64-micro-architectures)
         ("x86_64" ,@%gcc-7.5-x86_64-micro-architectures))
        ,@(package-properties gcc-6)))))
 
@@ -729,6 +730,7 @@  (define-public gcc-10
     `((compiler-cpu-architectures
        ("aarch64" ,@%gcc-10-aarch64-micro-architectures)
        ("armhf" ,@%gcc-10-armhf-micro-architectures)
+       ("i686" ,@%gcc-10-x86_64-micro-architectures)
        ("x86_64" ,@%gcc-10-x86_64-micro-architectures))
       ,@(package-properties gcc-8)))))
 
@@ -764,6 +766,7 @@  (define-public gcc-11
     `((compiler-cpu-architectures
        ("aarch64" ,@%gcc-11-aarch64-micro-architectures)
        ("armhf" ,@%gcc-11-armhf-micro-architectures)
+       ("i686" ,@%gcc-11-x86_64-micro-architectures)
        ("x86_64" ,@%gcc-11-x86_64-micro-architectures))
       ,@(package-properties gcc-8)))))
 
@@ -786,6 +789,7 @@  (define-public gcc-12
     `((compiler-cpu-architectures
        ("aarch64" ,@%gcc-12-aarch64-micro-architectures)
        ("armhf" ,@%gcc-12-armhf-micro-architectures)
+       ("i686" ,@%gcc-12-x86_64-micro-architectures)
        ("x86_64" ,@%gcc-12-x86_64-micro-architectures))
       ,@(package-properties gcc-11)))))
 
@@ -808,6 +812,7 @@  (define-public gcc-13
      `((compiler-cpu-architectures
         ("aarch64" ,@%gcc-13-aarch64-micro-architectures)
         ("armhf" ,@%gcc-13-armhf-micro-architectures)
+        ("i686" ,@%gcc-13-x86_64-micro-architectures)
         ("x86_64" ,@%gcc-13-x86_64-micro-architectures))
        ,@(package-properties gcc-11)))))
 
diff --git a/guix/cpu.scm b/guix/cpu.scm
index 6f9e8daa61..840215cff0 100644
--- a/guix/cpu.scm
+++ b/guix/cpu.scm
@@ -113,7 +113,7 @@  (define (cpu->gcc-architecture cpu)
   "Return the architecture name, suitable for GCC's '-march' flag, that
 corresponds to CPU, a record as returned by 'current-cpu'."
   (match (cpu-architecture cpu)
-    ("x86_64"
+    ((or "x86_64" "i686")
      ;; Transcribed from GCC's 'host_detect_local_cpu' in driver-i386.cc.
      (letrec-syntax ((if-flags (syntax-rules (=>)
                                  ((_)
@@ -200,7 +200,9 @@  (define (cpu->gcc-architecture cpu)
 
          ;; TODO: Recognize CENTAUR/CYRIX/NSC?
 
-         "x86-64")))
+         (match (cpu-architecture cpu)
+           ("x86_64" "x86-64")
+           (_ "generic")))))
     ("aarch64"
      ;; Transcribed from GCC's list of aarch64 processors in aarch64-cores.def
      ;; What to do with big.LITTLE cores?