From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id YEWBOPacA2IjwwAAgWs5BA (envelope-from ) for ; Wed, 09 Feb 2022 11:52:38 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id WMQgMfacA2KJVAEAG6o9tA (envelope-from ) for ; Wed, 09 Feb 2022 11:52:38 +0100 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 6F8F519271 for ; Wed, 9 Feb 2022 11:52:38 +0100 (CET) Received: from localhost ([::1]:38332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHkaT-0002Ni-KE for larch@yhetil.org; Wed, 09 Feb 2022 05:52:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHk93-0002aE-GR for guix-patches@gnu.org; Wed, 09 Feb 2022 05:24:17 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:56071) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHk8o-0001ej-Dg for guix-patches@gnu.org; Wed, 09 Feb 2022 05:24:16 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nHk8o-00083b-Ae for guix-patches@gnu.org; Wed, 09 Feb 2022 05:24:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53895] [PATCH 2/5] gnu: cpu: Add detection for AMD CPUs. Resent-From: Efraim Flashner Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 09 Feb 2022 10:24:02 +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.164440218830865 (code B ref 53895); Wed, 09 Feb 2022 10:24:02 +0000 Received: (at 53895) by debbugs.gnu.org; 9 Feb 2022 10:23:08 +0000 Received: from localhost ([127.0.0.1]:49959 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHk7w-00081l-5R for submit@debbugs.gnu.org; Wed, 09 Feb 2022 05:23:08 -0500 Received: from flashner.co.il ([178.62.234.194]:50040) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHk7u-00080t-KW for 53895@debbugs.gnu.org; Wed, 09 Feb 2022 05:23:07 -0500 Received: from localhost (unknown [37.46.46.251]) by flashner.co.il (Postfix) with ESMTPSA id EA4C5403CD; Wed, 9 Feb 2022 10:23:00 +0000 (UTC) From: Efraim Flashner Date: Wed, 9 Feb 2022 12:21:48 +0200 Message-Id: X-Mailer: git-send-email 2.34.0 In-Reply-To: References: MIME-Version: 1.0 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" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1644403958; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: 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; bh=8TmJ36awPpPgk7g0mbZxNUsERDJ0zLGtp4K++DB8mp4=; b=tQgVFGTGMG78CChO38K2F8jFDRs/3XZ5bmHv/lZdY2TI9Y4gqh/7HlnPIgEtox89V7uxg8 y7LT96ucF+Gn7TQ6gqjvQ2uewvjGAhqUUPF0hM6OtqnJX8cwkas5zxN+oyLbUlr9s+gQJj HFa49yp9HIicSGR+O9APe5clggqhoAJ86PzNES4xW2GrCbqe8bPFgjlH7Nv/BBC6cXffRW dlVY7B61ct5fCPPSkKgpU8so/4jW7eXK7WXBrercg7GFm2ScN3DP9qNSmI7kwv3++HdszN AZeL0tfXj3wQi0WRzN79lgKBFnQrkxJe5aXEvVN640VRDrmd2nGLfjrPS1kRhA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644403958; a=rsa-sha256; cv=none; b=PjsvvQThNjb/3oCL/0ceqXWEvMdg9s7fHtom5d6G5W2IMrD6OuNBv0VUUGNVR+OG/sZxrC doGIJJKjTXK71h2Qbp8fjD/Ytgw+hgqMkDeXW/lHs0RXz9rYtF14mrBHlkqOk9nwnC0GVG wU7Smh2Qceq/WrUfRTkCMps5c/4UY0MB3mkenw78YNizZGnFKLbZE8WqoHv1oEqDx7yLqy E0GIMKIH0QTxP6dPcWrIArmqVly/m//Q1S0ueZYaTHH7eUtMvMAw+biUXvVfo/UXhgh2Ep HEsv1wy6l9y95GF7A+D7ZYI58MLM7CGk5Ic6v+5+h9PtFjVA9brawG7D0HK3rQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; 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-Spam-Score: -2.13 Authentication-Results: aspmx1.migadu.com; dkim=none; 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: 6F8F519271 X-Spam-Score: -2.13 X-Migadu-Scanner: scn0.migadu.com X-TUID: N4ToGxRNHYt+ * guix/cpu.scm : 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 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