[PATCH 0/1] Add LoongArch64 support for D frontend

2023-09-23 Thread liushuyu



This patch adds the LoongArch64 support for GCC D frontend.

The runtime support is submitted as a separate patch here:
https://github.com/dlang/dmd/pull/15628.

You can find more information about the LoongArch architecture on this
website:
https://loongson.github.io/LoongArch-Documentation/README-EN.html.

Zixing Liu (1):
  gcc/d: add LoongArch64 support for D frontend

 gcc/config.gcc|  1 +
 gcc/config/loongarch/loongarch-d.cc   | 82 
 gcc/config/loongarch/loongarch-d.h| 26 +
 gcc/config/loongarch/t-loongarch  |  4 +
 .../fail_compilation/reserved_version.d   | 98 +++
 .../reserved_version_switch.d | 12 +++
 libphobos/configure.tgt   |  3 +
 libphobos/libdruntime/gcc/sections/elf.d  |  2 +
 libphobos/libdruntime/gcc/unwind/generic.d|  1 +
 9 files changed, 186 insertions(+), 43 deletions(-)
 create mode 100644 gcc/config/loongarch/loongarch-d.cc
 create mode 100644 gcc/config/loongarch/loongarch-d.h

--
2.42.0



[PATCH 1/1] gcc/d: add LoongArch64 support for D frontend

2023-09-23 Thread liushuyu



gcc/ChangeLog:

* config.gcc: add loongarch-d.o to d_target_objs for LoongArch
architecture.

gcc/config/ChangeLog:

* loongarch/loongarch-d.cc
(loongarch_d_target_versions): add interface function to define builtin
D versions for LoongArch architecture.
(loongarch_d_handle_target_float_abi): add interface function to define
builtin D traits for LoongArch architecture.
(loongarch_d_register_target_info): add interface function to register
loongarch_d_handle_target_float_abi function.
* loongarch/loongarch-d.h:
(loongarch_d_target_versions): add function prototype.
(loongarch_d_register_target_info): Likewise.
* loongarch/t-loongarch: add object target for loongarch-d.cc.

gcc/testsuite/ChangeLog:

* gdc.test/fail_compilation/reserved_version.d: add reserved version
tests for LoongArch architecture and also updated expected output.
* gdc.test/fail_compilation/reserved_version_switch.d: Likewise.

libphobos/ChangeLog:

* configure.tgt: enable libphobos for LoongArch architecture.
* configure: Regenerate.
* libdruntime/gcc/sections/elf.d: add TLS_DTV_OFFSET constant for
LoongArch64.
* libdruntime/gcc/unwind/generic.d: add __aligned__ constant for
LoongArch64.
* libdruntime/Makefile.in: Regenerate.

Signed-off-by: Zixing Liu 
---
 gcc/config.gcc|  1 +
 gcc/config/loongarch/loongarch-d.cc   | 82 
 gcc/config/loongarch/loongarch-d.h| 26 +
 gcc/config/loongarch/t-loongarch  |  4 +
 .../fail_compilation/reserved_version.d   | 98 +++
 .../reserved_version_switch.d | 12 +++
 libphobos/configure.tgt   |  3 +
 libphobos/libdruntime/gcc/sections/elf.d  |  2 +
 libphobos/libdruntime/gcc/unwind/generic.d|  1 +
 9 files changed, 186 insertions(+), 43 deletions(-)
 create mode 100644 gcc/config/loongarch/loongarch-d.cc
 create mode 100644 gcc/config/loongarch/loongarch-d.h

diff --git a/gcc/config.gcc b/gcc/config.gcc
index ee46d96bf62..782d933b497 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -480,6 +480,7 @@ mips*-*-*)
;;
 loongarch*-*-*)
cpu_type=loongarch
+   d_target_objs="loongarch-d.o"
extra_headers="larchintrin.h lsxintrin.h lasxintrin.h"
 	extra_objs="loongarch-c.o loongarch-builtins.o loongarch-cpu.o 
loongarch-opts.o loongarch-def.o"
 	extra_gcc_objs="loongarch-driver.o loongarch-cpu.o loongarch-opts.o 
loongarch-def.o"
diff --git a/gcc/config/loongarch/loongarch-d.cc 
b/gcc/config/loongarch/loongarch-d.cc

