public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/3] LoongArch GDC support.
@ 2023-11-17 10:00 Yang Yujie
  2023-11-17 10:00 ` [PATCH 1/3] LoongArch: Adjust D version strings Yang Yujie
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yang Yujie @ 2023-11-17 10:00 UTC (permalink / raw)
  To: gcc-patches; +Cc: ibuclaw, chenglulu, xuchenghua, Yang Yujie

This patchset is based on Zixing Liu's initial support patch:
https://gcc.gnu.org/pipermail/gcc-patches/2023-September/631260.html

Yang Yujie (3):
  LoongArch: Adjust D version strings.
  libphobos: Update build scripts for LoongArch64.
  libphobos: Adjust LoongArch definitons.

 gcc/config/loongarch/loongarch-d.cc           |  27 ++--
 gcc/d/dmd/cond.d                              |   6 +-
 gcc/d/implement-d.texi                        |   6 +
 libphobos/configure                           |  21 ++-
 libphobos/libdruntime/Makefile.am             |   3 +
 libphobos/libdruntime/Makefile.in             |  98 ++++++++-----
 .../config/loongarch/switchcontext.S          | 133 ++++++++++++++++++
 libphobos/libdruntime/core/stdc/fenv.d        |   8 +-
 libphobos/libdruntime/core/stdc/stdarg.d      |   6 +
 libphobos/libdruntime/core/sys/elf/package.d  |   2 +
 .../libdruntime/core/sys/linux/sys/auxv.d     |  17 +++
 .../libdruntime/core/sys/linux/sys/mman.d     |   1 +
 libphobos/libdruntime/core/thread/fiber.d     |  55 +++++---
 libphobos/libdruntime/core/vararg.d           |   7 +
 libphobos/m4/druntime/cpu.m4                  |   5 +
 libphobos/src/std/math/hardware.d             |  77 ++++++++++
 16 files changed, 389 insertions(+), 83 deletions(-)
 create mode 100644 libphobos/libdruntime/config/loongarch/switchcontext.S

-- 
2.42.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] LoongArch: Adjust D version strings.
  2023-11-17 10:00 [PATCH 0/3] LoongArch GDC support Yang Yujie
@ 2023-11-17 10:00 ` Yang Yujie
  2023-11-17 10:00 ` [PATCH 2/3] libphobos: Update build scripts for LoongArch64 Yang Yujie
  2023-11-17 10:00 ` [PATCH 3/3] libphobos: Adjust LoongArch definitons Yang Yujie
  2 siblings, 0 replies; 4+ messages in thread
From: Yang Yujie @ 2023-11-17 10:00 UTC (permalink / raw)
  To: gcc-patches; +Cc: ibuclaw, chenglulu, xuchenghua, Yang Yujie

gcc/ChangeLog:

	* config/loongarch/loongarch-d.cc: Undefine LoongArch32.
	Define LoongArch_SF, LoongArch_F32, LoongArch_F64

gcc/d/ChangeLog:

	* dmd/cond.d: Same.
	* implement-d.texi: Same.
---
 gcc/config/loongarch/loongarch-d.cc | 27 ++++++++++++++-------------
 gcc/d/dmd/cond.d                    |  6 +++---
 gcc/d/implement-d.texi              |  6 ++++++
 3 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/gcc/config/loongarch/loongarch-d.cc b/gcc/config/loongarch/loongarch-d.cc
index 9ac483c39a7..4692b78708a 100644
--- a/gcc/config/loongarch/loongarch-d.cc
+++ b/gcc/config/loongarch/loongarch-d.cc
@@ -29,24 +29,27 @@ along with GCC; see the file COPYING3.  If not see
 void
 loongarch_d_target_versions (void)
 {
-  if (TARGET_64BIT)
+  if (TARGET_ABI_LP64)
     d_add_builtin_version ("LoongArch64");
-  else
-    d_add_builtin_version ("LoongArch32");
 
-  if (TARGET_HARD_FLOAT_ABI)
+  if (TARGET_DOUBLE_FLOAT_ABI)
+    {
+      d_add_builtin_version ("LoongArch_F64");
+      d_add_builtin_version ("D_HardFloat");
+    }
+  else if (TARGET_SINGLE_FLOAT_ABI)
     {
-      d_add_builtin_version ("LoongArch_HardFloat");
+      d_add_builtin_version ("LoongArch_F32");
       d_add_builtin_version ("D_HardFloat");
     }
-  else if (TARGET_SOFT_FLOAT_ABI)
+  else
     {
-      d_add_builtin_version ("LoongArch_SoftFloat");
+      d_add_builtin_version ("LoongArch_SF");
       d_add_builtin_version ("D_SoftFloat");
     }
 }
 
-/* Handle a call to `__traits(getTargetInfo, "floatAbi")'.  */
+/* Handle trait getTargetInfo with key "floatAbi"  */
 
 static tree
 loongarch_d_handle_target_float_abi (void)
@@ -55,10 +58,8 @@ loongarch_d_handle_target_float_abi (void)
 
   if (TARGET_HARD_FLOAT_ABI)
     abi = "hard";
-  else if (TARGET_SOFT_FLOAT_ABI)
-    abi = "soft";
   else
-    abi = "";
+    abi = "soft";
 
   return build_string_literal (strlen (abi) + 1, abi);
 }
