]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: mingw: Make long double 64 bit
authorSaurabh Jha <saurabh.jha@arm.com>
Thu, 9 Oct 2025 15:03:18 +0000 (15:03 +0000)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Tue, 2 Dec 2025 01:19:48 +0000 (17:19 -0800)
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 <radek.barton@microsoft.com>
co-authored-by: Martin Vejbora <mvejbora@microsoft.com>

gcc/config/aarch64/aarch64-abi-ms.h
gcc/config/aarch64/aarch64.cc
gcc/config/aarch64/aarch64.h
gcc/testsuite/gcc.target/aarch64/mingw/long_double_size.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/mingw/mingw.exp [new file with mode: 0644]

index 6eefe2188b62e44dda30213b447c608f1019a0d0..55308431701b4eb687222e35b7c5e88c918396bc 100644 (file)
@@ -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.  */
index d8c99d8e3c27e4855ef95fab30cc455607b8cb81..f16c91cd44b21b2f602d4707e878939ea17099ed 100644 (file)
@@ -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);
 }
index 0e596b597449ea6ed32448a7caae52f65a9ceb1d..cb220c82c4ebde3ddae98e342d60f7dccd331261 100644 (file)
@@ -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 (file)
index 0000000..323bd97
--- /dev/null
@@ -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 (file)
index 0000000..66e151e
--- /dev/null
@@ -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*-*-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