Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KGc6A-0008Fj-0p for mharc-grub-devel@gnu.org; Wed, 09 Jul 2008 12:00:54 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KGc65-0008E1-6P for grub-devel@gnu.org; Wed, 09 Jul 2008 12:00:49 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KGc62-0008C1-Gm for grub-devel@gnu.org; Wed, 09 Jul 2008 12:00:48 -0400 Received: from [199.232.76.173] (port=41709 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KGc62-0008Bl-4A for grub-devel@gnu.org; Wed, 09 Jul 2008 12:00:46 -0400 Received: from mx20.gnu.org ([199.232.41.8]:47901) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KGbfZ-0008J8-GH for grub-devel@gnu.org; Wed, 09 Jul 2008 11:33:25 -0400 Received: from mailout10.t-online.de ([194.25.134.21]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KGZ7z-00033k-8Y for grub-devel@gnu.org; Wed, 09 Jul 2008 08:50:35 -0400 Received: from fwd32.aul.t-online.de by mailout10.sul.t-online.de with smtp id 1KGZ7w-0000Or-00; Wed, 09 Jul 2008 14:50:32 +0200 Received: from localhost (ZCZ5B6ZLYhnvYyBP65uuFkjFWgxN8-Gd2DngMp4xF6HXN5c4Ieyr+ZnRGz3HdDnwEg@[172.20.101.250]) by fwd32.aul.t-online.de with esmtp id 1KGZ7b-1EcJsG0; Wed, 9 Jul 2008 14:50:11 +0200 MIME-Version: 1.0 In-Reply-To: <1215586047.31230.27.camel@dv> References: <1215264476.26019.160.camel@localhost> <1215293427.17114.2.camel@dv> <1215298499.26019.192.camel@localhost> <20080706183042.GA22023@thorin> <1215374534.26019.194.camel@localhost> <48726DB3.9000809@t-online.de> <4873AC32.3060004@t-online.de> <1215586047.31230.27.camel@dv> Date: Wed, 09 Jul 2008 14:50:11 +0200 To: "The development of GRUB 2" X-UMS: email X-Mailer: TOI Kommunikationscenter V9-2-9 From: "Christian Franke" Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit Message-ID: <1KGZ7b-1EcJsG0@fwd32.aul.t-online.de> X-ID: ZCZ5B6ZLYhnvYyBP65uuFkjFWgxN8-Gd2DngMp4xF6HXN5c4Ieyr+ZnRGz3HdDnwEg@t-dialin.net X-TOI-MSGID: e07819a8-6994-49d9-8cc6-9a639a2a94b8 X-detected-kernel: by mx20.gnu.org: Linux 2.6 (newer, 3) X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) Subject: Re: Endianness macros capitalization X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Jul 2008 16:00:49 -0000 Pavel Roskin wrote: > On Tue, 2008-07-08 at 20:04 +0200, Christian Franke wrote: > > > With old gcc versions without the "rol" optimization, even the 16 > > bit swap should be a function: > > > > Or better yet, an asm statement. > > We should consider optimized assembly vs function call. Even the > 32-bit swap could be shorter: > > a: 86 c4 xchg %al,%ah > c: c1 c0 10 rol $0x10,%eax > f: 86 c4 xchg %al,%ah > 11: > > That's 7 bytes! ... But the function call in the 32-bit case requires only 5 bytes :-) (The 16-bit case requires more due to short->int propagation) Overall size from inline asm would only be smaller if there is any benefit from additional optimizations. Here is a possibly working draft for include/grub/i386/types.h (requires a #ifdef in include/grub/types.h): #define grub_swap_bytes32(x) \ ({ \ grub_uint32_t _x = (x), _y; asm ( \ "xchg %%al,%%ah\n" \ "roll $0x10,%%eax\n" \ "xchg %%al,%%ah\n" \ : "=a"(_y) : "0"(_x) \ ); \ _y; \ }) Result with the test script from my last mail: Debian gcc 4.1.2-7: inline (portable)=357, inline (asm)=126, function=104 Cygwin gcc 3.4.4: inline (portable)=340, inline (asm)=124, function=96 Function call is still better. The only candidate for inline is probably grub_swap_bytes16(). > .... And if written properly, it could work with any of > the registers that allow access to the lower two bytes (%eax, %ebx, > %ecx and %edx), thus giving more flexibility to the optimizer. > This would require support to access the Rl and Rh parts of eRx for each R in [a-d]. Something like: asm ( "xchg %0:l,%0:h\n" "roll $0x10,%0\n" "xchg %0:l,%0:h\n" : "=r"(_y) : "0"(_x) \ ); Do gcc or gas provide a syntax to do this? Christian