From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id cIt/NNJakWTtJAEASxT56A (envelope-from ) for ; Tue, 20 Jun 2023 09:52:50 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id UJJcNNJakWS8EgEA9RJhRA (envelope-from ) for ; Tue, 20 Jun 2023 09:52:50 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9E7231121E for ; Tue, 20 Jun 2023 09:52:50 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qBW9n-0003nI-MS; Tue, 20 Jun 2023 03:52:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qBW9l-0003mA-CZ for guix-patches@gnu.org; Tue, 20 Jun 2023 03:52:06 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBW9l-0006NY-36; Tue, 20 Jun 2023 03:52:05 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qBW9i-00055z-EO; Tue, 20 Jun 2023 03:52:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#64188] [PATCH 2/8] guix: cpu: Add inexact CPU matching. Resent-From: Efraim Flashner Original-Sender: "Debbugs-submit" Resent-CC: mail@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 20 Jun 2023 07:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64188 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 64188@debbugs.gnu.org Cc: Efraim Flashner , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 64188-submit@debbugs.gnu.org id=B64188.168724747619446 (code B ref 64188); Tue, 20 Jun 2023 07:52:02 +0000 Received: (at 64188) by debbugs.gnu.org; 20 Jun 2023 07:51:16 +0000 Received: from localhost ([127.0.0.1]:57949 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qBW8y-00053Z-0h for submit@debbugs.gnu.org; Tue, 20 Jun 2023 03:51:16 -0400 Received: from mail-wr1-f47.google.com ([209.85.221.47]:52732) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qBW8w-000535-7h for 64188@debbugs.gnu.org; Tue, 20 Jun 2023 03:51:14 -0400 Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-30e3caa6aa7so4364724f8f.1 for <64188@debbugs.gnu.org>; Tue, 20 Jun 2023 00:51:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687247468; x=1689839468; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=GvOp7dpftE/82t5oSPr/dcYhFChSum/lRb9TF6+vQPg=; b=CxfdHX97rzieiMXWSLZTg69dic0Z6Kr52ywrCTC9OzKgfGL1sG4z7n/xYEGmk4X9A8 pMyoYXRpctz4Cta95fXIYz74CMx9fAPSaKvd1DMNnLEQ5jIkPvivOJWDgY5R2dzHFSMx wmVfYWb1iBbZ7jhXFw29gCVeyM5H9npYpQAk09upZ5ADw5XfD6HSK4qZri/S2dkbkqR5 +zA+FWLNLVIPb1gx/4nWHnK9kbRWSSp+wzzluIt0XR2roaZnQHqdABup0RsfcyG6swwa f8iOgQKFojoQYOU1NwRgxGZGskSuBCaJBT5vZjIJJ7WeG7BwK1hKyVMsRvTb+18PRIV5 1cvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687247468; x=1689839468; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=GvOp7dpftE/82t5oSPr/dcYhFChSum/lRb9TF6+vQPg=; b=k3C7iD5CLWb73qk8ap6AXj7OPxAVMdBoCow48PEvajQ6T6jNVbm8aZi8OSFgPsz+ab VWL933kVGvG/LQnwGj+KkfEILHSlLc69p5FxmfJbrLCEHP9oLzZ1mM4HLcj6umt5pnLD KnIIVroyTyvTeEyYw/bP8k6RJ4mh06lFG1jhsrRvAS+CvDmUbh7w3dyvO0FOV8aCnHsP oi5aVFeuiTUHq6vUVfmpt9M/E5IaawZwZ3Uj+66ACV5TzxuKKOijmYnD0v08YJNKGkJH x0eBiDoULAq3j1ppAZQV/+ZlY7I74DSD3p6U65V7TcVknA/Xe2L9OkUBjEH4ar3OxVMS mFyQ== X-Gm-Message-State: AC+VfDwkPiFGy/HtSR+HuC+jS5X3Fwjxf8BIgSISBf5lgyqvpnzjPCj2 wDP2UzInIfLs5tjqeuUXf2kImYVJi4g9ITYC X-Google-Smtp-Source: ACHHUZ61+iLhFnmOjFejYMjKzL4IbtbO7Zu08eEoaCNFBm0NzY7vDysKXP898Zs7gxk0i3p2Uz+mPg== X-Received: by 2002:a05:6000:1370:b0:311:1a45:3606 with SMTP id q16-20020a056000137000b003111a453606mr9216934wrz.30.1687247468514; Tue, 20 Jun 2023 00:51:08 -0700 (PDT) Received: from localhost ([188.120.129.124]) by smtp.gmail.com with ESMTPSA id y14-20020a5d470e000000b0030647449730sm1356830wrq.74.2023.06.20.00.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 00:51:08 -0700 (PDT) From: Efraim Flashner Date: Tue, 20 Jun 2023 10:51:03 +0300 Message-Id: <6ecddc871328fcb3b494f3e6c1aafc6ad1d20830.1687247150.git.efraim@flashner.co.il> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1687247570; a=rsa-sha256; cv=none; b=E+T/qtrcLHFUA6zE1XSrrnbqUt0UpiHbdnu6cs8HpvgNRsE1UasMEc8MnvX9VfXvEeQMee yvN32y+YzxnijyvepED+2hvAgEcLNFaBMhMRPp52ffAtfJKKe91pwZ7Wt4Jcy/amA3+OAe HnX9FqRpnQEI4sAbUtIjegaSqFEmq5oDWT2/pHDl1KqlJeGjcyyr67f26fxSyTjsQaTi55 VYKfMGGUnbOyuZobrEGgnT5N1xnm40KGhrSLdeBN90CIRDOjcYU2AcXujyiE1zUE+h3cGY bMTZ97erB/oP2kD5t9WGU82um38OYLb08LOsMywHCDfEHDQtUjr1Neq1RP7b0g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=CxfdHX97; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1687247570; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=GvOp7dpftE/82t5oSPr/dcYhFChSum/lRb9TF6+vQPg=; b=L2lHAHzghUdEBlTYlU3dcJsCbdxG8FZsza1hg8SuctlnO6b1Jg2sOCbW/w1kBGcYbEdnuj AsomUhb6fqDG+tsttDOpkDLeQu++U015/OQ4aQ5OhVC/Ayjyu6ngx+63Oo/amOf1+QXqUX 5pYEbTZY3N2MWy4MwaAmTKgTMo589H5CfVRr3WLhaBexg436D+cP1DyxJvLNmmlq2igTPY WvKIt3F67CWtJXHwqsDF4NIWMbmtRLA1+UsyKeSROu1v/712PnBpURzx56lnPdxzIoxqON xzkOH9E6PpSG/tQRceTMGO1vCFPGybGcau7ssiCB3evWqhjZdMrWMEVHZRgu9g== Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=CxfdHX97; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Scanner: scn0.migadu.com X-Migadu-Spam-Score: 1.26 X-Spam-Score: 1.26 X-Migadu-Queue-Id: 9E7231121E X-TUID: bg2w4r7O16Ym * guix/cpu.scm (cpu->generic-architecture): New variable. --- guix/cpu.scm | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/guix/cpu.scm b/guix/cpu.scm index 45e1abeed7..e6102e3d14 100644 --- a/guix/cpu.scm +++ b/guix/cpu.scm @@ -32,7 +32,8 @@ (define-module (guix cpu) cpu-model cpu-flags - cpu->gcc-architecture)) + cpu->gcc-architecture + cpu->generic-architecture)) ;;; Commentary: ;;; @@ -285,3 +286,36 @@ (define (cpu->gcc-architecture cpu) (architecture ;; TODO: More architectures architecture))) + +(define (cpu->generic-architecture cpu) + "Return the architecture name, suitable for inexact architecture optimizations, +that corresponds to CPU, a record as returned by 'current-cpu'." + (match (cpu-architecture cpu) + ("x86_64" + (or (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 + ;; https://gitlab.com/x86-psABIs/x86-64-ABI/-/blob/master/x86-64-ABI/low-level-sys-info.tex + ;; v4: AVX512F, AVX512BW, AVX512CD, AVX512DQ, AVX512VL + ;; v3: AVX, AVX2, BMI1, BMI2, F16C, FMA, LZCNT, MOVBE, OSXSAVE + ;; v2: CMPXCHG16B, LAHF, SAHF, POPCNT, SSE3, SSE4.1, SSE4.2, SSSE3 + ("avx512f" "avx512bw" "abx512cd" "abx512dq" "avx512vl" + "avx" "avx2" "bmi1" "bmi2" "f16c" "fma" "movbe" + "popcnt" "sse3" "sse4_1" "sse4_2" "ssse3" => "x86_64-v4") + ("avx" "avx2" "bmi1" "bmi2" "f16c" "fma" "movbe" + "popcnt" "sse3" "sse4_1" "sse4_2" "ssse3" => "x86_64-v3") + ("popcnt" "sse3" "sse4_1" "sse4_2" "ssse3" => "x86_64-v2") + (_ => "x86_64-v1"))) + "x86_64-v1")) + (architecture + ;; TODO: More architectures + architecture))) -- Efraim Flashner רנשלפ םירפא GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351 Confidentiality cannot be guaranteed on emails sent or received unencrypted