new file mode 100644
index 000..d7875079212
--- /dev/null
+++ b/gcc/config/loongarch/loongarch-d.cc
@@ -0,0 +1,82 @@
+/* Subroutines for the D front end on the LoongArch architecture.
+   Copyright (C) 2017-2023 Free Software Foundation, Inc.
+
+GCC 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, or (at your option)
+any later version.
+
+GCC 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
+.  */
+
+#define IN_TARGET_CODE 1
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm_d.h"
+#include "d/d-target.h"
+#include "d/d-target-def.h"
+
+/* Implement TARGET_D_CPU_VERSIONS for LoongArch targets.  */
+
+void
+loongarch_d_target_versions (void)
+{
+  if (TARGET_64BIT)
+d_add_builtin_version ("LoongArch64");
+  else
+d_add_builtin_version ("LoongArch32");
+
+  if (TARGET_ABI_LP64)
+d_add_builtin_version ("D_LP64");
+  else
+d_add_builtin_version ("D_LP32");
+
+  if (TARGET_HARD_FLOAT_ABI)
+{
+  d_add_builtin_version ("LoongArch_HardFloat");
+  d_add_builtin_version ("D_HardFloat");
+}
+  else if (TARGET_SOFT_FLOAT_ABI)
+{
+  d_add_builtin_version ("LoongArch_SoftFloat");
+  d_add_builtin_version ("D_SoftFloat");
+}
+}
+
+/* Handle a call to `__traits(getTargetInfo, "floatAbi")'.  */
+
+static tree
+loongarch_d_handle_target_float_abi (void)
+{
+  const char *abi;
+
+  if (TARGET_HARD_FLOAT_ABI)
+abi = "hard";
+  else if (TARGET_SOFT_FLOAT_ABI)
+abi = "soft";
+  else
+abi = "";
+
+  return build_string_literal (strlen (abi) + 1, abi);
+}
+
+/* Implement TARGET_D_REGISTER_CPU_TARGET_INFO.  */
+
+void
+loongarch_d_register_target_info (void)
+{
+  const struct d_target_info_spec handlers[] = {
+{"floatAbi", loongarch_d_handle_target_float_abi},
+{NULL, NULL},
+  };
+
+  d_add_target_info_handlers (handlers)

[PATCH 0/1] Add LoongArch64 support for D frontend

2023-09-23 Thread liushuyu
From: Zixing Liu 

This patch adds the LoongArch64 support for GCC D frontend.

The runtime support is submitted as a separate patch here:
https://github.com/dlang/dmd/pull/15628.

You can find more information about the LoongArch architecture on this
website:
https://loongson.github.io/LoongArch-Documentation/README-EN.html.

Zixing Liu (1):
  gcc/d: add LoongArch64 support for D frontend

 gcc/config.gcc|  1 +
 gcc/config/loongarch/loongarch-d.cc   | 82 
 gcc/config/loongarch/loongarch-d.h| 26 +
 gcc/config/loongarch/t-loongarch  |  4 +
 .../fail_compilation/reserved_version.d   | 98 +++
 .../reserved_version_switch.d | 12 +++
 libphobos/configure.tgt   |  3 +
 libphobos/libdruntime/gcc/sections/elf.d  |  2 +
 libphobos/libdruntime/gcc/unwind/generic.d|  1 +
 9 files changed, 186 insertions(+), 43 deletions(-)
 create mode 100644 gcc/config/loongarch/loongarch-d.cc
 create mode 100644 gcc/config/loongarch/loongarch-d.h

-- 
2.42.0



[PATCH 1/1] gcc/d: add LoongArch64 support for D frontend

2023-09-23 Thread liushuyu
gcc/ChangeLog:

* config.gcc: add loongarch-d.o to d_target_objs for LoongArch
architecture.

gcc/config/ChangeLog:

* loongarch/loongarch-d.cc
(loongarch_d_target_versions): add interface function to define builtin
D versions for LoongArch architecture.
(loongarch_d_handle_target_float_abi): add interface function to define
builtin D traits for LoongArch architecture.
(loongarch_d_register_target_info): add interface function to register
loongarch_d_handle_target_float_abi function.
* loongarch/loongarch-d.h:
(loongarch_d_target_versions): add function prototype.
(loongarch_d_register_target_info): Likewise.
* loongarch/t-loongarch: add object target for loongarch-d.cc.

gcc/testsuite/ChangeLog:

* gdc.test/fail_compilation/reserved_version.d: add reserved version
tests for LoongArch architecture and also updated expected output.
* gdc.test/fail_compilation/reserved_version_switch.d: Likewise.

libphobos/ChangeLog:

* configure.tgt: enable libphobos for LoongArch architecture.
* configure: Regenerate.
* libdruntime/gcc/sections/elf.d: add TLS_DTV_OFFSET constant for
LoongArch64.
* libdruntime/gcc/unwind/generic.d: add __aligned__ constant for
LoongArch64.
* libdruntime/Makefile.in: Regenerate.

Signed-off-by: Zixing Liu 
---
 gcc/config.gcc|  1 +
 gcc/config/loongarch/loongarch-d.cc   | 82 
 gcc/config/loongarch/loongarch-d.h| 26 +
 gcc/config/loongarch/t-loongarch  |  4 +
 .../fail_compilation/reserved_version.d   | 98 +++
 .../reserved_version_switch.d | 12 +++
 libphobos/configure.tgt   |  3 +
 libphobos/libdruntime/gcc/sections/elf.d  |  2 +
 libphobos/libdruntime/gcc/unwind/generic.d|  1 +
 9 files changed, 186 insertions(+), 43 deletions(-)
 create mode 100644 gcc/config/loongarch/loongarch-d.cc
 create mode 100644 gcc/config/loongarch/loongarch-d.h

diff --git a/gcc/config.gcc b/gcc/config.gcc
index ee46d96bf62..782d933b497 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -480,6 +480,7 @@ mips*-*-*)
;;
 loongarch*-*-*)