@@ -69,8 +70,8 @@ void
 loongarch_d_register_target_info (void)
 {
   const struct d_target_info_spec handlers[] = {
-    {"floatAbi", loongarch_d_handle_target_float_abi},
-    {NULL, NULL},
+    { "floatAbi", loongarch_d_handle_target_float_abi },
+    { NULL, NULL },
   };
 
   d_add_target_info_handlers (handlers);
diff --git a/gcc/d/dmd/cond.d b/gcc/d/dmd/cond.d
index a8d099433a2..a6317eeffb1 100644
--- a/gcc/d/dmd/cond.d
+++ b/gcc/d/dmd/cond.d
@@ -692,10 +692,10 @@ extern (C++) final class VersionCondition : DVCondition
             case "LDC":
             case "linux":
             case "LittleEndian":
-            case "LoongArch32":
             case "LoongArch64":
-            case "LoongArch_HardFloat":
-            case "LoongArch_SoftFloat":
+            case "LoongArch_F64":
+            case "LoongArch_F32":
+            case "LoongArch_SF":
             case "MinGW":
             case "MIPS32":
             case "MIPS64":
diff --git a/gcc/d/implement-d.texi b/gcc/d/implement-d.texi
index 6f33bc192fe..cc0d1ecf593 100644
--- a/gcc/d/implement-d.texi
+++ b/gcc/d/implement-d.texi
@@ -1966,6 +1966,12 @@ Version relating to GNU Hurd systems.
 @item linux
 Version relating to Linux systems.
 
+@item LoongArch64
+@item LoongArch_SF
+@item LoongArch_F32
+@item LoongArch_F64
+Versions relating to the LoongArch family of processors.
+
 @item MinGW
 Version relating to the MinGW environment.
 
-- 
2.42.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] libphobos: Update build scripts for LoongArch64.
  2023-11-17 10:00 [PATCH 0/3] LoongArch GDC support Yang Yujie
  2023-11-17 10:00 ` [PATCH 1/3] LoongArch: Adjust D version strings Yang Yujie
@ 2023-11-17 10:00 ` Yang Yujie
  2023-11-17 10:00 ` [PATCH 3/3] libphobos: Adjust LoongArch definitons Yang Yujie
  2 siblings, 0 replies; 4+ messages in thread
From: Yang Yujie @ 2023-11-17 10:00 UTC (permalink / raw)
  To: gcc-patches; +Cc: ibuclaw, chenglulu, xuchenghua, Yang Yujie

libphobos/ChangeLog:

	* m4/druntime/cpu.m4: Support loongarch* targets.
	* libdruntime/Makefile.am: Same.
	* libdruntime/Makefile.in: Regenerate.
	* configure: Regenerate.
---
 libphobos/configure               | 21 ++++++-
 libphobos/libdruntime/Makefile.am |  3 +
 libphobos/libdruntime/Makefile.in | 98 +++++++++++++++++++------------
 libphobos/m4/druntime/cpu.m4      |  5 ++
 4 files changed, 87 insertions(+), 40 deletions(-)

diff --git a/libphobos/configure b/libphobos/configure
index 25b13bdd93e..9a59bad34ac 100755
--- a/libphobos/configure
+++ b/libphobos/configure
@@ -696,6 +696,8 @@ DRUNTIME_CPU_POWERPC_FALSE
 DRUNTIME_CPU_POWERPC_TRUE
 DRUNTIME_CPU_MIPS_FALSE
 DRUNTIME_CPU_MIPS_TRUE
+DRUNTIME_CPU_LOONGARCH_FALSE
+DRUNTIME_CPU_LOONGARCH_TRUE
 DRUNTIME_CPU_ARM_FALSE
 DRUNTIME_CPU_ARM_TRUE
 DRUNTIME_CPU_AARCH64_FALSE
@@ -11865,7 +11867,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11868 "configure"
+#line 11870 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11971,7 +11973,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11974 "configure"
+#line 11976 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -14305,6 +14307,9 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
                ;;
       arm*)    druntime_target_cpu_parsed="arm"
                ;;
+      loongarch*)
+               druntime_target_cpu_parsed="loongarch"
+               ;;
       mips*)   druntime_target_cpu_parsed="mips"
                ;;
       powerpc*)
@@ -14336,6 +14341,14 @@ else
   DRUNTIME_CPU_ARM_FALSE=
 fi
 
+   if test "$druntime_target_cpu_parsed" = "loongarch"; then
+  DRUNTIME_CPU_LOONGARCH_TRUE=
+  DRUNTIME_CPU_LOONGARCH_FALSE='#'
+else
+  DRUNTIME_CPU_LOONGARCH_TRUE='#'
+  DRUNTIME_CPU_LOONGARCH_FALSE=
+fi
+
    if test "$druntime_target_cpu_parsed" = "mips"; then
   DRUNTIME_CPU_MIPS_TRUE=
   DRUNTIME_CPU_MIPS_FALSE='#'
@@ -15997,6 +16010,10 @@ if test -z "${DRUNTIME_CPU_ARM_TRUE}" && test -z "${DRUNTIME_CPU_ARM_FALSE}"; th
   as_fn_error $? "conditional \"DRUNTIME_CPU_ARM\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${DRUNTIME_CPU_LOONGARCH_TRUE}" && test -z "${DRUNTIME_CPU_LOONGARCH_FALSE}"; then
+  as_fn_error $? "conditional \"DRUNTIME_CPU_LOONGARCH\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${DRUNTIME_CPU_MIPS_TRUE}" && test -z "${DRUNTIME_CPU_MIPS_FALSE}"; then
   as_fn_error $? "conditional \"DRUNTIME_CPU_MIPS\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am
index 23205fd3301..ca43a0753c4 100644
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -83,6 +83,9 @@ endif
 if DRUNTIME_CPU_ARM
     DRUNTIME_SOURCES_CONFIGURED += config/arm/switchcontext.S
 endif
+if DRUNTIME_CPU_LOONGARCH
+    DRUNTIME_SOURCES_CONFIGURED += config/loongarch/switchcontext.S
+endif
 if DRUNTIME_CPU_MIPS
     DRUNTIME_SOURCES_CONFIGURED += config/mips/switchcontext.S
 endif
diff --git a/libphobos/libdruntime/Makefile.in b/libphobos/libdruntime/Makefile.in
index 410245d71ca..f52bf36c282 100644
--- a/libphobos/libdruntime/Makefile.in
+++ b/libphobos/libdruntime/Makefile.in
@@ -124,12 +124,13 @@ target_triplet = @target@
 # CPU specific sources
 @DRUNTIME_CPU_AARCH64_TRUE@am__append_11 = config/aarch64/switchcontext.S
 @DRUNTIME_CPU_ARM_TRUE@am__append_12 = config/arm/switchcontext.S
-@DRUNTIME_CPU_MIPS_TRUE@am__append_13 = config/mips/switchcontext.S
-@DRUNTIME_CPU_POWERPC_TRUE@am__append_14 = config/powerpc/switchcontext.S
-@DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_TRUE@am__append_15 = config/mingw/switchcontext.S
-@DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_FALSE@am__append_16 = config/x86/switchcontext.S
-@DRUNTIME_CPU_SYSTEMZ_TRUE@am__append_17 = config/systemz/get_tls_offset.S
-@DRUNTIME_CPU_S390_TRUE@am__append_18 = config/s390/get_tls_offset.S
+@DRUNTIME_CPU_LOONGARCH_TRUE@am__append_13 = config/loongarch/switchcontext.S
+@DRUNTIME_CPU_MIPS_TRUE@am__append_14 = config/mips/switchcontext.S
+@DRUNTIME_CPU_POWERPC_TRUE@am__append_15 = config/powerpc/switchcontext.S
+@DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_TRUE@am__append_16 = config/mingw/switchcontext.S
+@DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_FALSE@am__append_17 = config/x86/switchcontext.S
+@DRUNTIME_CPU_SYSTEMZ_TRUE@am__append_18 = config/systemz/get_tls_offset.S
+@DRUNTIME_CPU_S390_TRUE@am__append_19 = config/s390/get_tls_offset.S
 subdir = libdruntime
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
@@ -485,46 +486,50 @@ am__objects_23 = core/sys/solaris/dlfcn.lo core/sys/solaris/elf.lo \
 @DRUNTIME_OS_SOLARIS_TRUE@am__objects_24 = $(am__objects_23)
 @DRUNTIME_CPU_AARCH64_TRUE@am__objects_25 = config/aarch64/libgdruntime_la-switchcontext.lo
 @DRUNTIME_CPU_ARM_TRUE@am__objects_26 = config/arm/libgdruntime_la-switchcontext.lo
-@DRUNTIME_CPU_MIPS_TRUE@am__objects_27 = config/mips/libgdruntime_la-switchcontext.lo
-@DRUNTIME_CPU_POWERPC_TRUE@am__objects_28 = config/powerpc/libgdruntime_la-switchcontext.lo
-@DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_TRUE@am__objects_29 = config/mingw/libgdruntime_la-switchcontext.lo
-@DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_FALSE@am__objects_30 = config/x86/libgdruntime_la-switchcontext.lo
-@DRUNTIME_CPU_SYSTEMZ_TRUE@am__objects_31 = config/systemz/libgdruntime_la-get_tls_offset.lo
-@DRUNTIME_CPU_S390_TRUE@am__objects_32 = config/s390/libgdruntime_la-get_tls_offset.lo
-am__objects_33 = $(am__objects_6) $(am__objects_8) $(am__objects_10) \
+@DRUNTIME_CPU_LOONGARCH_TRUE@am__objects_27 = config/loongarch/libgdruntime_la-switchcontext.lo
+@DRUNTIME_CPU_MIPS_TRUE@am__objects_28 = config/mips/libgdruntime_la-switchcontext.lo
+@DRUNTIME_CPU_POWERPC_TRUE@am__objects_29 = config/powerpc/libgdruntime_la-switchcontext.lo
+@DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_TRUE@am__objects_30 = config/mingw/libgdruntime_la-switchcontext.lo
+@DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_FALSE@am__objects_31 = config/x86/libgdruntime_la-switchcontext.lo
+@DRUNTIME_CPU_SYSTEMZ_TRUE@am__objects_32 = config/systemz/libgdruntime_la-get_tls_offset.lo
+@DRUNTIME_CPU_S390_TRUE@am__objects_33 = config/s390/libgdruntime_la-get_tls_offset.lo
+am__objects_34 = $(am__objects_6) $(am__objects_8) $(am__objects_10) \
 	$(am__objects_12) $(am__objects_14) $(am__objects_16) \
 	$(am__objects_18) $(am__objects_20) $(am__objects_22) \
 	$(am__objects_24) $(am__objects_25) $(am__objects_26) \
 	$(am__objects_27) $(am__objects_28) $(am__objects_29) \
-	$(am__objects_30) $(am__objects_31) $(am__objects_32)
-am__objects_34 = gcc/config.lo gcc/libbacktrace.lo
-am__objects_35 = $(am__objects_1) $(am__objects_2) $(am__objects_3) \
-	$(am__objects_4) $(am__objects_33) $(am__objects_34)
-am_libgdruntime_la_OBJECTS = $(am__objects_35)
+	$(am__objects_30) $(am__objects_31) $(am__objects_32) \
+	$(am__objects_33)
+am__objects_35 = gcc/config.lo gcc/libbacktrace.lo
+am__objects_36 = $(am__objects_1) $(am__objects_2) $(am__objects_3) \
+	$(am__objects_4) $(am__objects_34) $(am__objects_35)
+am_libgdruntime_la_OBJECTS = $(am__objects_36)
 libgdruntime_la_OBJECTS = $(am_libgdruntime_la_OBJECTS)
 am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
-am__objects_36 = core/stdc/libgdruntime_convenience_la-errno_.lo \
+am__objects_37 = core/stdc/libgdruntime_convenience_la-errno_.lo \
 	etc/valgrind/libgdruntime_convenience_la-valgrind_.lo
-@DRUNTIME_OS_MINGW_TRUE@am__objects_37 = $(am__objects_21) \
+@DRUNTIME_OS_MINGW_TRUE@am__objects_38 = $(am__objects_21) \
 @DRUNTIME_OS_MINGW_TRUE@	config/mingw/libgdruntime_convenience_la-msvc.lo
-@DRUNTIME_CPU_AARCH64_TRUE@am__objects_38 = config/aarch64/libgdruntime_convenience_la-switchcontext.lo
-@DRUNTIME_CPU_ARM_TRUE@am__objects_39 = config/arm/libgdruntime_convenience_la-switchcontext.lo
-@DRUNTIME_CPU_MIPS_TRUE@am__objects_40 = config/mips/libgdruntime_convenience_la-switchcontext.lo
-@DRUNTIME_CPU_POWERPC_TRUE@am__objects_41 = config/powerpc/libgdruntime_convenience_la-switchcontext.lo
-@DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_TRUE@am__objects_42 = config/mingw/libgdruntime_convenience_la-switchcontext.lo
-@DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_FALSE@am__objects_43 = config/x86/libgdruntime_convenience_la-switchcontext.lo
-@DRUNTIME_CPU_SYSTEMZ_TRUE@am__objects_44 = config/systemz/libgdruntime_convenience_la-get_tls_offset.lo
-@DRUNTIME_CPU_S390_TRUE@am__objects_45 = config/s390/libgdruntime_convenience_la-get_tls_offset.lo
-am__objects_46 = $(am__objects_6) $(am__objects_8) $(am__objects_10) \
+@DRUNTIME_CPU_AARCH64_TRUE@am__objects_39 = config/aarch64/libgdruntime_convenience_la-switchcontext.lo
+@DRUNTIME_CPU_ARM_TRUE@am__objects_40 = config/arm/libgdruntime_convenience_la-switchcontext.lo
+@DRUNTIME_CPU_LOONGARCH_TRUE@am__objects_41 = config/loongarch/libgdruntime_convenience_la-switchcontext.lo
+@DRUNTIME_CPU_MIPS_TRUE@am__objects_42 = config/mips/libgdruntime_convenience_la-switchcontext.lo
+@DRUNTIME_CPU_POWERPC_TRUE@am__objects_43 = config/powerpc/libgdruntime_convenience_la-switchcontext.lo
+@DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_TRUE@am__objects_44 = config/mingw/libgdruntime_convenience_la-switchcontext.lo
+@DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_FALSE@am__objects_45 = config/x86/libgdruntime_convenience_la-switchcontext.lo
+@DRUNTIME_CPU_SYSTEMZ_TRUE@am__objects_46 = config/systemz/libgdruntime_convenience_la-get_tls_offset.lo
+@DRUNTIME_CPU_S390_TRUE@am__objects_47 = config/s390/libgdruntime_convenience_la-get_tls_offset.lo
+am__objects_48 = $(am__objects_6) $(am__objects_8) $(am__objects_10) \
 	$(am__objects_12) $(am__objects_14) $(am__objects_16) \
-	$(am__objects_18) $(am__objects_20) $(am__objects_37) \
-	$(am__objects_24) $(am__objects_38) $(am__objects_39) \
-	$(am__objects_40) $(am__objects_41) $(am__objects_42) \
-	$(am__objects_43) $(am__objects_44) $(am__objects_45)
-am__objects_47 = $(am__objects_1) $(am__objects_36) $(am__objects_3) \
-	$(am__objects_4) $(am__objects_46) $(am__objects_34)
-am__objects_48 = $(am__objects_47)
-am_libgdruntime_convenience_la_OBJECTS = $(am__objects_48)
+	$(am__objects_18) $(am__objects_20) $(am__objects_38) \
+	$(am__objects_24) $(am__objects_39) $(am__objects_40) \
+	$(am__objects_41) $(am__objects_42) $(am__objects_43) \
+	$(am__objects_44) $(am__objects_45) $(am__objects_46) \
+	$(am__objects_47)
+am__objects_49 = $(am__objects_1) $(am__objects_37) $(am__objects_3) \
+	$(am__objects_4) $(am__objects_48) $(am__objects_35)
+am__objects_50 = $(am__objects_49)
+am_libgdruntime_convenience_la_OBJECTS = $(am__objects_50)
 libgdruntime_convenience_la_OBJECTS =  \
 	$(am_libgdruntime_convenience_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
@@ -799,7 +804,7 @@ DRUNTIME_SOURCES_CONFIGURED = $(am__append_1) $(am__append_2) \
 	$(am__append_9) $(am__append_10) $(am__append_11) \
 	$(am__append_12) $(am__append_13) $(am__append_14) \
 	$(am__append_15) $(am__append_16) $(am__append_17) \
-	$(am__append_18)
+	$(am__append_18) $(am__append_19)
 
 # Provide __start_minfo, __stop_minfo if linker doesn't.
 @DRUNTIME_OS_MINFO_BRACKETING_FALSE@DRTSTUFF = gcc/drtbegin.o gcc/drtend.o
@@ -1953,6 +1958,11 @@ config/arm/$(am__dirstamp):
 	@: > config/arm/$(am__dirstamp)
 config/arm/libgdruntime_la-switchcontext.lo:  \
 	config/arm/$(am__dirstamp)
+config/loongarch/$(am__dirstamp):
+	@$(MKDIR_P) config/loongarch
+	@: > config/loongarch/$(am__dirstamp)
+config/loongarch/libgdruntime_la-switchcontext.lo:  \
+	config/loongarch/$(am__dirstamp)
 config/mips/$(am__dirstamp):
 	@$(MKDIR_P) config/mips
 	@: > config/mips/$(am__dirstamp)
@@ -1995,6 +2005,8 @@ config/aarch64/libgdruntime_convenience_la-switchcontext.lo:  \
 	config/aarch64/$(am__dirstamp)
 config/arm/libgdruntime_convenience_la-switchcontext.lo:  \
 	config/arm/$(am__dirstamp)
+config/loongarch/libgdruntime_convenience_la-switchcontext.lo:  \
+	config/loongarch/$(am__dirstamp)
 config/mips/libgdruntime_convenience_la-switchcontext.lo:  \
 	config/mips/$(am__dirstamp)
 config/powerpc/libgdruntime_convenience_la-switchcontext.lo:  \
@@ -2017,6 +2029,8 @@ mostlyclean-compile:
 	-rm -f config/aarch64/*.lo
 	-rm -f config/arm/*.$(OBJEXT)
 	-rm -f config/arm/*.lo
+	-rm -f config/loongarch/*.$(OBJEXT)
+	-rm -f config/loongarch/*.lo
 	-rm -f config/mingw/*.$(OBJEXT)
 	-rm -f config/mingw/*.lo
 	-rm -f config/mips/*.$(OBJEXT)
@@ -2150,6 +2164,9 @@ config/aarch64/libgdruntime_la-switchcontext.lo: config/aarch64/switchcontext.S
 config/arm/libgdruntime_la-switchcontext.lo: config/arm/switchcontext.S
 	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/arm/libgdruntime_la-switchcontext.lo `test -f 'config/arm/switchcontext.S' || echo '$(srcdir)/'`config/arm/switchcontext.S
 
+config/loongarch/libgdruntime_la-switchcontext.lo: config/loongarch/switchcontext.S
+	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/loongarch/libgdruntime_la-switchcontext.lo `test -f 'config/loongarch/switchcontext.S' || echo '$(srcdir)/'`config/loongarch/switchcontext.S
+
 config/mips/libgdruntime_la-switchcontext.lo: config/mips/switchcontext.S
 	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/mips/libgdruntime_la-switchcontext.lo `test -f 'config/mips/switchcontext.S' || echo '$(srcdir)/'`config/mips/switchcontext.S
 
@@ -2174,6 +2191,9 @@ config/aarch64/libgdruntime_convenience_la-switchcontext.lo: config/aarch64/swit
 config/arm/libgdruntime_convenience_la-switchcontext.lo: config/arm/switchcontext.S
 	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_convenience_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/arm/libgdruntime_convenience_la-switchcontext.lo `test -f 'config/arm/switchcontext.S' || echo '$(srcdir)/'`config/arm/switchcontext.S
 
+config/loongarch/libgdruntime_convenience_la-switchcontext.lo: config/loongarch/switchcontext.S
+	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_convenience_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/loongarch/libgdruntime_convenience_la-switchcontext.lo `test -f 'config/loongarch/switchcontext.S' || echo '$(srcdir)/'`config/loongarch/switchcontext.S
+
 config/mips/libgdruntime_convenience_la-switchcontext.lo: config/mips/switchcontext.S
 	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_convenience_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/mips/libgdruntime_convenience_la-switchcontext.lo `test -f 'config/mips/switchcontext.S' || echo '$(srcdir)/'`config/mips/switchcontext.S
 
@@ -2226,6 +2246,7 @@ clean-libtool:
 	-rm -rf .libs _libs
 	-rm -rf config/aarch64/.libs config/aarch64/_libs
 	-rm -rf config/arm/.libs config/arm/_libs
+	-rm -rf config/loongarch/.libs config/loongarch/_libs
 	-rm -rf config/mingw/.libs config/mingw/_libs
 	-rm -rf config/mips/.libs config/mips/_libs
 	-rm -rf config/powerpc/.libs config/powerpc/_libs
@@ -2391,6 +2412,7 @@ distclean-generic:
 	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
 	-rm -f config/aarch64/$(am__dirstamp)
 	-rm -f config/arm/$(am__dirstamp)
+	-rm -f config/loongarch/$(am__dirstamp)
 	-rm -f config/mingw/$(am__dirstamp)
 	-rm -f config/mips/$(am__dirstamp)
 	-rm -f config/powerpc/$(am__dirstamp)
diff --git a/libphobos/m4/druntime/cpu.m4 b/libphobos/m4/druntime/cpu.m4
index db3a92c15fa..3461b2d3c51 100644
--- a/libphobos/m4/druntime/cpu.m4
+++ b/libphobos/m4/druntime/cpu.m4
@@ -15,6 +15,9 @@ AC_DEFUN([DRUNTIME_CPU_SOURCES],
                ;;
       arm*)    druntime_target_cpu_parsed="arm"
                ;;
+      loongarch*)
+               druntime_target_cpu_parsed="loongarch"
+               ;;
       mips*)   druntime_target_cpu_parsed="mips"
                ;;
       powerpc*)
@@ -34,6 +37,8 @@ AC_DEFUN([DRUNTIME_CPU_SOURCES],
                  [test "$druntime_target_cpu_parsed" = "aarch64"])
   AM_CONDITIONAL([DRUNTIME_CPU_ARM],
                  [test "$druntime_target_cpu_parsed" = "arm"])
+  AM_CONDITIONAL([DRUNTIME_CPU_LOONGARCH],
+                 [test "$druntime_target_cpu_parsed" = "loongarch"])
   AM_CONDITIONAL([DRUNTIME_CPU_MIPS],
                  [test "$druntime_target_cpu_parsed" = "mips"])
   AM_CONDITIONAL([DRUNTIME_CPU_POWERPC],
-- 
2.42.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] libphobos: Adjust LoongArch definitons.
  2023-11-17 10:00 [PATCH 0/3] LoongArch GDC support Yang Yujie
  2023-11-17 10:00 ` [PATCH 1/3] LoongArch: Adjust D version strings Yang Yujie
  2023-11-17 10:00 ` [PATCH 2/3] libphobos: Update build scripts for LoongArch64 Yang Yujie
@ 2023-11-17 10:00 ` Yang Yujie
  2 siblings, 0 replies; 4+ messages in thread
