From patchwork Fri Dec 8 05:54:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13484865 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 71AF8C4167B for ; Fri, 8 Dec 2023 05:56:14 +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=1dRKoi4mW+btqaBwC5JFdND2xh6NikqtWR5R2NF4r4M=; b=4hSP0wut9jdeXz g7fgG2NFggJYDFwzuBTGpfyzPID+k771xxQ8ywy0X42gT98+Z0WdF4Ob48kPo6HyzBDBrL69sanpa +c5C4clod4apuW56KhDhyIi3e65Cqy5j0UfHA1wWly7dDfNsSM2n3tW+Dd+vpGWZBUfyhV4eM3Cbl r9KeiRAq+JKTGfsAaWcFtLuEQhyAalhUwmRhu8kB+h1kv405mrZq/pFtyCoO6K4qnOeiXS0OwBpAg BdatMxn7H1i1CcCShyX58XwNCnkAojrTItpC1UJKsI0dWjtRQ3ZISEaWxLRBKjTWlJ/oKCHvdz4/L 8p9R1ia4E1ooJx32zhIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBTpx-00Eo5I-2k; Fri, 08 Dec 2023 05:55:45 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rBTpV-00EnbR-0K for linux-arm-kernel@lists.infradead.org; Fri, 08 Dec 2023 05:55:22 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1d03bcf27e9so14678625ad.0 for ; Thu, 07 Dec 2023 21:55:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1702014916; x=1702619716; 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=jlkhIfYEZ3lvxXxXZeJnWgi8rztsMBcyR5bRnlna3ss=; b=GqtFeIFWpOmY4GYXQcv1dhgPyXwHpXOcQR++aVxXQWmk7Qbr7mDbVuZgL7ff+1iy5p CfppDYOSWJOZNBZ8XjzPn64Kl9bLQX0CNgm80QmRFEPo794ZOtTkOZSswAzbf8gQEX7E BIJCmsNfeokzHftLKcl7Tp3+6JI34VwZD1ibY5xMFzFVz8o+PeGnjQm+yvmsyr2WulEc twfeK5H6twFwzljDqpINBJJMGMP2IBt88MdqBOZNJawzUj6OmqN1fR+wP1K9Ge2x6wNj zNA+STp1Hiwh1OT4Th9Roabq3mwdD+qfx0yR14c4VjGiPVBDwqTyQpEIV3T8nyx2g9d6 oBwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702014916; x=1702619716; 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=jlkhIfYEZ3lvxXxXZeJnWgi8rztsMBcyR5bRnlna3ss=; b=FiVV32wgRwyhIy1zpGixFVhQzWp/XTaIbUnqLbW7jAjMPbWsqEtEaoebnF/nbkzQVO t9Qx2O4+6wxCjZ034BP70VgdOz5aE2CyUrVhInpFHjgAAXCn639GDpgjzX67u75VuYdT 7tz3XryfqcL2/p+wnad1vDYbY2FVf1G5fQrm+j1MxVj13lmSnPa1JDVKYUCTy5F1WvnD si2zQaUEMNTt2WdoQVQozKvlvGTZWXWObqRAcvT/o8gVkqHGMTvX8IGZmcfxKDOxhpxy ArK8WW4BpRPJt0gQ7BWhnDD6+UJ2iDMGG5uRXdWi37qcjVBElfJuz3uYKNkakykP2Fdj pkGg== X-Gm-Message-State: AOJu0Yx6OLawXeyCwr+rFoqHh0xBjUHcAHZNw+/eRNj0FlpJqENKDjPH 9v6GKWN6TkzxxRAvizX6kopHoJGq6ETe1CWbfqhNrAT5AD2Zp46FVgLOfI5E2TPixk9z0PRlw45 7VNXoAsEpzIHljAMH12BFb33oKInlgwIVxYoo2MDf/itf07/3+ZiC7e7gU78WkxXdfY7wsJ4BiO sCxL2Hz/6K0wm7HF0uNHDEKfbFSw== X-Google-Smtp-Source: AGHT+IFq3S7FmJealx+s/zAc0NWuz2K3VM/cjjAkpGlz2K3tHlLviwkN/+BPcQyJZRioERW0JqTrBw== X-Received: by 2002:a17:902:b60f:b0:1d0:c7e0:c82c with SMTP id b15-20020a170902b60f00b001d0c7e0c82cmr2930083pls.8.1702014916347; Thu, 07 Dec 2023 21:55:16 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id s22-20020a170902989600b001ce5b859a59sm786250plp.305.2023.12.07.21.55.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 21:55:16 -0800 (PST) From: Samuel Holland To: linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-riscv@lists.infradead.org, Christoph Hellwig Cc: linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-arch@vger.kernel.org, Samuel Holland Subject: [RFC PATCH 11/12] selftests/fpu: Move FP code to a separate translation unit Date: Thu, 7 Dec 2023 21:54:41 -0800 Message-ID: <20231208055501.2916202-12-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231208055501.2916202-1-samuel.holland@sifive.com> References: <20231208055501.2916202-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-20231207_215517_181373_C9C85D19 X-CRM114-Status: GOOD ( 17.90 ) 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 --- lib/Makefile | 3 ++- lib/{test_fpu.c => test_fpu_glue.c} | 32 +------------------------- lib/test_fpu_impl.c | 35 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 32 deletions(-) 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.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..2761b51117b0 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; -} +int test_fpu(void); 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..2ff01980bc22 --- /dev/null +++ b/lib/test_fpu_impl.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +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; +}