From: Bobby Bingham <koorogi@koorogi.info>
To: musl@lists.openwall.com
Subject: [PATCH] ppc: simplify __clone by saving fn/arg to child stack
Date: Sat, 30 Apr 2016 16:39:25 -0500 [thread overview]
Message-ID: <1462052365-4747-1-git-send-email-koorogi@koorogi.info> (raw)
Previously, the parent spilled r30-r31 to its stack so that
the fn/arg could be stored in those registers, where they
would be available to the child process.
If instead, we save fn/arg to the child stack, we can avoid
spilling/restoring any registers in the parent.
---
src/thread/powerpc/clone.s | 34 ++++++++++------------------------
1 file changed, 10 insertions(+), 24 deletions(-)
diff --git a/src/thread/powerpc/clone.s b/src/thread/powerpc/clone.s
index a57dbcc..92ebe76 100644
--- a/src/thread/powerpc/clone.s
+++ b/src/thread/powerpc/clone.s
@@ -13,20 +13,15 @@ __clone:
# SYS_clone = 120
# SYS_exit = 1
-# store non-volatile regs r30, r31 on stack in order to put our
-# start func and its arg there
-stwu 30, -16(1)
-stw 31, 4(1)
-
-# save r3 (func) into r30, and r6(arg) into r31
-mr 30, 3
-mr 31, 6
-
# create initial stack frame for new thread
clrrwi 4, 4, 4
li 0, 0
stwu 0, -16(4)
+# save fn and arg to child stack
+stw 3, 4(4)
+stw 6, 8(4)
+
#move c into first arg
mr 3, 5
#mr 4, 4
@@ -47,26 +42,17 @@ neg 3, 3 #negate the result (errno)
# compare sc result with 0
cmpwi cr7, 3, 0
-# if not 0, jump to end
-bne cr7, 2f
+# if not 0, return
+bnelr cr7
#else: we're the child
#call funcptr: move arg (d) into r3
-mr 3, 31
-#move r30 (funcptr) into CTR reg
-mtctr 30
+lwz 3, 8(1)
+#load funcptr (a) into CTR
+lwz 0, 4(1)
+mtctr 0
# call CTR reg
bctrl
# mov SYS_exit into r0 (the exit param is already in r3)
li 0, 1
sc
-
-2:
-
-# restore stack
-lwz 30, 0(1)
-lwz 31, 4(1)
-addi 1, 1, 16
-
-blr
-
--
2.8.1
reply other threads:[~2016-04-30 21:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1462052365-4747-1-git-send-email-koorogi@koorogi.info \
--to=koorogi@koorogi.info \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).