From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id QPolE7CHmWQ9gAEASxT56A (envelope-from ) for ; Mon, 26 Jun 2023 14:42:24 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id YIfdErCHmWSVrAAAauVa8A (envelope-from ) for ; Mon, 26 Jun 2023 14:42:24 +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 D8057170C for ; Mon, 26 Jun 2023 14:42:23 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qDlWJ-0000Bp-Tv; Mon, 26 Jun 2023 08:40:40 -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 1qDlVq-0008J4-P5 for guix-patches@gnu.org; Mon, 26 Jun 2023 08:40:12 -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 1qDlVl-0005wV-Lb; Mon, 26 Jun 2023 08:40:09 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qDlVj-0004IJ-6t; Mon, 26 Jun 2023 08:40:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#64188] [PATCH v2 2/7] guix: cpu: Add generalized 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: Mon, 26 Jun 2023 12:40:03 +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.168778315216362 (code B ref 64188); Mon, 26 Jun 2023 12:40:03 +0000 Received: (at 64188) by debbugs.gnu.org; 26 Jun 2023 12:39:12 +0000 Received: from localhost ([127.0.0.1]:44760 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qDlUu-0004Fn-DN for submit@debbugs.gnu.org; Mon, 26 Jun 2023 08:39:12 -0400 Received: from mail-lf1-f50.google.com ([209.85.167.50]:48247) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qDlUn-0004EV-Ph for 64188@debbugs.gnu.org; Mon, 26 Jun 2023 08:39:06 -0400 Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-4f86dbce369so4158064e87.0 for <64188@debbugs.gnu.org>; Mon, 26 Jun 2023 05:39:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687783140; x=1690375140; 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=CXBRcMEcNe1ySkaWYCr/u8mNOd3kmsx59TQ9m6l9814=; b=W5/SMplaOd6C7EBlEIMyTTIFOZHwM7+AaAkm1RbzPjicxmdiHFaGAX+xvdjkjxa4zv NQ1ZxKPv1pL6LFwTpU5dQsO+eO46siXqkDbMIL2d87rOwnKIP5gFN5cVVDL+L72UxOON 2410RdSuq9uIiuSW7exjl7NeQTcw6dGgHo0WYPT5fIQQCx+Em9E+CnstUICrREx+H+ml NkObDCeyP2CQO3/FkDin5xhas91f7BfPYNxcehB2N3XjxtUnzHox0p8NdAJYvW+wTJJs lZo0S25H2abndtce/3T41oYJdyRbjvoIeUummWVBZd4lmatzzFFwLQYc+DYFUAnylPQx 0QHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687783140; x=1690375140; 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=CXBRcMEcNe1ySkaWYCr/u8mNOd3kmsx59TQ9m6l9814=; b=b9/1yNv+UxbDuC8kN8I7D6HbdvO6WUtIKkW3oUzLFItM/Mxr8d140Dq0Xm0AnMYjCz 62JYSt00KiWk4u+jfGpoOFRPHS9fWWcNJneSYAB/u8v32vJ6PqJe8GZ3zbVYryUcv/yi j3YD+wd7CdcoFpZNPOVdIupkDWW/JBFDarz6bfiWMgFCWyMQZFUOdzvtTlCrLCD4gQ0D 2f6nE0tRYSgtKBOZhO0jEezXS4dHUikNgLKajkfmu4VgSvVJJVf4YffA2eYolKv7a74y /YsLsPMz95Oe4rOxab9DCavN2M6dxyZhgUMiQh0wg+Mmovjxp4Me83ADAToJcXv05luy tJgw== X-Gm-Message-State: AC+VfDxb4ciI4cWdUbDaVawMu+yNbhRNauxO+nJ+dxkNoCbNgLtTiZND 8Y0+AOw3/Ztk3j/b9qcktvMyQLnOhUSu1w== X-Google-Smtp-Source: ACHHUZ6/lx9TjRlfrj9Kh9axDestorK5vIJoWpJ9qek15aLt3SpK2tAUNC5QfWC1H/lyh/P4OM1xZQ== X-Received: by 2002:a19:7b06:0:b0:4f3:a051:58df with SMTP id w6-20020a197b06000000b004f3a05158dfmr16387854lfc.59.1687783139781; Mon, 26 Jun 2023 05:38:59 -0700 (PDT) Received: from localhost ([188.120.129.124]) by smtp.gmail.com with ESMTPSA id y17-20020a1c4b11000000b003f90a604885sm7598171wma.34.2023.06.26.05.38.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 05:38:59 -0700 (PDT) From: Efraim Flashner Date: Mon, 26 Jun 2023 15:38:38 +0300 Message-Id: <7bd5d1f49f921827954ff0373121a52c0cbc0ad6.1687781377.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1687783344; 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=CXBRcMEcNe1ySkaWYCr/u8mNOd3kmsx59TQ9m6l9814=; b=uo57SqYkd6KRJaQZy1VNX7PfhgpH4Jw24aDQXljQTBdUVFfmw7VhCOuY0XoArj5xhZCaOs D2ke9K22qUdW6M3wgLzQ0btCGrKHlJl+Rt++AyVq7uQoCy83tdiJDv9IyJfvsDqJvAYCS5 BlFYCFLd46cxpL6mV0OhtFztcRArPZjuemwOMzUD5F5fTfq2nB+cJS5RX8ALKyUUbtv9ga gUq8wDPcR+yxpD1SwvsbiY/OGOBS0RsLs2a8ZI2o/kqpUOTm6Vq1IAP9Z5xcj8TF8WyjIK WXZmPOB5Lb9D94r877N1MT9WqBkFeG2DZ/avMfgUiuOiu3R81SwueQ/lU73vpw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b="W5/SMpla"; 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-Seal: i=1; s=key1; d=yhetil.org; t=1687783344; a=rsa-sha256; cv=none; b=Cz8eAmH+e/zrmm6iP0J0ccbkwM7aey7NHSZy78kfzcrrgQs+F3CxSTgDya6VqidGs5DLf1 TY7mcDoiw6xsl2DMF0Cfm4hQyX9YrRl8x2pcg/oB9vupgjNTMo+Dm05zaJdJnk1OiAX7GZ Un41Fe85SjoqzmLN4XmRFuOWS7i/au/qaT8DgabVQedtBWJgWaXAyPrBHsLO+IXidmrhSO D1mg1tq4IfAGSzcKxUF4psbcR9ZiQha8Lt7Zs4J2BeDSWQq6/CR/zYMb20m8vhE/zEjxky uT4rrL2u78t0mLu2ZEJL8IuYpsv3etOGC3asbuTvvLiy6OXoHpYV6Cn777mOFQ== X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: 0.25 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b="W5/SMpla"; 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-Queue-Id: D8057170C X-Spam-Score: 0.25 X-TUID: ZHbdL8SbV8e6 * guix/cpu.scm (cpu->micro-architecture-level): New variable. --- guix/cpu.scm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/guix/cpu.scm b/guix/cpu.scm index 45e1abeed7..3fc12327ed 100644 --- a/guix/cpu.scm +++ b/guix/cpu.scm @@ -285,3 +285,36 @@ (define (cpu->gcc-architecture cpu) (architecture ;; TODO: More architectures architecture))) + +(define (cpu->micro-architecture-level cpu) + "Return a micro-architecture name, suitable for generalized optimizations that +correspond roughly 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