Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp915307lqh; Fri, 29 Mar 2024 00:28:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWg8p8e50wE3bN3ZgtufM2nRBdhw2gAxzO8NE173Nk0otX97OMgdolHanhR7KUHJdz37q+3T4B4FOYMvARyx5ZcvypgtKE9C6Yftgwogg== X-Google-Smtp-Source: AGHT+IHFagkJNaw5Qwzz9DCzLZ4oZGl/K1T7FLnq2ePK8kDD+jo/QI1C4OmOlW2t4423sBui2OfU X-Received: by 2002:a0d:dfc7:0:b0:614:2f22:8695 with SMTP id i190-20020a0ddfc7000000b006142f228695mr1678029ywe.1.1711697283642; Fri, 29 Mar 2024 00:28:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711697283; cv=pass; d=google.com; s=arc-20160816; b=VezkLf35ltYqWfCSmA7eq2+9NjbiEEDBMjeXdnq9gaIbEWcbl0vSjz4mGTyu17tL/N sqUpyrfKPN7f1QOh9QinFu4VYmmi5r/+97gJ8RByzhLFX6f5JMBzb4iythwSVp+8b/XG nCsl8SOF9UN+7Sz0rborc0PedN3oUtrq73A5Z2uxMTxaMf1CdT1GEPUtEktWmE4kkvXX dxarO25xh9t/xT7v8Ebe24PnY1WI3yKB6LvvmEezuD/uri0yxSJCuoLzffqj/FILJZGO 8rk2A78ZV/HTJDqPi2FfL8cO9lJxAqk4wOtaLh+nTNSUc9vuT79fDgwKWjA+WkdfhP1l jKHg== 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=IERaZRfF/9oogZdizMupzfKIm+UO6QVYkIeFwIsamZU=; fh=bO5wkMWVyAmlcK/jrB+5GsJP0U535A85Nq3xBEBHFwY=; b=wqXa4WImyEou1Cx4M/GGOaAucRRuGxSGxvkOJRcQAUCbkfvEl5UA9DrE6H+UY4fYz9 sqLtKLsP0v1VT80EjxF1Krc+YMRS0iya8j11tQf3a+x/v9osXvGPxRRumG8td/UbCcIZ RzwBkFpC5Jd2TXZqfXlbT6HvmlQs9JkQl5pUpj4uErerWLpgYZw7WKQwlSYtl5F1lQdo 1rz59g6tr0RdLrkZ5Srl1cONv3GksjeuXgjcTZp5UPpR9lmi3LgJe09KsvpdQqFFEGiN mXQEY5zy3WlOSw5Xj/AGbW89JBC/IaevH4t3PLoPPHVoV79VqCT+1HSq7tfGTErTrKHL /qvg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=UWIwmaot; 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-124241-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124241-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id y6-20020a05622a164600b004315801deeesi3044212qtj.163.2024.03.29.00.28.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 00:28:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124241-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=UWIwmaot; 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-124241-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124241-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 4F3581C2131E for ; Fri, 29 Mar 2024 07:28:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F030657B5; Fri, 29 Mar 2024 07:25:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="UWIwmaot" Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 107335D8FD for ; Fri, 29 Mar 2024 07:25:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711697108; cv=none; b=epi1PdHL5mby+NATWRSyui1s15EVQubRIKijB7i99tWkFIOaJPQwvh7lv8icptm8NVfOQ3xMROsYNwjGPk67RjFQDETMOFZPDd1oIVGZpE8cxbzlKEnf1SqymPGR27KQ294EaRAz31DHF+04U+pt+1hv3ZY1Fn7imjHohJPwI+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711697108; c=relaxed/simple; bh=sDSM8SzyTSBzvwgCVM/QtpZk9UVDm9MyzCcLceVlwvo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WBUpYlvYEuJ/r0zNXdOu2elQghAyqw2Juno+I2XpvDs7VPJoeJa7QQdxX4jojS3P8oluOqEWbw+hZX8hZfzo4N+USs85iiTGVIj84hRl1myuT3W+wLNDKpFlTpzCkSO7Ge2YiDB+YdOczdkYO4oIUyVIbdJIFAtiKzOJtPuwWA4= 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=UWIwmaot; arc=none smtp.client-ip=209.85.216.46 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-pj1-f46.google.com with SMTP id 98e67ed59e1d1-29fb12a22afso1334851a91.3 for ; Fri, 29 Mar 2024 00:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711697106; x=1712301906; 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=IERaZRfF/9oogZdizMupzfKIm+UO6QVYkIeFwIsamZU=; b=UWIwmaot0nXODV6lmi/3x88Uajdml4SyA9rrPah4N4ilELSLttuLO7mbY4ueV2UfOM 2LlJrMCAtRE/ZDCH7Ae58GYDpez9Z2ZcuOHtupvDIUKJwvy/HNFiDI4HV3Lq39Adw4fK H+FkMOdVAnuctEgzQ8mTvAIrkyzVFAnZ9nX+e6pHswOK1DGS41B/7zYEgiucoXafsWsV EgA00nVMlqROx1eWCPQidkeGqlxbwB0u0iOjeMuJpYoVXm0bUIGOGvNcWUaIXEs3yaOn pwcmUC6Nkt5CsgVf+We/CMYTAb4UjNdITvnpLnYMPFFZ5mexQPiJsSIUPP8gYzILvfkR Z8pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711697106; x=1712301906; 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=IERaZRfF/9oogZdizMupzfKIm+UO6QVYkIeFwIsamZU=; b=Xh29XcVpHiTe0iqNLh4I6PGcMj1QVsqyL8VNlOcO4HA5NPxu19CGvntInD5sl6sTH/ XiYdyEgh8Dle1vm/8boIAMYQfp/ZSGx7u1bc0wqwLkBdCu0HqdlGM8rMGGsX1kGmxtPM THuPbTbw5pc67etnOfC6V0CrFhgsYkYQHQ6yTlmexHr+CvsBmAUovqDJHJjxXjT0CYv5 yC6lDNNESNszjKT6D2mY36YHIBGjrYOq6fW4KDw3IbxP2wyijBLIaNA2e2FCDU4RZTqL j1JSMZln+GNbusTCGqLqbsg2kwpYM43sSw+W/d9wm2/Qpv4wccdoO+/A8e/XtU0tFnF4 SadQ== X-Gm-Message-State: AOJu0YzySe5M6+qYOcNpdLkfwyAjKCUi0sF1GjH0iAvECaRRSget/JJg Bxew7wwJq4SalalLw+QM9eWg5nx5Xpi1UTqFRNeQgTR0gi0/9Xmh+KGWjeeP2Qw= X-Received: by 2002:a17:90a:3ee6:b0:2a0:3a16:7489 with SMTP id k93-20020a17090a3ee600b002a03a167489mr1460482pjc.44.1711697106489; Fri, 29 Mar 2024 00:25:06 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id b8-20020a17090a010800b0029ddac03effsm4971798pjb.11.2024.03.29.00.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 00:25:06 -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 v4 14/15] selftests/fpu: Move FP code to a separate translation unit Date: Fri, 29 Mar 2024 00:18:29 -0700 Message-ID: <20240329072441.591471-15-samuel.holland@sifive.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240329072441.591471-1-samuel.holland@sifive.com> References: <20240329072441.591471-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.44.0