From: Zixing Liu <liushuyu...@gmail.com>

This set of patches will add proper IEEE 128 quad precision marking to GDC
compiler, so that it works with the new changes in D standard library
where POWER system can use any math functions inside the standard library
that requires the "real" type.

The patch also adds the ELFv1 and ELFv2 version identifiers to bridge
the gap between LLVM D Compiler (LDC) and GNU D Compiler (GDC) so that
the user can reliably use the "version(...)" syntax to check for which
ABI is currently in use.

Zixing Liu (1):
  gdc: define ELFv1, ELFv2 and D_PPCUseIEEE128 versions for powerpc

 gcc/config/rs6000/rs6000-d.cc |  8 ++++++++
 gcc/testsuite/gdc.dg/ppcabi.d | 23 +++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/ppcabi.d

-- 
2.48.1

>From 67f7c2207f1bbe0c7a5e1751e45e85c6abfe9357 Mon Sep 17 00:00:00 2001
From: Zixing Liu <liushuyu...@gmail.com>
Date: Wed, 5 Feb 2025 17:46:23 -0700
Subject: [PATCH 1/1] gdc: define ELFv1, ELFv2 and D_PPCUseIEEE128 versions for
 powerpc

gcc/ChangeLog:
        * config/rs6000/rs6000-d.cc: define ELFv1, ELFv2 and D_PPCUseIEEE128
          version identifiers according to the target options.
          This allows POWER system with IEEE 128 capable libc to use a
          larger set of D standard library (phobos).

gcc/testsuite/ChangeLog:
        * gdc.dg/ppcabi.d: Add a test to test for code generation
          correctness when using IEEE 128 and new ELFv1 and ELFv2
          identifiers.

Signed-off-by: Zixing Liu <liushuyu...@gmail.com>
---
 gcc/config/rs6000/rs6000-d.cc |  8 ++++++++
 gcc/testsuite/gdc.dg/ppcabi.d | 23 +++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/ppcabi.d

diff --git a/gcc/config/rs6000/rs6000-d.cc b/gcc/config/rs6000/rs6000-d.cc
index c9e1acad88..1b19275760 100644
--- a/gcc/config/rs6000/rs6000-d.cc
+++ b/gcc/config/rs6000/rs6000-d.cc
@@ -45,6 +45,14 @@ rs6000_d_target_versions (void)
       d_add_builtin_version ("PPC_SoftFloat");
       d_add_builtin_version ("D_SoftFloat");
     }
+
+  if (DEFAULT_ABI == ABI_ELFv2)
+    d_add_builtin_version ("ELFv2");
+  else
+    d_add_builtin_version ("ELFv1");
+
+  if (TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128)
+    d_add_builtin_version ("D_PPCUseIEEE128");
 }
 
 /* Handle a call to `__traits(getTargetInfo, "floatAbi")'.  */
diff --git a/gcc/testsuite/gdc.dg/ppcabi.d b/gcc/testsuite/gdc.dg/ppcabi.d
new file mode 100644
index 0000000000..38a90eb16e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/ppcabi.d
@@ -0,0 +1,23 @@
+// { dg-do compile { target { powerpc64*-linux-gnu* } } }
+// { dg-options "-mabi=ieeelongdouble -mabi=elfv2 -mcpu=power9 -O2" }
+
+// { dg-final { scan-assembler "_Z13test_functionu9__ieee128" } }
+extern (C++) bool test_function(real arg) {
+    // { dg-final { scan-assembler "xscmpuqp" } }
+    // { dg-final { scan-assembler-not "fcmpu" } }
+    return arg > 0.0;
+}
+
+// { dg-final { scan-assembler "test_version" } }
+extern (C) bool test_version() {
+    // { dg-final { scan-assembler "li 3,1" } }
+    version (D_PPCUseIEEE128) return true;
+    else return false;
+}
+
+// { dg-final { scan-assembler "test_elf_version" } }
+extern (C) bool test_elf_version() {
+    // { dg-final { scan-assembler "li 3,1" } }
+    version (ELFv2) return true;
+    else return false;
+}
-- 
2.48.1

Reply via email to