diff mbox series

libphobos: Fix build fails for powerpc-linux

Message ID 20210420233506.1152892-1-ibuclaw@gdcproject.org
State New
Headers show
Series libphobos: Fix build fails for powerpc-linux | expand

Commit Message

Iain Buclaw April 20, 2021, 11:35 p.m. UTC
Hi,

This patch addresses the raised issue in the RC thread (haven't seen a
bugzilla PR for it?)

As register names are required for darwin, but not accepted by gas
unless you use `-mregnames', they have been conditionally removed on
non-darwin targets.

To avoid duplicating large blocks of almost identical code, the inline
assembly is now statically generated.

I've tested this on powerpc64le-linux-gnu.  The build succeeds, and both
gdc and libphobos testsuite looks fine.

OK for others if I commit this to mainline and releases/gcc-11?

Regards,
Iain.

---
libphobos/ChangeLog:

	* libdruntime/core/thread/osthread.d (callWithStackShell): Statically
	generate PPC and PPC64 asm implementations, and conditionally remove
	PPC register names on non-Darwin targets.
---
 libphobos/libdruntime/core/thread/osthread.d | 68 +++++++-------------
 1 file changed, 24 insertions(+), 44 deletions(-)

Comments

Iain Buclaw April 21, 2021, 12:44 a.m. UTC | #1
Excerpts from Iain Buclaw's message of April 21, 2021 1:35 am:
> Hi,
> 
> This patch addresses the raised issue in the RC thread (haven't seen a
> bugzilla PR for it?)
> 
> As register names are required for darwin, but not accepted by gas
> unless you use `-mregnames', they have been conditionally removed on
> non-darwin targets.
> 
> To avoid duplicating large blocks of almost identical code, the inline
> assembly is now statically generated.
> 
> I've tested this on powerpc64le-linux-gnu.  The build succeeds, and both
> gdc and libphobos testsuite looks fine.
> 
> OK for others if I commit this to mainline and releases/gcc-11?
> 

I've seen a couple of affirmations off the list, so have gone ahead and
committed it.

Iain.
diff mbox series

Patch

diff --git a/libphobos/libdruntime/core/thread/osthread.d b/libphobos/libdruntime/core/thread/osthread.d
index 31764e69691..9fcd30e50fb 100644
--- a/libphobos/libdruntime/core/thread/osthread.d
+++ b/libphobos/libdruntime/core/thread/osthread.d
@@ -1444,55 +1444,35 @@  in (fn)
         else version (PPC)
         {
             void*[19] regs = void;
-            asm pure nothrow @nogc
-            {
-                "stw r13, %0" : "=m" (regs[ 0]);
-                "stw r14, %0" : "=m" (regs[ 1]);
-                "stw r15, %0" : "=m" (regs[ 2]);
-                "stw r16, %0" : "=m" (regs[ 3]);
-                "stw r17, %0" : "=m" (regs[ 4]);
-                "stw r18, %0" : "=m" (regs[ 5]);
-                "stw r19, %0" : "=m" (regs[ 6]);
-                "stw r20, %0" : "=m" (regs[ 7]);
-                "stw r21, %0" : "=m" (regs[ 9]);
-                "stw r22, %0" : "=m" (regs[ 9]);
-                "stw r23, %0" : "=m" (regs[10]);
-                "stw r24, %0" : "=m" (regs[11]);
-                "stw r25, %0" : "=m" (regs[12]);
-                "stw r26, %0" : "=m" (regs[13]);
-                "stw r27, %0" : "=m" (regs[14]);
-                "stw r28, %0" : "=m" (regs[15]);
-                "stw r29, %0" : "=m" (regs[16]);
-                "stw r30, %0" : "=m" (regs[17]);
-                "stw r31, %0" : "=m" (regs[18]);
-            }
+            version (Darwin)
+                enum regname = "r";
+            else
+                enum regname = "";
+            static foreach (i; 0 .. regs.length)
+            {{
+                enum int j = 13 + i; // source register
+                asm pure nothrow @nogc
+                {
+                    "stw "~regname~j.stringof~", %0" : "=m" (regs[i]);
+                }
+            }}
             sp = cast(void*)&regs[0];
         }
         else version (PPC64)
         {
             void*[19] regs = void;
-            asm pure nothrow @nogc
-            {
-                "std r13, %0" : "=m" (regs[ 0]);
-                "std r14, %0" : "=m" (regs[ 1]);
-                "std r15, %0" : "=m" (regs[ 2]);
-                "std r16, %0" : "=m" (regs[ 3]);
-                "std r17, %0" : "=m" (regs[ 4]);
-                "std r18, %0" : "=m" (regs[ 5]);
-                "std r19, %0" : "=m" (regs[ 6]);
-                "std r20, %0" : "=m" (regs[ 7]);
-                "std r21, %0" : "=m" (regs[ 8]);
-                "std r22, %0" : "=m" (regs[ 9]);
-                "std r23, %0" : "=m" (regs[10]);
-                "std r24, %0" : "=m" (regs[11]);
-                "std r25, %0" : "=m" (regs[12]);
-                "std r26, %0" : "=m" (regs[13]);
-                "std r27, %0" : "=m" (regs[14]);
-                "std r28, %0" : "=m" (regs[15]);
-                "std r29, %0" : "=m" (regs[16]);
-                "std r30, %0" : "=m" (regs[17]);
-                "std r31, %0" : "=m" (regs[18]);
-            }
+            version (Darwin)
+                enum regname = "r";
+            else
+                enum regname = "";
+            static foreach (i; 0 .. regs.length)
+            {{
+                enum int j = 13 + i; // source register
+                asm pure nothrow @nogc
+                {
+                    "std "~regname~j.stringof~", %0" : "=m" (regs[i]);
+                }
+            }}
             sp = cast(void*)&regs[0];
         }
         else