From: Saurabh Jha Date: Thu, 9 Oct 2025 15:03:18 +0000 (+0000) Subject: aarch64: mingw: Make long double 64 bit X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=429c2e50d9c7e1f018bb9d7c83bc194ae6e17a3a;p=thirdparty%2Fgcc.git aarch64: mingw: Make long double 64 bit On windows targets, the size of long double is 64 bits. Therefore, unlike aarch64-**-linux-gnu, where the size of long double is 128 bits, the size of long double for aarch64-w64-mingw32 has to be 64 bits. This commit makes changes to gcc so that long double is 64 bits for aarch64-w64-mingw32. gcc/ChangeLog: * config/aarch64/aarch64-abi-ms.h (TARGET_LONG_DOUBLE_128): Set this to 0. * config/aarch64/aarch64.cc (aarch64_scalar_mode_supported_p): Make long double 64 bits. (aarch64_c_mode_for_floating_type): Return true for TFmode. * config/aarch64/aarch64.h (TARGET_LONG_DOUBLE_128): Set this to 1. gcc/testsuite/ChangeLog: * gcc.target/aarch64/mingw/mingw.exp: New test. * gcc.target/aarch64/mingw/long_double_size.c: New test. co-authored-by: Radek Barton co-authored-by: Martin Vejbora --- diff --git a/gcc/config/aarch64/aarch64-abi-ms.h b/gcc/config/aarch64/aarch64-abi-ms.h index 6eefe2188b6..55308431701 100644 --- a/gcc/config/aarch64/aarch64-abi-ms.h +++ b/gcc/config/aarch64/aarch64-abi-ms.h @@ -43,4 +43,10 @@ along with GCC; see the file COPYING3. If not see #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \ fprintf (FILE, "\t" ASM_COMMENT_START " seh_endproc\n") +/* Long double is 64 bit for Coff targets. + Reference: + https://learn.microsoft.com/en-us/cpp/c-language/type-long-double. */ +#undef TARGET_LONG_DOUBLE_128 +#define TARGET_LONG_DOUBLE_128 0 + #endif /* GCC_AARCH64_ABI_MS_H. */ diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index d8c99d8e3c2..f16c91cd44b 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -29783,6 +29783,9 @@ aarch64_scalar_mode_supported_p (scalar_mode mode) if (DECIMAL_FLOAT_MODE_P (mode)) return default_decimal_float_supported_p (); + if (mode == TFmode) + return true; + return ((mode == HFmode || mode == BFmode) ? true : default_scalar_mode_supported_p (mode)); @@ -29873,7 +29876,7 @@ aarch64_bitint_type_info (int n, struct bitint_info *info) static machine_mode aarch64_c_mode_for_floating_type (enum tree_index ti) { - if (ti == TI_LONG_DOUBLE_TYPE) + if (TARGET_LONG_DOUBLE_128 && ti == TI_LONG_DOUBLE_TYPE) return TFmode; return default_mode_for_floating_type (ti); } diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h index 0e596b59744..cb220c82c4e 100644 --- a/gcc/config/aarch64/aarch64.h +++ b/gcc/config/aarch64/aarch64.h @@ -945,6 +945,11 @@ enum reg_class /* CPU/ARCH option handling. */ #include "config/aarch64/aarch64-opts.h" +/* Long double is stored in 128 bits by default. */ +#ifndef TARGET_LONG_DOUBLE_128 +#define TARGET_LONG_DOUBLE_128 1 +#endif + /* If there is no CPU defined at configure, use generic as default. */ #ifndef TARGET_CPU_DEFAULT # define TARGET_CPU_DEFAULT AARCH64_CPU_generic_armv8_a diff --git a/gcc/testsuite/gcc.target/aarch64/mingw/long_double_size.c b/gcc/testsuite/gcc.target/aarch64/mingw/long_double_size.c new file mode 100644 index 00000000000..323bd971d2a --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/mingw/long_double_size.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O2" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +/** + * For aarch64-w64-mingw32 target, long double is 64 bits. Unlike in + * aarch64-linux-gnu, where long double is 128 bits. The tests below validate + * validate that. In aarch64-linux-gnu, the results would be the opposite. + */ + +/* +** test: +** fmov d0, 4.0e\+0 +** ret +*/ +long double +test () +{ + long double i = 4; + return i; +} + +/* { dg-final { scan-assembler-not "ldr\tq\[0-9\]+, \[x\[0-9\]+\]*" } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/mingw/mingw.exp b/gcc/testsuite/gcc.target/aarch64/mingw/mingw.exp new file mode 100644 index 00000000000..66e151e50ee --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/mingw/mingw.exp @@ -0,0 +1,41 @@ +# Copyright (C) 2025 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# GCC testsuite that uses the `dg.exp' driver. + +# Exit immediately if this isn't an AArch64-Mingw target. +if {![istarget aarch64*-*-mingw32] } then { + return +} + +# Load support procs. +load_lib gcc-dg.exp + +# If a testcase doesn't have special options, use these. +global DEFAULT_CFLAGS +if ![info exists DEFAULT_CFLAGS] then { + set DEFAULT_CFLAGS " -ansi -pedantic-errors" +} + +# Initialize `dg'. +dg-init + +# Main loop. +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \ + "" $DEFAULT_CFLAGS + +# All done. +dg-finish