From: Yang Yujie @ 2023-11-17 10:00 UTC (permalink / raw)
  To: gcc-patches; +Cc: ibuclaw, chenglulu, xuchenghua, Yang Yujie

Upstream commits:
https://github.com/dlang/phobos/commit/870eb5d5d6972b12dd4b69d48ef049abee811b6b
https://github.com/dlang/dmd/commit/9cb5517290fac5d28f52c11c254115c0f1086b69

libphobos/ChangeLog:

	* libdruntime/core/stdc/fenv.d: Fix LongArch FP rounding mode constants.
	* libdruntime/core/vararg.d: Add LoongArch64 support.
	* libdruntime/core/stdc/stdarg.d: Same.
	* libdruntime/core/sys/linux/sys/auxv.d: Same.
	* libdruntime/core/sys/elf/package.d: Define EM_LOONGARCH (258).
	* libdruntime/core/sys/linux/sys/mman.d: Reference corresponding
	glibc header in comment.
	* libdruntime/core/thread/fiber.d: Save $r21 in fiber contexts.
	* src/std/math/hardware.d: Implement FP control.
	* libdruntime/config/loongarch/switchcontext.S: New file.
---
 .../config/loongarch/switchcontext.S          | 133 ++++++++++++++++++
 libphobos/libdruntime/core/stdc/fenv.d        |   8 +-
 libphobos/libdruntime/core/stdc/stdarg.d      |   6 +
 libphobos/libdruntime/core/sys/elf/package.d  |   2 +
 .../libdruntime/core/sys/linux/sys/auxv.d     |  17 +++
 .../libdruntime/core/sys/linux/sys/mman.d     |   1 +
 libphobos/libdruntime/core/thread/fiber.d     |  55 +++++---
 libphobos/libdruntime/core/vararg.d           |   7 +
 libphobos/src/std/math/hardware.d             |  77 ++++++++++
 9 files changed, 279 insertions(+), 27 deletions(-)
 create mode 100644 libphobos/libdruntime/config/loongarch/switchcontext.S

