From patchwork Wed Feb 9 10:21:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Efraim Flashner X-Patchwork-Id: 37131 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 37FED27BBEA; Wed, 9 Feb 2022 10:35:34 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id E212F27BBE9 for ; Wed, 9 Feb 2022 10:35:33 +0000 (GMT) Received: from localhost ([::1]:45230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHkJw-0003lV-SV for patchwork@mira.cbaines.net; Wed, 09 Feb 2022 05:35:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:32890) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHk7q-0002D2-Qy for guix-patches@gnu.org; Wed, 09 Feb 2022 05:23:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:56058) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHk7p-0001aI-Ug for guix-patches@gnu.org; Wed, 09 Feb 2022 05:23:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nHk7p-000810-QF for guix-patches@gnu.org; Wed, 09 Feb 2022 05:23:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53895] [PATCH 1/5] guix: cpu: Rewrite based on feature flags. Resent-From: Efraim Flashner Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 09 Feb 2022 10:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53895 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 53895@debbugs.gnu.org Cc: Efraim Flashner Received: via spool by 53895-submit@debbugs.gnu.org id=B53895.164440215630768 (code B ref 53895); Wed, 09 Feb 2022 10:23:01 +0000 Received: (at 53895) by debbugs.gnu.org; 9 Feb 2022 10:22:36 +0000 Received: from localhost ([127.0.0.1]:49955 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHk7P-00080B-RA for submit@debbugs.gnu.org; Wed, 09 Feb 2022 05:22:36 -0500 Received: from flashner.co.il ([178.62.234.194]:50034) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHk7O-0007zy-4O for 53895@debbugs.gnu.org; Wed, 09 Feb 2022 05:22:34 -0500 Received: from localhost (unknown [37.46.46.251]) by flashner.co.il (Postfix) with ESMTPSA id 394FB403CD; Wed, 9 Feb 2022 10:22:28 +0000 (UTC) From: Efraim Flashner Date: Wed, 9 Feb 2022 12:21:47 +0200 Message-Id: <848868e0ad4427a976bec55968f82a3469009fb9.1644401681.git.efraim@flashner.co.il> X-Mailer: git-send-email 2.34.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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 +;;; Copyright © 2022 Efraim Flashner ;;; ;;; 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.