Grub Development Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: Endianness macros capitalization
Date: Thu, 10 Jul 2008 21:25:37 +0200	[thread overview]
Message-ID: <48766231.9050006@t-online.de> (raw)
In-Reply-To: <1215626250.26246.9.camel@dv>

Pavel Roskin wrote:
> On Wed, 2008-07-09 at 14:50 +0200, Christian Franke wrote:
>   
>
>> 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().
>>     
>
> But we are getting closer!
>
>   

But probably not close enough in the average case, see below :-)


>>> .... 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?
>>     
>
> Yes.  That's %b0 and %h0.  Use "=q" for all registers with "upper
> halves" (%ah-%dh).
>
>   

Thanks for the info.

I tried this in the same script:

#define grub_swap_bytes32(x) \
({ \
   grub_uint32_t _x = (x), _y; \
   asm ( \
        "xchgb %b0,%h0\n" \
        "roll $0x10,%0\n" \
        "xchgb %b0,%h0\n" \
        : "=q"(_y) : "0"(_x) \
    ); \
    _y; \
})


GCC optimizer does a good job optimizing register use, but function call 
is still better:

Debian gcc 4.1.2-7:
inline (portable)=357,asm (%%eax)=126, asm (%0)=107, function=104

Cygwin gcc 3.4.4:
inline (portable)=340, asm (%%eax)=124, asm (%0)=104, function=96


Inline asm is only better is rare cases, e.g. with this test function:

type test(type *x)
{
  return func(x[0]) + func(x[1]) + ... + func(x[N]);
}

Result with Cygwin gcc 3.4.4:

N=0: asm=14, function=11
N=1: asm=28, function=32
N=2: asm=40, function=41
N=3: asm=52, function=51
N=4: asm=64, function=61
N=5: asm=76, function=72


To test which files would possibly be affected by any size optimization 
of grub_swap_bytes*(), I 've done a test compilation with these macros 
replaced by dummies '(x)'. Only the size of following modules changed:

affs.mod
afs.mod
amiga.mod
apple.mod
ata.mod
hfs.mod
hfsplus.mod
iso9660.mod
jpeg.mod
png.mod
sfs.mod
sun.mod
xfs.mod

Remaining modules and kernel.img are identical.

Christian




  reply	other threads:[~2008-07-10 19:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-05 13:27 Endianness macros capitalization Javier Martín
2008-07-05 21:30 ` Pavel Roskin
2008-07-05 22:54   ` Javier Martín
2008-07-05 23:14     ` Pavel Roskin
2008-07-06 18:30     ` Robert Millan
2008-07-06 20:02       ` Javier Martín
2008-07-07 19:25         ` Christian Franke
2008-07-08 18:04           ` Christian Franke
2008-07-09  6:47             ` Pavel Roskin
2008-07-09 12:50               ` Christian Franke
2008-07-09 17:57                 ` Pavel Roskin
2008-07-10 19:25                   ` Christian Franke [this message]
2008-07-10 19:59                     ` Pavel Roskin
2008-07-11  7:06                       ` Jordi Mallach
2008-07-11  8:53                     ` Pavel Roskin
2008-07-11  9:07                       ` Pavel Roskin
2008-07-11 13:21                         ` Christian Franke
2008-07-11 18:33                           ` Pavel Roskin
2008-07-20 13:45                 ` Christian Franke
2008-07-20 23:31                   ` Pavel Roskin

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=48766231.9050006@t-online.de \
    --to=christian.franke@t-online.de \
    --cc=grub-devel@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox