From 15a88f985c84f293e815cecfb7e3db940677073a Mon Sep 17 00:00:00 2001 From: Artemiy Volkov Date: Thu, 1 Aug 2024 09:15:30 +0200 Subject: [PATCH] RISC-V: Introduce the -mlong-double-{64,128} option Similarly to some other targets, this patch adds the ability to change the size of long double. This is to support the ABI deviation permitting long double to be 64-bit wide. Add a testcase checking that, whenever -mlong-double-64 is given, 64-bit double-precision instructions are used instead of calls to libgcc's 128-bit softfloat functions. FIXME: This patch is incomplete and unsafe until a mechanism is added that would propagate this option to the assembler and linker to ensure that 64-bit long double and 128-bit long double code can never be linked together. Signed-off-by: Artemiy Volkov --- gcc/config/riscv/riscv.h | 2 +- gcc/config/riscv/riscv.opt | 8 ++++++++ .../gcc.target/riscv/arcv-long-double-64.c | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/riscv/arcv-long-double-64.c diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index 7797e67317a6..c7ae6e4da791 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -190,7 +190,7 @@ ASM_MISA_SPEC #define FLOAT_TYPE_SIZE 32 #define DOUBLE_TYPE_SIZE 64 -#define LONG_DOUBLE_TYPE_SIZE 128 +#define LONG_DOUBLE_TYPE_SIZE (TARGET_LONG_DOUBLE_64 ? 64 : 128) /* Allocation boundary (in *bits*) for storing arguments in argument list. */ #define PARM_BOUNDARY BITS_PER_WORD diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index ec792d382a51..4a8f8f77cdd9 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -637,3 +637,11 @@ Enum(arcv_mpy_option) String(10c) Value(ARCV_MPY_OPTION_10C) -param=arcv-mpy-option= Target RejectNegative Joined Enum(arcv_mpy_option) Var(arcv_mpy_option) Init(ARCV_MPY_OPTION_2C) The type of MPY unit used by the RMX-100 core (to be used in combination with -mtune=rmx100) (default: 2c). + +mlong-double-64 +Target RejectNegative Negative(mlong-double-128) Mask(LONG_DOUBLE_64) +Use 64-bit long double. + +mlong-double-128 +Target RejectNegative Negative(mlong-double-64) InverseMask(LONG_DOUBLE_64) +Use 128-bit long double. diff --git a/gcc/testsuite/gcc.target/riscv/arcv-long-double-64.c b/gcc/testsuite/gcc.target/riscv/arcv-long-double-64.c new file mode 100644 index 000000000000..d531d3f5756b --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/arcv-long-double-64.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target rv32 } */ +/* { dg-options "-march=rv32gc -mabi=ilp32d -mlong-double-64" } */ + +int __attribute__((noinline)) +g (long double ld) +{ + return (int)ld; +} + +int +f (int x) +{ + return (long double) 3.141592; +} + +/* { dg-final { scan-assembler-times "__fixtfsi" 0 } } */