Skip to content

Commit 9613736

Browse files
SiFiveHollandakpm00
authored andcommitted
selftests/fpu: move FP code to a separate translation unit
This ensures no compiler-generated floating-point code can appear outside kernel_fpu_{begin,end}() sections, and some architectures enforce this separation. Link: https://lkml.kernel.org/r/20240329072441.591471-15-samuel.holland@sifive.com Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Acked-by: Christian König <christian.koenig@amd.com> Cc: Alex Deucher <alexander.deucher@amd.com> Cc: Borislav Petkov (AMD) <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Masahiro Yamada <masahiroy@kernel.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nicolas Schier <nicolas@fjasle.eu> Cc: Palmer Dabbelt <palmer@rivosinc.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: WANG Xuerui <git@xen0n.name> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent a28e4b6 commit 9613736

File tree

4 files changed

+48
-32
lines changed

4 files changed

+48
-32
lines changed

lib/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ FPU_CFLAGS += $(call cc-option,-msse -mpreferred-stack-boundary=3,-mpreferred-st
133133
endif
134134

135135
obj-$(CONFIG_TEST_FPU) += test_fpu.o
136-
CFLAGS_test_fpu.o += $(FPU_CFLAGS)
136+
test_fpu-y := test_fpu_glue.o test_fpu_impl.o
137+
CFLAGS_test_fpu_impl.o += $(FPU_CFLAGS)
137138

138139
# Some KUnit files (hooks.o) need to be built-in even when KUnit is a module,
139140
# so we can't just use obj-$(CONFIG_KUNIT).

lib/test_fpu.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* SPDX-License-Identifier: GPL-2.0+ */
2+
3+
#ifndef _LIB_TEST_FPU_H
4+
#define _LIB_TEST_FPU_H
5+
6+
int test_fpu(void);
7+
8+
#endif

lib/test_fpu.c renamed to lib/test_fpu_glue.c

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,7 @@
1919
#include <linux/debugfs.h>
2020
#include <asm/fpu/api.h>
2121

22-
static int test_fpu(void)
23-
{
24-
/*
25-
* This sequence of operations tests that rounding mode is
26-
* to nearest and that denormal numbers are supported.
27-
* Volatile variables are used to avoid compiler optimizing
28-
* the calculations away.
29-
*/
30-
volatile double a, b, c, d, e, f, g;
31-
32-
a = 4.0;
33-
b = 1e-15;
34-
c = 1e-310;
35-
36-
/* Sets precision flag */
37-
d = a + b;
38-
39-
/* Result depends on rounding mode */
40-
e = a + b / 2;
41-
42-
/* Denormal and very large values */
43-
f = b / c;
44-
45-
/* Depends on denormal support */
46-
g = a + c * f;
47-
48-
if (d > a && e > a && g > a)
49-
return 0;
50-
else
51-
return -EINVAL;
52-
}
22+
#include "test_fpu.h"
5323

5424
static int test_fpu_get(void *data, u64 *val)
5525
{

lib/test_fpu_impl.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
3+
#include <linux/errno.h>
4+
5+
#include "test_fpu.h"
6+
7+
int test_fpu(void)
8+
{
9+
/*
10+
* This sequence of operations tests that rounding mode is
11+
* to nearest and that denormal numbers are supported.
12+
* Volatile variables are used to avoid compiler optimizing
13+
* the calculations away.
14+
*/
15+
volatile double a, b, c, d, e, f, g;
16+
17+
a = 4.0;
18+
b = 1e-15;
19+
c = 1e-310;
20+
21+
/* Sets precision flag */
22+
d = a + b;
23+
24+
/* Result depends on rounding mode */
25+
e = a + b / 2;
26+
27+
/* Denormal and very large values */
28+
f = b / c;
29+
30+
/* Depends on denormal support */
31+
g = a + c * f;
32+
33+
if (d > a && e > a && g > a)
34+
return 0;
35+
else
36+
return -EINVAL;
37+
}

0 commit comments

Comments
 (0)