From: Saurabh Jha <[email protected]>
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.
(__NO_BINARY80__): Define this so that __ENABLE_BINARY80__ is
set 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 <[email protected]>
co-authored-by: Martin Vejbora <[email protected]>
---
gcc/config/aarch64/aarch64-abi-ms.h | 8 ++++
gcc/config/aarch64/aarch64.cc | 5 ++-
gcc/config/aarch64/aarch64.h | 5 +++
.../aarch64/mingw/long_double_size.c | 23 +++++++++++
.../gcc.target/aarch64/mingw/mingw.exp | 41 +++++++++++++++++++
5 files changed, 81 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.target/aarch64/mingw/long_double_size.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/mingw/mingw.exp
diff --git a/gcc/config/aarch64/aarch64-abi-ms.h b/gcc/config/aarch64/aarch64-abi-ms.h
index 6eefe2188b62..2317fee7fad9 100644
--- a/gcc/config/aarch64/aarch64-abi-ms.h
+++ b/gcc/config/aarch64/aarch64-abi-ms.h
@@ -43,4 +43,12 @@ 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
+
+#define __NO_BINARY80__
+
#endif /* GCC_AARCH64_ABI_MS_H. */
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 89097e237728..a0735504dcca 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -29763,6 +29763,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));
@@ -29853,7 +29856,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 0e596b597449..cb220c82c4eb 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 000000000000..323bd971d2a9
--- /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 000000000000..9986e0421af4
--- /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
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Exit immediately if this isn't an AArch64-Mingw target.
+if {![istarget aarch64-w64-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