Received: by 2002:a05:7208:3003:b0:81:def:69cd with SMTP id f3csp828738rba; Wed, 27 Mar 2024 13:04:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVGkBgxD4Cyfn0F9lH+ees/7MI2O67aHsNvA83i6LsHueLGNvauDUjruAsKubQ8A9Uh9dts7paKoWDW096BOciSRi4xBWVddoTyMDBYtQ== X-Google-Smtp-Source: AGHT+IH9E2OKj1KdHYP9iLMQ/xa8QHN2i8eP8vkphUKNZy3jV4DKRaEqZuVoUh3DW2OAFvCosBwz X-Received: by 2002:a05:620a:3b90:b0:78a:6c2d:451b with SMTP id ye16-20020a05620a3b9000b0078a6c2d451bmr612912qkn.65.1711569893353; Wed, 27 Mar 2024 13:04:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711569893; cv=pass; d=google.com; s=arc-20160816; b=AUVvEhOzdGp+Zc1V0t3z2j5dhPhnUXVM3URMpow2Huh++DgGQQgTKCnRnvu67DvLjr Ej1RTHIeAI0tLioBCDQTxFFErASnb667yP9SFl36ngbYHLrOGsJLzXP7XaqEEnrktUVd uEMMf5Hfn+PJNq1tH35PsSRJ4jVGe0Mz1sAZrp5XcVGwYxtSyONo4rOlYrzS5wX1M9CN 4v6jWPM4hxIfWAptAKb9OnwANwtsd3twSKrKzzKmcN4r5XGgltBJ66PhZOlyn95ubBL7 vRoFu1e6qORifZbGBeXmkbVpyWrxhjSxNhnUOkP160AGczambv6nIsovR888SWayUCAa Migg== ARC-Message-Signature: i=2; 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=WUVdv0rxxPa8lHoyIaYtKDRoPzXAvzEPK1q3j7PbRrc=; fh=bO5wkMWVyAmlcK/jrB+5GsJP0U535A85Nq3xBEBHFwY=; b=aOt9XfVTACs3kDwjVUXNNqKcblhKunC0i+rMkWqpgC9QemuyKCzwOupz+v9H5IdUK8 JX5kcDrrQ7cSgL651aNugnySKr08kjWdViKPYcaqhbEZcrhHwbHIVRoXRuc1HosUCAoz kTINs7XeQdMgI8O6uwFLygRuO0MDGySVpI/oPlJEpWw9/WXJeoAcS/XDQcBScxcYwlrW +AkA7CkGQw7fkwzGSq8/B0JENspRrTunsiUtZQTeae7Hi3ZwKN4BGvi1u3858s1aMlaL hB7NksyKQg/oHDgg9ov8QOhdPs7nCkoL4/J1v1hf80bqCMnyGsxVhO3FpSx7E8318LnM uYCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=jOltWDy+; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-121946-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121946-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 pi21-20020a05620a379500b0078a33ccec17si10749749qkn.577.2024.03.27.13.04.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 13:04:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-121946-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=jOltWDy+; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-121946-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121946-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 E93451C333AB for ; Wed, 27 Mar 2024 20:04:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4CF21552E3; Wed, 27 Mar 2024 20:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="jOltWDy+" Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 27EC9154BE0 for ; Wed, 27 Mar 2024 20:02:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711569738; cv=none; b=CVNwHXFcb9vgbWbMX/L9iUoi48memYMtP9dfsSAJtEvS1Q6+hU4tLpwUXo4RCGhq6/gVRGw3fmTKc7T0AeI/PRAWEm8ZNJvvxqt96wSghWkXa59Q4HFsLnqq47Gok5Qh8RcXROcIphKixo82OLIB1exuXNZwg/u7caXarJf3sGk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711569738; c=relaxed/simple; bh=GLOA3AwKqg2OXJCgfGVxEWRiYujUlmeNO1fdj8ZA+Yc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jMYOyQpOXal7yxQrkYeFs7bjO2YVsrAgGcvIocKSF02/i6gcvxJy3cK0Bby4t1ztuu/ymv21qD+KLp9WqhoqnsZZGfJvkeXM/dp9Jp9GxZICQ7t3PgoNFFNWb7eaBY8+xjYO/CDVcdW9C0gH+UwW+HTbzt9Z4S2Y8ujHFu1MA08= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=jOltWDy+; arc=none smtp.client-ip=209.85.214.176 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-pl1-f176.google.com with SMTP id d9443c01a7336-1e0d82d441bso2013075ad.3 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=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=WUVdv0rxxPa8lHoyIaYtKDRoPzXAvzEPK1q3j7PbRrc=; b=jOltWDy+Thxmmty2DIUbDSmP81TByO4nFyhc8IwxuXtFEX5AgHBKZ0y4Fak6Jh+R9w PJxsYnjLOrC4nlXDe68Z9GbbFPva4GmbFuHml5AGAh9mOyieSywkVsQi0VLvF7uObAAZ x199peNXPNVyZ7EVogcZhYaTGNxz3sSVYcjcDE7Y+q7/APhrIuE/s7rRPl6edttAcBln wVYA94a6aI2gbuL3OksGWQ8JFeS3Ueki8lwytu5rXyAc/47oxxpUf5DP61Xvt0+hsIQg wOPsJMlTFDba/hDZ8/Y4GtM83EO6uHVpIo6o8nxLymgora9VlVbE4pKNJVHo1/PHTXg1 tNQA== 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=V1LlH5te4xwIpiHz6fkHeB4RirWZ67dwNAS7gcc8AK7zTLGlskSe6uWFaY6GxKkpOh gb/zIwlhLh+P2NjJTdaNCdkqf8rfGEGrh90VpDrR8HV0EQZQ1XWrH9E7Ne9EmOaUAZY7 Dp1P+lJLquHhbKKgLHxHYCwfrI629PnACLm9iQ52Kij2QEyNFMOw3CZxKAdMHJ9rbPwZ PfRY5hTZEmTgtGGF7zOGfSXLuZd2tQeeeu4I15zSvSkrEYoYxEEOIrnDMO8Zwe5HN/IT 5AglPikFlW/nEGxXG9IrszYKn0s+itD9rcbRCFbMOZVXWJa5tL2/S4JA68+33EEDy4ta lYYA== X-Gm-Message-State: AOJu0YxeRyBv0E2gWRO3lomVFY47swvW9n17iohtlYKLD5x1V/5E6OnS 4W8EpeAusxBcorTIpX2faS7S8wMbi80sOswpBlOD/V1GHIoFT2f9lCTaO0a5bP3XRtvkl0nmdZu V 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> 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. 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; +} -- 2.43.1