cpu_type=loongarch
+   d_target_objs="loongarch-d.o"
extra_headers="larchintrin.h lsxintrin.h lasxintrin.h"
extra_objs="loongarch-c.o loongarch-builtins.o loongarch-cpu.o 
loongarch-opts.o loongarch-def.o"
extra_gcc_objs="loongarch-driver.o loongarch-cpu.o loongarch-opts.o 
loongarch-def.o"
diff --git a/gcc/config/loongarch/loongarch-d.cc 
b/gcc/config/loongarch/loongarch-d.cc
new file mode 100644
index 000..d7875079212
--- /dev/null
+++ b/gcc/config/loongarch/loongarch-d.cc
@@ -0,0 +1,82 @@
+/* Subroutines for the D front end on the LoongArch architecture.
+   Copyright (C) 2017-2023 Free Software Foundation, Inc.
+
+GCC 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, or (at your option)
+any later version.
+
+GCC 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
+.  */
+
+#define IN_TARGET_CODE 1
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm_d.h"
+#include "d/d-target.h"
+#include "d/d-target-def.h"
+
+/* Implement TARGET_D_CPU_VERSIONS for LoongArch targets.  */
+
+void
+loongarch_d_target_versions (void)
+{
+  if (TARGET_64BIT)
+d_add_builtin_version ("LoongArch64");
+  else
+d_add_builtin_version ("LoongArch32");
+
+  if (TARGET_ABI_LP64)
+d_add_builtin_version ("D_LP64");
+  else
+d_add_builtin_version ("D_LP32");
+
+  if (TARGET_HARD_FLOAT_ABI)
+{
+  d_add_builtin_version ("LoongArch_HardFloat");
+  d_add_builtin_version ("D_HardFloat");
+}
+  else if (TARGET_SOFT_FLOAT_ABI)
+{
+  d_add_builtin_version ("LoongArch_SoftFloat");
+  d_add_builtin_version ("D_SoftFloat");
+}
+}
+
+/* Handle a call to `__traits(getTargetInfo, "floatAbi")'.  */
+
+static tree
+loongarch_d_handle_target_float_abi (void)
+{
+  const char *abi;
+
+  if (TARGET_HARD_FLOAT_ABI)
+abi = "hard";
+  else if (TARGET_SOFT_FLOAT_ABI)
+abi = "soft";
+  else
+abi = "";
+
+  return build_string_literal (strlen (abi) + 1, abi);
+}
+
+/* Implement TARGET_D_REGISTER_CPU_TARGET_INFO.  */
+
+void
+loongarch_d_register_target_info (void)
+{
+  const struct d_target_info_spec handlers[] = {
+{"floatAbi", loongarch_d_handle_target_float_abi},
+{NULL, NULL},
+  };
+
+  d_add_target_info_handlers (h

Re: [PATCH v2 0/1] Add LoongArch64 support for D frontend

2023-09-25 Thread liushuyu

Hi Yujie,

Sorry, I did not know Loongson Technologies is also working on this.

However, you can jump onto that GitHub pull request to review my changes 
so that they align with your implementation and nobody's effort would go 
to waste.


Thanks,

Zixing

On 2023/9/25 04:04, Yang Yujie wrote:

Hi Zixing,

We are also working on a patch series that could pass the libphobos regression 
tests.
Will post this later once all failed items are fixed.

Yujie

On Sun, Sep 24, 2023 at 03:40:32PM -0600, Zixing Liu wrote:

This patch adds the LoongArch64 support for GCC D frontend.

The runtime support is submitted as a separate patch here:
https://github.com/dlang/dmd/pull/15628.

You can find more information about the LoongArch architecture on this
website:
https://loongson.github.io/LoongArch-Documentation/README-EN.html.

--

Changes since the last revision of the patch:

* Corrected copyright years in loongarch-d.cc and loongarch-d.h.
* Removed changes to the tests, the changes have been rolled into the DMD
   changes in:
   
https://github.com/dlang/dmd/pull/15628/commits/eb84b8a2bc86aa751ad6f472422e8abad63ff500
   .
* Removed D_LP32 and D_LP64 bits. Since LoongArch ABIs are somewhat
   complicated, we may introduce the ABI information in the form of target
   traits in the future.

Zixing Liu (1):

  gcc/config.gcc |  1 +
  gcc/config/loongarch/loongarch-d.cc| 77 ++
  gcc/config/loongarch/loongarch-d.h | 26 
  gcc/config/loongarch/t-loongarch   |  4 ++
  libphobos/configure.tgt|  3 +
  libphobos/libdruntime/gcc/sections/elf.d   |  2 +
  libphobos/libdruntime/gcc/unwind/generic.d |  1 +
  7 files changed, 114 insertions(+)
  create mode 100644 gcc/config/loongarch/loongarch-d.cc
  create mode 100644 gcc/config/loongarch/loongarch-d.h

--
2.42.0


[PATCH 0/1] gdc: define ELFv1, ELFv2 and D_PPCUseIEEE128 versions for powerpc

2025-02-05 Thread liushuyu
From: Zixing Liu 

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 
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 
---
 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 00..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



Re: [PATCH 0/1] gdc: define ELFv1, ELFv2 and D_PPCUseIEEE128 versions for powerpc

2025-02-12 Thread liushuyu

Hi,


Excerpts from liushuyu's message of Februar 6, 2025 2:02 am:

From: Zixing Liu 

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.

Thanks. I wonder if something could be done to predefine ELFv1 for other
targets too. Unconditionally calling add_builtin_version in glibc-d.cc,
freebsd-d.cc, ..., doesn't seem like the best thing to do, but I'm open
for suggestions.


As far as I understand, ELFv1 and ELFv2 concepts are limited to PowerPC 
platforms due to the need for compatibility.


No other platform (supported by D) has such a need for defining ELFv1 
and ELFv2 version identifiers.



+
+  if (TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128)
+d_add_builtin_version ("D_PPCUseIEEE128");

It says in the spec that all version identifiers derived from any
predefined versions by appending any character(s) are reserved.

So there's no need for the `D_` prefix, `PPC_UseIEEE128` will suffice.


In the upstream druntime change 
(https://github.com/dlang/dmd/pull/20826), I have changed the identifier 
to `|PPCUseIEEE128` and instead of letting compilers setting it, I have 
changed the druntime so that compiler does not need to explicitly set 
this version identifier.

|

||


+
+// { 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;
+}

These two tests should return a different value, otherwise you could
just end up matching the same function return twice.


I will address this comment in a newer revision of the patch.

A newer revision of the patch will be submitted after the D language 
upstream merges the druntime changes.



Kind regards,
Iain.


Thanks,

Zixing



[PATCH v2 1/1] gdc: define ELFv1 and ELFv2 versions for powerpc

2025-02-13 Thread liushuyu
From: Zixing Liu 

gcc/ChangeLog:
* config/rs6000/rs6000-d.cc: define ELFv1 and ELFv2
  version identifiers according to the target options.

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 
---
 gcc/config/rs6000/rs6000-d.cc |  5 +
 gcc/testsuite/gdc.dg/ppcabi.d | 23 +++
 2 files changed, 28 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..bc5d643d49 100644
--- a/gcc/config/rs6000/rs6000-d.cc
+++ b/gcc/config/rs6000/rs6000-d.cc
@@ -45,6 +45,11 @@ 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");
 }
 
 /* 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 00..9271c64436
--- /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 (PPC64) return real.mant_dig == 113;
+else return false;
+}
+
+// { dg-final { scan-assembler "test_elf_version" } }
+extern (C) bool test_elf_version() {
+// { dg-final { scan-assembler "li 3,0" } }
+version (ELFv2) return false;
+else return true;
+}
-- 
2.48.1



[PATCH v2 0/1] gdc: define ELFv1 and ELFv2 versions for powerpc

2025-02-13 Thread liushuyu
From: Zixing Liu 

This patch was formerly known as
"gdc: define ELFv1, ELFv2 and D_PPCUseIEEE128 versions for powerpc",
due to new developments in https://github.com/dlang/dmd/pull/20826,
compiler is now not required to mark D_PPCUseIEEE128 version identifier.
Instead, correctly setting real.mant_dig will suffice (GDC is already providing
the correct information).

The patch 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.

ELFv1 and ELFv2 ABI concept seem to only exist on POWER platforms,
so other platforms do not need to follow this change, as far as I know.

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

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

-- 
2.48.1