diff --git a/libphobos/libdruntime/config/loongarch/switchcontext.S b/libphobos/libdruntime/config/loongarch/switchcontext.S
new file mode 100644
index 00000000000..edfb9b67e8f
--- /dev/null
+++ b/libphobos/libdruntime/config/loongarch/switchcontext.S
@@ -0,0 +1,133 @@
+/* LoongArch support code for fibers and multithreading.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+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.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "../common/threadasm.S"
+
+/**
+ * Performs a context switch.
+ *
+ * $a0 - void** - ptr to old stack pointer
+ * $a1 - void*  - new stack pointer
+ *
+ */
+
+#if defined(__loongarch_lp64)
+#  define GPR_L ld.d
+#  define GPR_S st.d
+#  define SZ_GPR 8
+#  define ADDSP(si)   addi.d  $sp, $sp, si
+#elif defined(__loongarch64_ilp32)
+#  define GPR_L ld.w
+#  define GPR_S st.w
+#  define SZ_GPR 4
+#  define ADDSP(si)   addi.w  $sp, $sp, si
+#else
+#  error Unsupported GPR size (must be 64-bit or 32-bit).
+#endif
+
+#if defined(__loongarch_double_float)
+#  define FPR_L fld.d
+#  define FPR_S fst.d
+#  define SZ_FPR 8
+#elif defined(__loongarch_single_float)
+#  define FPR_L fld.s
+#  define FPR_S fst.s
+#  define SZ_FPR 4
+#else
+#  define SZ_FPR 0
+#endif
+
+    .text
+    .align 2
+    .global fiber_switchContext
+    .type   fiber_switchContext, @function
+fiber_switchContext:
+    .cfi_startproc
+    ADDSP(-11 * SZ_GPR)
+
+    // fp regs and return address are stored below the stack
+    // because we don't want the GC to scan them.
+
+    // return address (r1)
+    GPR_S  $r1, $sp, -SZ_GPR
+
+#if SZ_FPR != 0
+    // callee-saved scratch FPRs (f24-f31)
+    FPR_S  $f24, $sp, -SZ_GPR-1*SZ_FPR
+    FPR_S  $f25, $sp, -SZ_GPR-2*SZ_FPR
+    FPR_S  $f26, $sp, -SZ_GPR-3*SZ_FPR
+    FPR_S  $f27, $sp, -SZ_GPR-4*SZ_FPR
+    FPR_S  $f28, $sp, -SZ_GPR-5*SZ_FPR
+    FPR_S  $f29, $sp, -SZ_GPR-6*SZ_FPR
+    FPR_S  $f30, $sp, -SZ_GPR-7*SZ_FPR
+    FPR_S  $f31, $sp, -SZ_GPR-8*SZ_FPR
+#endif
+
+    // callee-saved GPRs (r21, fp (r22), r23-r31)
+    GPR_S $r21, $sp, 0*SZ_GPR
+    GPR_S  $fp, $sp, 1*SZ_GPR
+    GPR_S  $s0, $sp, 2*SZ_GPR
+    GPR_S  $s1, $sp, 3*SZ_GPR
+    GPR_S  $s2, $sp, 4*SZ_GPR
+    GPR_S  $s3, $sp, 5*SZ_GPR
+    GPR_S  $s4, $sp, 6*SZ_GPR
+    GPR_S  $s5, $sp, 7*SZ_GPR
+    GPR_S  $s6, $sp, 8*SZ_GPR
+    GPR_S  $s7, $sp, 9*SZ_GPR
+    GPR_S  $s8, $sp, 10*SZ_GPR
+
+    // swap stack pointer
+    GPR_S $sp, $a0, 0
+    move $sp, $a1
+
+    GPR_L  $r1, $sp, -SZ_GPR
+
+#if SZ_FPR != 0
+    FPR_L  $f24, $sp, -SZ_GPR-1*SZ_FPR
+    FPR_L  $f25, $sp, -SZ_GPR-2*SZ_FPR
+    FPR_L  $f26, $sp, -SZ_GPR-3*SZ_FPR
+    FPR_L  $f27, $sp, -SZ_GPR-4*SZ_FPR
+    FPR_L  $f28, $sp, -SZ_GPR-5*SZ_FPR
+    FPR_L  $f29, $sp, -SZ_GPR-6*SZ_FPR
+    FPR_L  $f30, $sp, -SZ_GPR-7*SZ_FPR
+    FPR_L  $f31, $sp, -SZ_GPR-8*SZ_FPR
+#endif
+
+    GPR_L $r21, $sp, 0*SZ_GPR
+    GPR_L  $fp, $sp, 1*SZ_GPR
+    GPR_L  $s0, $sp, 2*SZ_GPR
+    GPR_L  $s1, $sp, 3*SZ_GPR
+    GPR_L  $s2, $sp, 4*SZ_GPR
+    GPR_L  $s3, $sp, 5*SZ_GPR
+    GPR_L  $s4, $sp, 6*SZ_GPR
+    GPR_L  $s5, $sp, 7*SZ_GPR
+    GPR_L  $s6, $sp, 8*SZ_GPR
+    GPR_L  $s7, $sp, 9*SZ_GPR
+    GPR_L  $s8, $sp, 10*SZ_GPR
+
+    ADDSP(11 * SZ_GPR)
+
+    jr     $r1 // return
+    .cfi_endproc
+    .size fiber_switchContext,.-fiber_switchContext
diff --git a/libphobos/libdruntime/core/stdc/fenv.d b/libphobos/libdruntime/core/stdc/fenv.d
index 288f9c25dc6..0051ecdb7c9 100644
--- a/libphobos/libdruntime/core/stdc/fenv.d
+++ b/libphobos/libdruntime/core/stdc/fenv.d
@@ -797,7 +797,7 @@ else
     }
     else version (LoongArch64)
     {
-        // Define bits representing exceptions in the FPSR status word.
+        // Define bits representing exceptions in the Flags field in FCSR{0,2}.
         enum
         {
             FE_INEXACT      = 0x010000, ///
@@ -808,13 +808,13 @@ else
             FE_ALL_EXCEPT   = 0x1f0000, ///
         }
 
-        // Define bits representing rounding modes in the FPCR Rmode field.
+        // Define bits representing rounding modes in the RM field in FCSR{0,3}.
         enum
         {
             FE_TONEAREST    = 0x000, ///
             FE_TOWARDZERO   = 0x100, ///
-            FE_DOWNWARD     = 0x200, ///
-            FE_UPWARD       = 0x300, ///
+            FE_UPWARD       = 0x200, ///
+            FE_DOWNWARD     = 0x300, ///
         }
     }
     else
