From: Christian Franke <Christian.Franke@t-online.de>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: Endianness macros capitalization
Date: Tue, 08 Jul 2008 20:04:34 +0200 [thread overview]
Message-ID: <4873AC32.3060004@t-online.de> (raw)
In-Reply-To: <48726DB3.9000809@t-online.de>
[-- Attachment #1: Type: text/plain, Size: 1633 bytes --]
Christian Franke wrote:
>>>
>
> Assembly code for grub_swap_bytes16 from Debian gcc 4.1.2-7:
>
> Macro or Inline: 4 bytes (minus possible additional benefit from
> register level optimizations)
>
> 66 c1 c0 08 rol $0x8,%ax
>
>
> Function call: 11 bytes
>
> 0f b7 c0 movzwl %ax,%eax
> e8 xx xx xx xx call grub_swap_bytes16
> 0f b7 c0 movzwl %ax,%eax
>
> The break even is possibly at grub_swap_bytes64() :-)
>
I take that back. For i386, even grub_swap_bytes32() should possibly be
a function.
The attached script compares the sizes of 8 inline expansions of
grub_swap_bytesNN() vs. function calls.
Sample output (Debian gcc 4.1.2-7):
/* 16 bit: inline=88, function=128 */
/* 32 bit: inline=357, function=104 */
#define GRUB_DONT_INLINE_GRUB_SWAP_BYTES32 1
/* 64 bit: inline=2621, function=167 */
#define GRUB_DONT_INLINE_GRUB_SWAP_BYTES64 1
With old gcc versions without the "rol" optimization, even the 16 bit
swap should be a function:
(Cygwin gcc 3.4.4):
/* 16 bit: inline=148, function=116 */
#define GRUB_DONT_INLINE_GRUB_SWAP_BYTES16 1
/* 32 bit: inline=340, function=96 */
#define GRUB_DONT_INLINE_GRUB_SWAP_BYTES32 1
/* 64 bit: inline=2876, function=164 */
#define GRUB_DONT_INLINE_GRUB_SWAP_BYTES64 1
Interestingly, the 64bit inline result is much smaller if
'-fomit-frame-pointer' is added:
(Cygwin gcc 3.4.4):
/* 16 bit: inline=144, function=112 */
#define GRUB_DONT_INLINE_GRUB_SWAP_BYTES16 1
/* 32 bit: inline=336, function=92 */
#define GRUB_DONT_INLINE_GRUB_SWAP_BYTES32 1
/* 64 bit: inline=1372, function=160 */
#define GRUB_DONT_INLINE_GRUB_SWAP_BYTES64 1
Christian
[-- Attachment #2: testsizes.sh.txt --]
[-- Type: text/plain, Size: 996 bytes --]
#!/bin/sh
set -e
srcdir=..
cat <<EOF > test.c
#include <grub/types.h>
#ifdef extf
type extf(type);
#define func extf
#else
#define func inlf
#endif
extern type x1,x2,x3,x4;
type test(type x, type *p)
{
x4 = func(func(x1) + func(x2) + func(x3));
*p = func(func(*p) * 13);
return func(func(x) + 42);
}
EOF
CC="gcc -c -I. -Iinclude -I${srcdir}/include -Os -falign-jumps=1 -falign-loops=1 -falign-functions=1 -mregparm=3 -mrtd $*"
for bits in 16 32 64; do
${CC} -Dtype=grub_uint${bits}_t -Dinlf=grub_swap_bytes${bits} -o test${bits}i.o test.c
si=$(size test${bits}i.o | sed -n '2s,^ *\([0-9]*\).*$,\1,p')
${CC} -Dtype=grub_uint${bits}_t -Dextf=grub_swap_bytes${bits}_f -o test${bits}f.o test.c
sf=$(size test${bits}f.o | sed -n '2s,^ *\([0-9]*\).*$,\1,p')
echo "/* ${bits} bit: inline=$si, function=$sf */"
[ $si -gt $sf ] && echo "#define GRUB_DONT_INLINE_GRUB_SWAP_BYTES${bits} 1"
#rm -f test${bits}{i,f}.o
done
rm -f test.c
next prev parent reply other threads:[~2008-07-08 18:05 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 [this message]
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
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=4873AC32.3060004@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.