Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2139255rdb; Thu, 7 Dec 2023 21:56:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9MyyyA7U7WNPhlpphAV5HeW7fYeHyK3QnrX8rfUwz97mKNITnFbzhGT7a7woadPvGBvuE X-Received: by 2002:a05:6358:9214:b0:170:160f:4400 with SMTP id d20-20020a056358921400b00170160f4400mr5294445rwb.17.1702014979657; Thu, 07 Dec 2023 21:56:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702014979; cv=none; d=google.com; s=arc-20160816; b=ClbTG/QOINKW83EaDlX2hqAii2jp+p6+bgegvJh9PLBHtkf4Uad/F8/5SfncXQX8mL wQSF3+ced6e5aZbXRu5CbDLnTI0wpBCxPS35iDwKyO/yxL0RfsNBDE9Utx5QXtbdcI2v 1QbgZyKguibQfJPnAWlgFSDMOG6gfgAVoiHLrP78tSeA+96MexxxTyXugWwXeJJEqRSX X/lAL38J1LUmupbi34vchI2GcfhGaflUW7ehn4Ne4Tbjy5SGg0efa6fls0Nva0e5fXNn RmxgdhG6Rk8tUbh2uf/yLXPWyhIYt3ceDF1U/TQsV+9/8rtyXgN1DbxdKTf8wRwaCgu4 rsfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jlkhIfYEZ3lvxXxXZeJnWgi8rztsMBcyR5bRnlna3ss=; fh=GWiN7/yH5ZaeB7dNf34H6takS9oI70VVB29etA3Fg9Y=; b=BK0pxCf/gNJ/gSh+LzIO6bB4/QtPe7+8WuIzL7fdD2iHSEDSU80f5dp/J9tj/BizZH cT5gRxRhQe4vZy/6tWZfZl26/X4kkRQRsOkM+hPTxJWJ+/x6fbkC8BBS92zgIP9wgD4k xwyqtHIFDZhlCROzLemfDCeDnjCcJ3ShqTU7h7YArao8H/b97IA1Vco6+LfHLBpgcOpY UG0Zv4FRk3qyVy4E2VEEzNr2iZ6i4rb9jfiNFFczcRAKxlyx6YoirbZLYkGSoKnVFqhC mGQR7d6BEpVqCl+DgtSB0bfvyB0SfEh6iy0SMa6+Fb1GD7EsUsaNqv7RFQG8UazMNzo8 hiFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=AEao+vb1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id 4-20020a631544000000b005c201808430si961155pgv.120.2023.12.07.21.56.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 21:56:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=AEao+vb1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 55C9A8292A56; Thu, 7 Dec 2023 21:56:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232875AbjLHFzq (ORCPT + 99 others); Fri, 8 Dec 2023 00:55:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573237AbjLHFzS (ORCPT ); Fri, 8 Dec 2023 00:55:18 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 000791722 for ; Thu, 7 Dec 2023 21:55:17 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d04dba2781so14486915ad.3 for ; Thu, 07 Dec 2023 21:55:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1702014916; x=1702619716; 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=jlkhIfYEZ3lvxXxXZeJnWgi8rztsMBcyR5bRnlna3ss=; b=AEao+vb1AvlKCIZJWmSxqBAoZQ2zLBQiff9us//NXqfNiWxT5xzE6uPZhc9It8sve3 8EnnnmYC4H/51rhQd8qSg4DzVBrdvRBSQDUeodRh1Ihu73hxhKklJKAXANtJkiJq84mi WOEHhznz2WCEjTOH7IyC6Vs9FDPTxV+ll8wnMS+WZ3tDZ+nFF6f5BQhByzOHWOwjldRm V9avHASvOEafq/ltXFpavUtVMr7EQfoDO+tP9IhtEW89dF59ygk10LH4S/EJknTwjUJg MR5gsMOrcVWlE5WciXozIIqRuR6tabKbslZMqykkMx6Rx20twrpzeQmSLOVBuobZ09Nt /Deg== 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=MSBtA+wSoW02/UAMJaByTIqVysNnmd+zcDW14nGodee8fqXg7hsqnVBi23acM+RTe4 PxraPVQ9vCg3uRjD+n+6B6nFXJXBonaCPpgaQ1I1RSYwy8utKm3YQFAzA0MRY/tob/Ac s96Y41MntGAqghbNUgVMmbG3lxPXIsBlfreAKPgVxHXpeuxj76uDRUh6qINFwv0oysuo wxnOQz2MRe94bn4WHI7u5AIKEe6oVXL5rYRbuD9xAyJC7eRQDwbTDJqaEF0xuv8oxano AVI5hrK4rqb+8Q7GB8OT6Ee02+5o2WRNrWDvJ809IYQUAtaPRbUmBZcBDRUCB+jlGdK8 yA/g== X-Gm-Message-State: AOJu0Yzzbe6/zRAesaiFWaSRKrGHM6JLTIJqe8meyDxcKGPYhBpKMzM0 ZVhyT6/pXx4fO/miwiC5/5Qxnbk9GJXHH5ruXZw= 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 07 Dec 2023 21:56:12 -0800 (PST) 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; +} -- 2.42.0