diff --git a/libphobos/libdruntime/core/stdc/stdarg.d b/libphobos/libdruntime/core/stdc/stdarg.d
index 5b79813ae1b..0ba1ebe34e3 100644
--- a/libphobos/libdruntime/core/stdc/stdarg.d
+++ b/libphobos/libdruntime/core/stdc/stdarg.d
@@ -257,6 +257,12 @@ T va_arg(T)(ref va_list ap)
         ap += T.sizeof.alignUp;
         return *p;
     }
+    else version (LoongArch64)
+    {
+        auto p = cast(T*) ap;
+        ap += T.sizeof.alignUp;
+        return *p;
+    }
     else version (MIPS_Any)
     {
         auto p = cast(T*) ap;
diff --git a/libphobos/libdruntime/core/sys/elf/package.d b/libphobos/libdruntime/core/sys/elf/package.d
index b120ee58f69..60e05d97036 100644
--- a/libphobos/libdruntime/core/sys/elf/package.d
+++ b/libphobos/libdruntime/core/sys/elf/package.d
@@ -339,6 +339,8 @@ enum EM_CSKY =        252;
 
 enum EM_NUM =         253;
 
+enum EM_LOONGARCH =   258;
+
 enum EM_ALPHA =        0x9026;
 
 enum EV_NONE =         0;
diff --git a/libphobos/libdruntime/core/sys/linux/sys/auxv.d b/libphobos/libdruntime/core/sys/linux/sys/auxv.d
index 5f098e98e02..1099fae497f 100644
--- a/libphobos/libdruntime/core/sys/linux/sys/auxv.d
+++ b/libphobos/libdruntime/core/sys/linux/sys/auxv.d
@@ -13,6 +13,7 @@ extern (C):
 
 version (MIPS32)  version = MIPS_Any;
 version (MIPS64)  version = MIPS_Any;
+version (LoongArch64) version = LoongArch_Any;
 version (PPC)     version = PPC_Any;
 version (PPC64)   version = PPC_Any;
 version (S390)    version = IBMZ_Any;
@@ -156,3 +157,19 @@ else version (IBMZ_Any)
   enum HWCAP_S390_TE                      = 1024;
   enum HWCAP_S390_VX                      = 2048;
 }
