From patchwork Thu Dec 28 01:42:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 183622 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1760234dyb; Wed, 27 Dec 2023 17:50:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnyqTANQ8dfNOI9SL7ylX7ka0iMFGNHDcDaOuTqncTrJrPTBesYJiNZYGI4JawH2YaYE8e X-Received: by 2002:a17:902:d2cb:b0:1d4:2330:85a3 with SMTP id n11-20020a170902d2cb00b001d4233085a3mr4264717plc.20.1703728203182; Wed, 27 Dec 2023 17:50:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703728203; cv=none; d=google.com; s=arc-20160816; b=S3gNNGNBZOwfuFzrSyDfcrbBPOPVi4pjq7EOnNwvHxIzqxLiyhf6YR4cFZFRz39E3g x1NWh9IwZK8Uop92TbN1NOz8MtSYjm89EQ8dQBFQv6JuSa+FdKUQCZEU0y6SGGGIPNMO 9Z1xyZr0v2nCIJqYfSPTVYixoHUQ+vGhzTKUQV61MSar9TBwzes3TMFoR8mdhzk4JXBH TzRUiTeLkNkNnVw595S0XphSW6wJVwlPZ8vgg6uYvK01MsaiEQ2Qc1pRpyB8TmTOZgro sNRRXfr6Se9kw03obN9ETIOX8HBRUklOhQ09DzWGcm3uUA3rpm1CyPIjRGAhWJNY8wlJ 2Miw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cNUGRAFHmKzY6lG9DcfUZlQ4QTwCBjkCL5t9hP4xKAE=; fh=xcb3qhkLQEi6t+Vw3J1T1wFra1a2BdIsNlygM9Jzpag=; b=oGlLh3lvNQl4Q9ySRZraITrUK1ZQrGheoI4hPlMx8GAyEq/rT4SBTxqBJkfWTVwvv4 8oxr/1BwOvIBWh/D/i53ceS1Cmi2LZd3TSaNSwDADXtc8wAnU9h40AlzxKC7NNWZNmPn sqBciyktDiKxAo3/1HmL63WGvQdYzdIbT/VAE3eHt6ShFUa6a1rsoRPot09BRFL8AYsI Z+niq4J4soTgW2pu7UDd+PK5QHAuiLRgdqhD90n8nJdo9Sjmodcl2BLFs8shzdNzbWT7 UeFGrVk30TMky3vUM+4sbqKlANbg2NAXifdDPJ9/uGkVy/QENr8WN3CbN4rG44uDbaTm vOzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=GqNicyL4; spf=pass (google.com: domain of linux-kernel+bounces-12380-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12380-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x15-20020a170902a38f00b001d38d9dee98si12076217pla.573.2023.12.27.17.50.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 17:50:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12380-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=GqNicyL4; spf=pass (google.com: domain of linux-kernel+bounces-12380-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12380-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E041AB230E2 for ; Thu, 28 Dec 2023 01:46:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 69393AD57; Thu, 28 Dec 2023 01:42:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="GqNicyL4" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 301C3BE73 for ; Thu, 28 Dec 2023 01:42:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-oo1-f48.google.com with SMTP id 006d021491bc7-594c7241fa9so894489eaf.0 for ; Wed, 27 Dec 2023 17:42:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1703727759; x=1704332559; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cNUGRAFHmKzY6lG9DcfUZlQ4QTwCBjkCL5t9hP4xKAE=; b=GqNicyL4HRL32ZlN0VfuvcMGrPr8Ec3ZI1q0Dx2AbK1QdgMQxIa4SOwedFwZHhHw9o Tzge5pdNAGVg9SB4lKcOcg0OcidwWRd0niq6G5xGMv1aNRjvC9htZk5hh15tyG8mre89 emtFnBn+cWSGhdr2oeWMAoUs3EUG746eOtMqpz4jGeXcZzEOxndxUJm3yriiRhPtEJvC ySqwfWOueZNzB2unRwfUJbKuAsb2WfJWd+MYMrdOZ7AvzGpNw8LKLD+gzT2ZYl3MZnKq CVjSzOjbP379aTv718iE+AjGteQsrnO8tSJYb4OwNFRqpv12xFAhllkgBFhrTNypVpY4 M/Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703727759; x=1704332559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cNUGRAFHmKzY6lG9DcfUZlQ4QTwCBjkCL5t9hP4xKAE=; b=NOE1pSjXlmJjYY6D+DfmSmp2u+Uu00vgDx4k8Rs1RyiIL8Gz5lenht6GafpWIVgjXr FhJMQvFro65IDRrr02T7RuzkdeXohteoAjEK8V8wSt4dLiAlJuq0Dh4cDAJW2VIVkjMH mO2fOgeqpDiBOC12xvnKmmzNCNpXFDcT/4Ts44Yt3iiME+HGvxT4U4v7XrbRNs1lYaU2 LaZHhqJfd5YJuRs3w+K53vDhDtFi386yVRYmJroEqGBPHMGMYqTwufjA9D3AgxvwK5yH ET3E5pHOAU1xEsRUB8u/4qI2a8lBCtVD6xRQN4euTBB8/qW4UwCJjzj8gXiJoiBabWT2 L9ig== X-Gm-Message-State: AOJu0YzclPrpbkZsRatpC2oW8JKjOc3vvnYBfFVftm1BjSscCga7KGp9 dpsHvYhssPILMPCWB2fnrvqrEfA4CNclNg== X-Received: by 2002:a05:6358:3a1b:b0:172:c06c:fce3 with SMTP id g27-20020a0563583a1b00b00172c06cfce3mr5190091rwe.58.1703727759326; Wed, 27 Dec 2023 17:42:39 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id g24-20020aa78758000000b006d49ed3effasm7335440pfo.63.2023.12.27.17.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 17:42:39 -0800 (PST) From: Samuel Holland To: linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-riscv@lists.infradead.org, Christoph Hellwig Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-arch@vger.kernel.org, Samuel Holland Subject: [PATCH v2 13/14] selftests/fpu: Move FP code to a separate translation unit Date: Wed, 27 Dec 2023 17:42:03 -0800 Message-ID: <20231228014220.3562640-14-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231228014220.3562640-1-samuel.holland@sifive.com> References: <20231228014220.3562640-1-samuel.holland@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786488504458198268 X-GMAIL-MSGID: 1786488504458198268 This ensures no compiler-generated floating-point code can appear outside kernel_fpu_{begin,end}() sections, and some architectures enforce this separation. Signed-off-by: Samuel Holland Reviewed-by: Christoph Hellwig --- Changes in v2: - Declare test_fpu() in a header lib/Makefile | 3 ++- lib/test_fpu.h | 8 +++++++ lib/{test_fpu.c => test_fpu_glue.c} | 32 +------------------------ lib/test_fpu_impl.c | 37 +++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 32 deletions(-) create mode 100644 lib/test_fpu.h rename lib/{test_fpu.c => test_fpu_glue.c} (71%) create mode 100644 lib/test_fpu_impl.c diff --git a/lib/Makefile b/lib/Makefile index 6b09731d8e61..e7cbd54944a2 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -132,7 +132,8 @@ FPU_CFLAGS += $(call cc-option,-msse -mpreferred-stack-boundary=3,-mpreferred-st endif obj-$(CONFIG_TEST_FPU) += test_fpu.o -CFLAGS_test_fpu.o += $(FPU_CFLAGS) +test_fpu-y := test_fpu_glue.o test_fpu_impl.o +CFLAGS_test_fpu_impl.o += $(FPU_CFLAGS) obj-$(CONFIG_TEST_LIVEPATCH) += livepatch/ diff --git a/lib/test_fpu.h b/lib/test_fpu.h new file mode 100644 index 000000000000..4459807084bc --- /dev/null +++ b/lib/test_fpu.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _LIB_TEST_FPU_H +#define _LIB_TEST_FPU_H + +int test_fpu(void); + +#endif diff --git a/lib/test_fpu.c b/lib/test_fpu_glue.c similarity index 71% rename from lib/test_fpu.c rename to lib/test_fpu_glue.c index e82db19fed84..85963d7be826 100644 --- a/lib/test_fpu.c +++ b/lib/test_fpu_glue.c @@ -19,37 +19,7 @@ #include #include -static int test_fpu(void) -{ - /* - * This sequence of operations tests that rounding mode is - * to nearest and that denormal numbers are supported. - * Volatile variables are used to avoid compiler optimizing - * the calculations away. - */ - volatile double a, b, c, d, e, f, g; - - a = 4.0; - b = 1e-15; - c = 1e-310; - - /* Sets precision flag */ - d = a + b; - - /* Result depends on rounding mode */ - e = a + b / 2; - - /* Denormal and very large values */ - f = b / c; - - /* Depends on denormal support */ - g = a + c * f; - - if (d > a && e > a && g > a) - return 0; - else - return -EINVAL; -} +#include "test_fpu.h" static int test_fpu_get(void *data, u64 *val) { diff --git a/lib/test_fpu_impl.c b/lib/test_fpu_impl.c new file mode 100644 index 000000000000..777894dbbe86 --- /dev/null +++ b/lib/test_fpu_impl.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include "test_fpu.h" + +int test_fpu(void) +{ + /* + * This sequence of operations tests that rounding mode is + * to nearest and that denormal numbers are supported. + * Volatile variables are used to avoid compiler optimizing + * the calculations away. + */ + volatile double a, b, c, d, e, f, g; + + a = 4.0; + b = 1e-15; + c = 1e-310; + + /* Sets precision flag */ + d = a + b; + + /* Result depends on rounding mode */ + e = a + b / 2; + + /* Denormal and very large values */ + f = b / c; + + /* Depends on denormal support */ + g = a + c * f; + + if (d > a && e > a && g > a) + return 0; + else + return -EINVAL; +}