From patchwork Wed Mar 27 20:00:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13607464 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 ED7EDC47DD9 for ; Wed, 27 Mar 2024 21:18:31 +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=X4QJFV0ozAM/DD3C2RE4MOJ85LaspLJiWsERnNdyEu0=; b=0khWd0CQwIGd06 42WjSXFFpCg2CMJr4fN6XU0QVPS5AY7p1sr1x/eM24CUFHLO1VbQMRmCTE/nbsQpMDAX+rie6/qFu I6sbuhY8AtopixN3HgE9N+RIFgyJbzJFHKuF2nfF0G5swDBq/4TRmquwNondmxf+Tg84vpCnQV5TW rzx/pcVwcnG4NHHsbqo1H2XFkHyqiOnjwA4+Llu7oZBMrK8hB96GDvMdmtwrGA36nhaoWhoOgervK 3sTlcEazO2eDY5e/pEubv88vJpUHV+Wu9TQ3FC8xmdllf2BqzdtELbBVuQjE8za69E3/Zejj450RV 3nxfTQEGdj2LrXmMV1Yw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpafH-0000000BBEu-0gok; Wed, 27 Mar 2024 21:18:31 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpZTZ-0000000AuBl-2Z1r for linux-arm-kernel@bombadil.infradead.org; Wed, 27 Mar 2024 20:02:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=WUVdv0rxxPa8lHoyIaYtKDRoPzXAvzEPK1q3j7PbRrc=; b=fBc6aU5/SbgERnzpSK11zxPZnS 3rmYTBgq0NrXeooDO/LjsOIo0xeTcfPm6rXFMC+NRg/NLlf3U7HpiXVOZ7ZuXI+VcXDcDUEU+SRq9 mFN4zMzIG7c8a2lOhfCLBTXwuotHACwKkhgBLxhyFYCBXMk/MWD5X1mUoqAu8yh5WjbQYPVkMchJF lHeVywbbJ6ltE7zbTFxEgKfdO8yJ1bCe/qSkmd6qTnOsKL69unBlXP+WBfMlLYcFUvgow7cemW8D3 af2F2i5gZJxmSdaKARWch4VMad6B1QACWhIuc8Tf8iFBR02NR//bPJiPRkkdtN1F4EV3GLJ05VGn6 2dwaWMJQ==; Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpZTV-00000000Wt0-3wyn for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2024 20:02:20 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1e0f3052145so2330765ad.2 for ; Wed, 27 Mar 2024 13:02:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711569736; x=1712174536; 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=WUVdv0rxxPa8lHoyIaYtKDRoPzXAvzEPK1q3j7PbRrc=; b=NmuFCOjS7HV6MI5lwJDAeIFXCbldxwTAH9UI9d22wz22em8lOkT6H2gBv8DCFvvRYA p3Ug/MiMV9K0QiotO4XkdqEdeiJJhvKIBjM2UxcFzISmrPk0OsvKzNq2/J7OsSCpmNey iprL5u0hgJo/T/Kz7JBh9m6hWVqnM0v/tFMi0IVli/DkRzUecGooLnGekK12CXPtjEyd RUvyotExY6Hip20+cjPrjTNEGafcRhSUcQPxPjTAzFrOusiNMcDZDngqertRIpYf68JK ZZcUT7213NZadtj8sZKip7tKvcVWrZ7/OhuyCLynv2HNtq+ywwEWS+3VSan61GhWI1Y3 td4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711569736; x=1712174536; 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=WUVdv0rxxPa8lHoyIaYtKDRoPzXAvzEPK1q3j7PbRrc=; b=rSi+MRCgrCgt6ubxOWorDH26QcXNWOHha7QYdRJWVWiOOdX42QRg6kAuoy2u6QIIVf tff2OmGqAYeaCKkV9C6j1wfEd+LyOtnzVxzr0nwDVSHaz/PJRpsiL+nt949v8/Lkfu73 NqOjRTJvn9s9VfjkZzZPv4cLYlmZ0J/3WMZBrNIOfgylqwwwRNQODsMMLnN/YfF5nv5O 7SvcD8K2mDrC11tvgLhfQqIrriiZ7ZwAb0Tcn9NYRu4MWUwiVbMbaRJT+kywYLeFShic ystSeQzB5hMZJUUVF95HL25aOpYMykkQpQZt5qrQipcAmAJMkCBnxzXDltldztVrkAzd Ctrw== X-Forwarded-Encrypted: i=1; AJvYcCV0RucJ5unve2/3FkfcMB73trSymNG1gWM9YgRpjxhculyjp1cYJmCSriKRrCvEzl4mkOz+/q279Av1xjxhBhBYNVNCGc8T3zUKVc7fvRZddprxDSk= X-Gm-Message-State: AOJu0YxXIp4w1DJyz0gUo3YQcnMYBAPYbUgB8G83yE3oErkTZtP7Y5I6 HDLJii3k/uPLW5TMb5sK+gd/4ItEfnfrZbzu3OTXsJkwiDfrnt/YrD98bTCxOpQ= X-Google-Smtp-Source: AGHT+IElWB3obfH3WLoSJnhNdDLs9puYhG8ITpGoTToOUpNvi6XoJmk6eGirKGJFaRPnDc33GdSn9w== X-Received: by 2002:a17:902:b28c:b0:1e0:e85b:2d30 with SMTP id u12-20020a170902b28c00b001e0e85b2d30mr669199plr.42.1711569736542; Wed, 27 Mar 2024 13:02:16 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id u4-20020a170902e5c400b001dd0d0d26a4sm9446459plf.147.2024.03.27.13.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 13:02:16 -0700 (PDT) From: Samuel Holland To: Andrew Morton , linux-arm-kernel@lists.infradead.org, x86@kernel.org Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, Christoph Hellwig , loongarch@lists.linux.dev, amd-gfx@lists.freedesktop.org, Samuel Holland Subject: [PATCH v3 13/14] selftests/fpu: Move FP code to a separate translation unit Date: Wed, 27 Mar 2024 13:00:44 -0700 Message-ID: <20240327200157.1097089-14-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240327200157.1097089-1-samuel.holland@sifive.com> References: <20240327200157.1097089-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-20240327_200218_206535_4E2A23BF X-CRM114-Status: GOOD ( 20.55 ) 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. Reviewed-by: Christoph Hellwig Signed-off-by: Samuel Holland --- (no changes since v2) 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 ffc6b2341b45..fcb35bf50979 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -133,7 +133,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) # Some KUnit files (hooks.o) need to be built-in even when KUnit is a module, # so we can't just use obj-$(CONFIG_KUNIT). 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; +}