Date: Tue, 31 Oct 2000 13:54:00 +0200 From: Ruslan Ermilov <ru@FreeBSD.ORG> To: Bruce Evans <bde@zeta.org.au> Cc: Mike Smith <msmith@mass.osd.bsdi.com>, Bruce Evans <bde@FreeBSD.ORG>, Konstantin Chuguev <Konstantin.Chuguev@dante.org.uk>, Brian Somers <brian@Awfulhak.org>, kargl@apl.washington.edu, freebsd-current@FreeBSD.ORG Subject: Re: platform byte order macros? Message-ID: <20001031135400.A64533@sunbay.com> In-Reply-To: <Pine.BSF.4.21.0010281555100.49427-100000@besplex.bde.org>; from bde@zeta.org.au on Sat, Oct 28, 2000 at 04:13:46PM %2B1100 References: <20001027182758.A41742@sunbay.com> <Pine.BSF.4.21.0010281555100.49427-100000@besplex.bde.org>
index | next in thread | previous in thread | raw e-mail
On Sat, Oct 28, 2000 at 04:13:46PM +1100, Bruce Evans wrote:
> On Fri, 27 Oct 2000, Ruslan Ermilov wrote:
>
> > On Fri, Oct 27, 2000 at 06:11:49PM +0300, Ruslan Ermilov wrote:
> > > On Fri, Oct 27, 2000 at 07:34:06AM -0700, Mike Smith wrote:
> > > > > +#ifdef __OPTIMIZE__
> > > >
> > > > Using macros does not "optimise" anything,
>
> Not quite true. Using inline functions pessimizes everything that is
> compiled without -O since the functions don't get inlined but code
> for them is generated in each object file whether or not they are
> used. <sys/types.h> is included a lot, so having inline functions in
> it is especially pessimal for the -O0 case.
>
Hmm, even if these function declared static? I was not able to
reproduce this with static inline functions.
> > > > and this is a very poor choice
> > > > of defines. __MACRO_ENDIAN_CONVERSIONS might be better.
>
> __OPTIMIZE__ is the standard gcc macro for telling whether gcc has been
> invoked with -O. It is used sort of backwards here. There is no reason
> to turn off the macros for constants, but turning off the inlines for
> non-constants would fix the useless bloat in the -O0 case.
>
> Is the htonl() family used enough on constants for the constant case to
> be worth optimizing?
>
Probably it's not.
> Writing the byte swapping using shifts and masks might be best in all
> cases. The compiler can in theory reduce shifts and masks to bswap on
> i386's if that is best, but it can't look inside asm statements.
>
And in practice (with -O), they are almost equivalent. The following C
code
#include <sys/types.h>
unsigned short
foo(unsigned short a)
{
return (htons(a));
}
produces the following asm code diffs when using the current __asm version
compared to the macro version:
--- a.s.ASM Tue Oct 31 13:17:32 2000
+++ a.s.MACRO Tue Oct 31 13:45:57 2000
@@ -1,20 +1,18 @@
.file "a.c"
.version "01.01"
gcc2_compiled.:
.text
.p2align 2,0x90
.globl foo
.type foo,@function
foo:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
-#APP
- xchgb %ah, %al
-#NO_APP
+ rolw $8,%ax
andl $65535,%eax
leave
ret
.Lfe1:
.size foo,.Lfe1-foo
.ident "[ASM_FILE_END]GCC: (c) 2.95.2 19991024 (release)"
--
Ruslan Ermilov Oracle Developer/DBA,
ru@sunbay.com Sunbay Software AG,
ru@FreeBSD.org FreeBSD committer,
+380.652.512.251 Simferopol, Ukraine
http://www.FreeBSD.org The Power To Serve
http://www.oracle.com Enabling The Information Age
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001031135400.A64533>