+else version (LoongArch_Any)
+{
+  enum HWCAP_LOONGARCH_CPUCFG             = 0x00000001;
+  enum HWCAP_LOONGARCH_LAM                = 0x00000002;
+  enum HWCAP_LOONGARCH_UAL                = 0x00000004;
+  enum HWCAP_LOONGARCH_FPU                = 0x00000008;
+  enum HWCAP_LOONGARCH_LSX                = 0x00000010;
+  enum HWCAP_LOONGARCH_LASX               = 0x00000020;
+  enum HWCAP_LOONGARCH_CRC32              = 0x00000040;
+  enum HWCAP_LOONGARCH_COMPLEX            = 0x00000080;
+  enum HWCAP_LOONGARCH_CRYPTO             = 0x00000100;
+  enum HWCAP_LOONGARCH_LVZ                = 0x00000200;
+  enum HWCAP_LOONGARCH_LBT_X86            = 0x00000400;
+  enum HWCAP_LOONGARCH_LBT_ARM            = 0x00000800;
+  enum HWCAP_LOONGARCH_LBT_MIPS           = 0x00001000;
+}
diff --git a/libphobos/libdruntime/core/sys/linux/sys/mman.d b/libphobos/libdruntime/core/sys/linux/sys/mman.d
index 7ed78ef6436..e4765af1490 100644
--- a/libphobos/libdruntime/core/sys/linux/sys/mman.d
+++ b/libphobos/libdruntime/core/sys/linux/sys/mman.d
@@ -432,6 +432,7 @@ else version (MIPS_Any)
         MAP_HUGETLB = 0x80000,
     }
 }
+// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/bits/mman-map-flags-generic.h
 else version (LoongArch64)
 {
     static if (_DEFAULT_SOURCE) enum
diff --git a/libphobos/libdruntime/core/thread/fiber.d b/libphobos/libdruntime/core/thread/fiber.d
index 65878bc1c66..e0838bcffef 100644
--- a/libphobos/libdruntime/core/thread/fiber.d
+++ b/libphobos/libdruntime/core/thread/fiber.d
@@ -178,8 +178,12 @@ private
     }
     else version (LoongArch64)
     {
-        version = AsmLoongArch64_Posix;
-        version = AsmExternal;
+        version (Posix)
+        {
+            version = AsmLoongArch64_Posix;
+            version = AsmExternal;
+            version = AlignFiberStackTo16Byte;
+        }
     }
 
     version (Posix)
@@ -1442,27 +1446,6 @@ private:
             pstack -= ABOVE;
             *cast(size_t*)(pstack - SZ_RA) = cast(size_t)&fiber_entryPoint;
         }
-        else version (AsmLoongArch64_Posix)
-        {
-            version (StackGrowsDown) {}
-            else static assert(0);
-
-            // Like others, FP registers and return address (ra) are kept
-            // below the saved stack top (tstack) to hide from GC scanning.
-            // The newp stack should look like this on LoongArch64:
-            // 18: fp     <- pstack
-            // ...
-            //  9: s0     <- newp tstack
-            //  8: ra     [&fiber_entryPoint]
-            //  7: fs7
-            // ...
-            //  1: fs1
-            //  0: fs0
-            pstack -= 10 * size_t.sizeof; // skip s0-s8 and fp
-            // set $ra
-            push( cast(size_t) &fiber_entryPoint );
-            pstack += size_t.sizeof;
-        }
         else version (AsmAArch64_Posix)
         {
             // Like others, FP registers and return address (lr) are kept
@@ -1558,6 +1541,32 @@ private:
                 push( cast(size_t) m_ctxt.bstack + m_size );        // GS:[16] - Bottom of stack
             }
         }
