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,
[EMAIL PROTECTED]           Sunbay Software AG,
[EMAIL PROTECTED]          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 [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to