Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3702430rdb; Wed, 27 Dec 2023 17:45:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7wDmM6hspj7pvZ2ClhgBt/EnCWPRfPATEJIJuZxZ6GIQesITd8WzEX/6PQbYiQiRb3utQ X-Received: by 2002:a05:6214:4112:b0:67f:428f:350 with SMTP id kc18-20020a056214411200b0067f428f0350mr16630149qvb.91.1703727951422; Wed, 27 Dec 2023 17:45:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703727951; cv=none; d=google.com; s=arc-20160816; b=wao/2/6KkviJkttHhc852J4zJLp2aJ0NhzA5MAaEpTF4qSiyH5i59cLPdr1j9cUmOQ U35vI2ix2MwGrJ4wlH8fGMN4PtStf/1uPJe/555oDXKr2kG/NUZJg0exGK3yq0qdgUy5 jPy9y90HmIRKOHflHerDOdkFSvQmqNZd5Y6prNLbea4CwR+L+QJdSjpIYjqf+TJZ3No/ qFoToZCOnpHUPahGPpni95MM2mKolALHYs+BzY9FOvd4rkwSgHukItFpDGdJXvvZzBj7 GFZGhNy+Fd8wGhkUNo5u/8zUgOy20typXksUMgRHoXfUmX52e/pgbSchCiuGA8dwpZ1P mxsA== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12380-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bs41-20020a05620a472900b0077f6ff697c6si16721151qkb.164.2023.12.27.17.45.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 17:45:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12380-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12380-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1F4921C2139D for ; Thu, 28 Dec 2023 01:45:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A34CDDDCE; Thu, 28 Dec 2023 01:42:42 +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 Content-Transfer-Encoding: 8bit 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 --- 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; +} -- 2.42.0