+        else version (AsmLoongArch64_Posix)
+        {
+            // Like others, FP registers and return address ($r1) are kept
+            // below the saved stack top (tstack) to hide from GC scanning.
+            // fiber_switchContext expects newp sp to look like this:
+            //   10: $r21 (reserved)
+            //    9: $r22 (frame pointer)
+            //    8: $r23
+            //   ...
+            //    0: $r31 <-- newp tstack
+            //   -1: $r1  (return address)  [&fiber_entryPoint]
+            //   -2: $f24
+            //   ...
+            //   -9: $f31
+
+            version (StackGrowsDown) {}
+            else
+                static assert(false, "Only full descending stacks supported on LoongArch64");
+
+            // Only need to set return address ($r1).  Everything else is fine
+            // zero initialized.
+            pstack -= size_t.sizeof * 11;    // skip past space reserved for $r21-$r31
+            push (cast(size_t) &fiber_entryPoint);
+            pstack += size_t.sizeof;         // adjust sp (newp) above lr
+        }
+
         else static if ( __traits( compiles, ucontext_t ) )
         {
             getcontext( &m_utxt );
diff --git a/libphobos/libdruntime/core/vararg.d b/libphobos/libdruntime/core/vararg.d
index 2c3e9659fb6..e6dd47d06d3 100644
--- a/libphobos/libdruntime/core/vararg.d
+++ b/libphobos/libdruntime/core/vararg.d
@@ -129,6 +129,13 @@ void va_arg()(ref va_list ap, TypeInfo ti, void* parmn)
         ap += tsize.alignUp;
         parmn[0..tsize] = p[0..tsize];
     }
+    else version (LoongArch64)
+    {
+        const tsize = ti.tsize;
+        auto p = cast(void*) ap;
+        ap += tsize.alignUp;
+        parmn[0..tsize] = p[0..tsize];
+    }
     else version (MIPS_Any)
     {
         const tsize = ti.tsize;
diff --git a/libphobos/src/std/math/hardware.d b/libphobos/src/std/math/hardware.d
index 81c7302b4c1..e2ca3dbe064 100644
--- a/libphobos/src/std/math/hardware.d
+++ b/libphobos/src/std/math/hardware.d
@@ -33,6 +33,7 @@ version (SPARC64)   version = SPARC_Any;
 version (SystemZ)   version = IBMZ_Any;
 version (RISCV32)   version = RISCV_Any;
 version (RISCV64)   version = RISCV_Any;
+version (LoongArch64)   version = LoongArch_Any;
 
 version (D_InlineAsm_X86)    version = InlineAsm_X86_Any;
 version (D_InlineAsm_X86_64) version = InlineAsm_X86_Any;
@@ -60,6 +61,7 @@ else version (X86_Any)   version = IeeeFlagsSupport;
 else version (PPC_Any)   version = IeeeFlagsSupport;
 else version (RISCV_Any) version = IeeeFlagsSupport;
 else version (MIPS_Any)  version = IeeeFlagsSupport;
+else version (LoongArch_Any) version = IeeeFlagsSupport;
 else version (ARM_Any)   version = IeeeFlagsSupport;
 
 // Struct FloatingPointControl is only available if hardware FP units are available.
@@ -90,6 +92,7 @@ private:
     // The ARM and PowerPC FPSCR is a 32-bit register.
     // The SPARC FSR is a 32bit register (64 bits for SPARC 7 & 8, but high bits are uninteresting).
     // The RISC-V (32 & 64 bit) fcsr is 32-bit register.
+    // THe LoongArch fcsr (fcsr0) is a 32-bit register.
     uint flags;
 
     version (CRuntime_Microsoft)
@@ -174,6 +177,20 @@ private:
                     return result;
                 }
             }
+            else version (LoongArch_Any)
+            {
+                version (D_SoftFloat)
+                    return 0;
+                else
+                {
+                    uint result = void;
+                    asm pure nothrow @nogc
+                    {
+                        "movfcsr2gr %0,$r2" : "=r" (result);
+                    }
+                    return result & EXCEPTIONS_MASK;
+                }
+            }
             else
                 assert(0, "Not yet supported");
         }
@@ -273,6 +290,18 @@ private:
                     }
                 }
             }
+            else version (LoongArch_Any)
+            {
+                version (D_SoftFloat)
+                    return;
+                else
+                {
+                    asm nothrow @nogc
+                    {
+                        "movgr2fcsr $r2,$r0";
+                    }
+                }
+            }
             else
                 assert(0, "Not yet supported");
         }
@@ -725,6 +754,21 @@ nothrow @nogc:
                                  | inexactException,
         }
     }
+    else version (LoongArch_Any)
+    {
+        enum : ExceptionMask
+        {
+            inexactException      = 0x00,
+            divByZeroException    = 0x01,
+            overflowException     = 0x02,
+            underflowException    = 0x04,
+            invalidException      = 0x08,
+            severeExceptions   = overflowException | divByZeroException
+                                 | invalidException,
+            allExceptions      = severeExceptions | underflowException
+                                 | inexactException,
+        }
+    }
     else version (MIPS_Any)
     {
         enum : ExceptionMask
@@ -812,6 +856,8 @@ nothrow @nogc:
             return true;
         else version (MIPS_Any)
             return true;
+        else version (LoongArch_Any)
+            return true;
         else version (ARM_Any)
         {
             // The hasExceptionTraps_impl function is basically pure,
@@ -885,6 +931,10 @@ private:
     {
         alias ControlState = uint;
     }
+    else version (LoongArch_Any)
+    {
+        alias ControlState = uint;
+    }
     else version (MIPS_Any)
     {
         alias ControlState = uint;
@@ -959,6 +1009,20 @@ private:
                 }
                 return cont;
             }
+            else version (LoongArch_Any)
+            {
+                version (D_SoftFloat)
+                    return 0;
+                else
+                {
+                    ControlState cont;
+                    asm pure nothrow @nogc
+                    {
+                        "movfcsr2gr %0,$r0" : "=r" (cont);
+                    }
+                    cont &= (roundingMask | allExceptions);
+                }
+            }
             else version (RISCV_Any)
             {
                 version (D_SoftFloat)
@@ -1068,6 +1132,19 @@ private:
                     }
                 }
             }
+            else version (LoongArch_Any)
+            {
+                version (D_SoftFloat)
+                    return;
+                else
+                {
+                    asm nothrow @nogc
+                    {
+                        "movgr2fcsr $r0,%0" :
+                        : "r" (newState & (roundingMask | allExceptions));
+                    }
+                }
+            }
             else version (RISCV_Any)
             {
                 version (D_SoftFloat)
-- 
2.42.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-17 10:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17 10:00 [PATCH 0/3] LoongArch GDC support Yang Yujie
2023-11-17 10:00 ` [PATCH 1/3] LoongArch: Adjust D version strings Yang Yujie
2023-11-17 10:00 ` [PATCH 2/3] libphobos: Update build scripts for LoongArch64 Yang Yujie
2023-11-17 10:00 ` [PATCH 3/3] libphobos: Adjust LoongArch definitons Yang Yujie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).