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: 13505557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 42254C46CD2 for ; Thu, 28 Dec 2023 01:44:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lUJK3rggX9jzemYkV+XlMA2FtDQhzrnopaplzaRXddg=; b=3WRX+eEZGrtQMs sBw0gRpvK/nAPCB99dM+K2bllj8d1nUZCV9J8Ptpw2E4Jr8pqH+rOL8nYPDeYKzClF2o94H+Iimtv qpR6jXJ28LvqdXkvjvcFaL4jG6QaJj8URNsj6nk4eXd5RmGXIOB5AwfZSNxACKvdBfikStDnRaktp soesQRg6P02dt1CYDwGaMTFeTr5TgKRfnqy1DLVtRjSIrQZJU6XURDtSEUWlPb1F17iz2oB/EPrRF Dn7zvTINetlj/PN3w0aCotHp5MHeBByfdRPtCvjk98iKM1h6NQ3GT6wZL794aWfpYHJSxfADAP2Uz BZjKtiCpEImM4BDAG+Cw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rIfRS-00Ft3E-26; Thu, 28 Dec 2023 01:44:10 +0000 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rIfQ1-00Frvp-0y for linux-arm-kernel@lists.infradead.org; Thu, 28 Dec 2023 01:42:44 +0000 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-594c7241fa9so894490eaf.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=lists.infradead.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=H66MLoC+5OApqRJxufPGLfaVx6v0l4D4mf28XHrnDm00rY5DjjRV1DcifWZJ1ZUmGX AE3TGSzUzElAVUFGVmcjdJ3bbk0T+XwGPbY39kv43Fhg4rERuYPtr1xilumStCEfxrBU if6h3+R/645DgHXhzcfGT1y/oGLIqQmGMEYiXZVwg1hsM5sp2NLpudu5+gfOhC717VHC 9NO/ivePkqVPYFXxAX86wK+JOvhHrOY3wAEnDf2R3BuRFTomqg92y0Ip0htbqJZh5/Gj mEh0X+wF6fgA2Ry8sPCiqHGAg6LkgD77rGcnY89u98TB9OMiGcTla/YR0U6/q4RlTgjr 3wlQ== 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=aXCu6MgoMCy4BmQrv2vHawzoqwF8R8ll3+0ra3dL7SraoWVRlycnunHlTSwi7ST0QC 9YGS4DgqwQapbPDY9CVelzREeIyxtchpISJRbXS/GSUB9aSTpJCKLz4umBZMiKU0qRVt FCeHwjs7GZ/Nv5WyE4GwO+IGJnwdaevqh9TyABm26ho5eEf1t7f+3KGXldGjxoVRVRiS 5EANXlidW9NGWW18yD/aM6gEoAP3zsqgxbHZUcQe4sfEhpglo4n+wemEMqX4FvKz/0Gp C0LYfC7cxLKRsUOOAPJYUI80ugPU8feLzL9EOm9dADYc0xWea9BHCkFnGy0WtZ6FTAhA MsGw== X-Gm-Message-State: AOJu0YxEXT6KN4KpAFH8KnwulU/fgHGA7S34GscCDERTARWhpvPf65Xv fgLHesAxmea0y7t6+AgEOS45WICm/TpvhHUJc9z1jNvk659wTsrFR2oM9Kj8p37SWNrO5BHAVsS rzHx/i6FRoZAh6vGg1TjmTe4mnAyVKBTi5i0r73+f6Dc1RXpmEmPZDwZG7NT+CNmH0igPwPxY5O I2BiPUOQeATXJpWUt3XDINUh8DXH0nsRVrgg== X-Google-Smtp-Source: AGHT+IGvfqTB3x7wwPMxp1qNsfQvBXkwAH7kyz4he4Bu1Z+L46cvb1psldcQ6vV6De8969ozhHXwqQ== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231227_174241_367218_C88E6CC2 X-CRM114-Status: GOOD ( 18.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; +}