From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 2EBF21F880 for ; Thu, 9 Jan 2020 21:13:56 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:references:from:subject:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=RxvpF+td+kqxZlLl x1Q8gFg23UKgEJhQbvL2KanhLFEHPQWEkRJ5jwRizR5lypI47en7oUX8orOuVAJs LQbdbl5mzA/MkVoctgfviWc+lLJJY2f3bl+SqfXm8kKSeAOUx83YQ9LoeI6gBy5d 0m00VVcNeewdxWrhWbf+VnuB9qw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:references:from:subject:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=JSUFzEU1EDXFjMqkYHYbMG 8KkxM=; b=igvxski9MQHqTyQq9sG4kxmwnT84JSSoem7t7aKxpd+Qy4kK3ckqro rodI0vGdmxQ2yBtBM7Sv1rq08c3GiTBcJLSPyQHoCWp0iNWvBExqPfTUs0qUpX6f jm7jys63mvN/qvG7dj++DFsplKGavhKKO/1Ps9utWeOhQki6435OE= Received: (qmail 126264 invoked by alias); 9 Jan 2020 21:13:47 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 126133 invoked by uid 89); 9 Jan 2020 21:13:46 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: mail-qv1-f65.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=to:references:from:autocrypt:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=BCRCwJrugIWOWWIeqvLtAiBTw4wo1RCUVS7xc3N2ZLA=; b=wY1JYQaLNrq0ZE1k0TAqFU84phpgbVGYv8OtWsX6VXfMJJ18Wjh4MyyKBK/mBp0E6k BnkVKzzj+ybCJbLqpSu7lMI6dUbC+QtmxJlQCfYIQ5dIC+O3Oo1X/0jYQJOp8m4k/4QM iKQe8q51pugOUxBlttZzQpXYPAZhzY/BgQbf/qGyB4NbniQnW0wT7h6qD1Ea6jyzwfn6 6cXrth5MYvlKsmH/RXby0lexTuOUCXTosN6Mh5znX9pziIlqb0oKP/ZiRTUlPfzVCiSB PRJG0/gmDyLWfONOl+wmMVk8TtyikoyNBlYga7qjbiX4wjCBqWE60Jd8QBU6Y1tN3TTY WxFA== To: libc-alpha@sourceware.org References: <20200108161535.6141-1-hjl.tools@gmail.com> <20200108161535.6141-2-hjl.tools@gmail.com> From: Adhemerval Zanella Subject: Re: V2 [PATCH 1/5] i386: Don't unnecessarily save and restore EAX, ECX and EDX [BZ# 25262] Message-ID: <64be6c36-aea8-59a0-faab-32f76bf9cc20@linaro.org> Date: Thu, 9 Jan 2020 18:13:39 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20200108161535.6141-2-hjl.tools@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 08/01/2020 13:15, H.J. Lu wrote: > On i386, since EAX, ECX and EDX are caller-saved, there are no need > to save and restore EAX, ECX and EDX in getcontext, setcontext and > swapcontext. They just need to clear EAX on success. The extra > scratch registers are needed to enable CET. > > Tested on i386. LGTM thanks. You might also remove the oE{A,C,D}X definitions from Linux i386 ucontext_i.sym. As a side note, Hurd might do the same on its implementations. Reviewed-by: Adhemerval Zanella > --- > sysdeps/unix/sysv/linux/i386/getcontext.S | 8 +------- > sysdeps/unix/sysv/linux/i386/setcontext.S | 11 ++++------- > sysdeps/unix/sysv/linux/i386/swapcontext.S | 17 +++++------------ > 3 files changed, 10 insertions(+), 26 deletions(-) > > diff --git a/sysdeps/unix/sysv/linux/i386/getcontext.S b/sysdeps/unix/sysv/linux/i386/getcontext.S > index f86df4d555..9c1df9a2aa 100644 > --- a/sysdeps/unix/sysv/linux/i386/getcontext.S > +++ b/sysdeps/unix/sysv/linux/i386/getcontext.S > @@ -26,13 +26,7 @@ ENTRY(__getcontext) > /* Load address of the context data structure. */ > movl 4(%esp), %eax > > - /* Return value of getcontext. EAX is the only register whose > - value is not preserved. */ > - movl $0, oEAX(%eax) > - > - /* Save the 32-bit register values and the return address. */ > - movl %ecx, oECX(%eax) > - movl %edx, oEDX(%eax) > + /* Save the preserved register values and the return address. */ > movl %edi, oEDI(%eax) > movl %esi, oESI(%eax) > movl %ebp, oEBP(%eax) Ok. > diff --git a/sysdeps/unix/sysv/linux/i386/setcontext.S b/sysdeps/unix/sysv/linux/i386/setcontext.S > index b4b5c0298c..f042d80bf4 100644 > --- a/sysdeps/unix/sysv/linux/i386/setcontext.S > +++ b/sysdeps/unix/sysv/linux/i386/setcontext.S > @@ -65,22 +65,19 @@ ENTRY(__setcontext) > cfi_offset (esi, oESI) > cfi_offset (ebp, oEBP) > cfi_offset (ebx, oEBX) > - cfi_offset (edx, oEDX) > - cfi_offset (ecx, oECX) > movl oESP(%eax), %esp > > /* Push the return address on the new stack so we can return there. */ > pushl %ecx > > - /* Load the values of all the 32-bit registers (except ESP). > - Since we are loading from EAX, it must be last. */ > + /* Load the values of all the preserved registers (except ESP). */ > movl oEDI(%eax), %edi > movl oESI(%eax), %esi > movl oEBP(%eax), %ebp > movl oEBX(%eax), %ebx > - movl oEDX(%eax), %edx > - movl oECX(%eax), %ecx > - movl oEAX(%eax), %eax > + > + /* All done, return 0 for success. */ > + xorl %eax, %eax > > /* End FDE here, we fall into another context. */ > cfi_endproc Ok. > diff --git a/sysdeps/unix/sysv/linux/i386/swapcontext.S b/sysdeps/unix/sysv/linux/i386/swapcontext.S > index 792bfdf7e6..090c2d8c3e 100644 > --- a/sysdeps/unix/sysv/linux/i386/swapcontext.S > +++ b/sysdeps/unix/sysv/linux/i386/swapcontext.S > @@ -26,13 +26,7 @@ ENTRY(__swapcontext) > /* Load address of the context data structure we save in. */ > movl 4(%esp), %eax > > - /* Return value of swapcontext. EAX is the only register whose > - value is not preserved. */ > - movl $0, oEAX(%eax) > - > - /* Save the 32-bit register values and the return address. */ > - movl %ecx, oECX(%eax) > - movl %edx, oEDX(%eax) > + /* Save the preserved register values and the return address. */ > movl %edi, oEDI(%eax) > movl %esi, oESI(%eax) > movl %ebp, oEBP(%eax) > @@ -91,15 +85,14 @@ ENTRY(__swapcontext) > /* Push the return address on the new stack so we can return there. */ > pushl %ecx > > - /* Load the values of all the 32-bit registers (except ESP). > - Since we are loading from EAX, it must be last. */ > + /* Load the values of all the preserved registers (except ESP). */ > movl oEDI(%eax), %edi > movl oESI(%eax), %esi > movl oEBP(%eax), %ebp > movl oEBX(%eax), %ebx > - movl oEDX(%eax), %edx > - movl oECX(%eax), %ecx > - movl oEAX(%eax), %eax > + > + /* All done, return 0 for success. */ > + xorl %eax, %eax > > /* The following 'ret' will pop the address of the code and jump > to it. */ >