From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9970 Path: news.gmane.org!not-for-mail From: Bobby Bingham Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] ppc: simplify __clone by saving fn/arg to child stack Date: Sat, 30 Apr 2016 16:39:25 -0500 Message-ID: <1462052365-4747-1-git-send-email-koorogi@koorogi.info> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1462052403 11525 80.91.229.3 (30 Apr 2016 21:40:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 30 Apr 2016 21:40:03 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-9983-gllmg-musl=m.gmane.org@lists.openwall.com Sat Apr 30 23:39:48 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1awcc7-00081y-Tx for gllmg-musl@m.gmane.org; Sat, 30 Apr 2016 23:39:48 +0200 Original-Received: (qmail 19830 invoked by uid 550); 30 Apr 2016 21:39:46 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 19796 invoked from network); 30 Apr 2016 21:39:42 -0000 X-Mailer: git-send-email 2.8.1 Xref: news.gmane.org gmane.linux.lib.musl.general:9970 Archived-At: 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