From owner-freebsd-current Tue Oct 31 3:55:52 2000 Delivered-To: freebsd-current@freebsd.org Received: from whale.sunbay.crimea.ua (whale.sunbay.crimea.ua [212.110.138.65]) by hub.freebsd.org (Postfix) with ESMTP id C5C7A37B479; Tue, 31 Oct 2000 03:55:31 -0800 (PST) Received: (from ru@localhost) by whale.sunbay.crimea.ua (8.11.0/8.11.0) id e9VBs0J09165; Tue, 31 Oct 2000 13:54:00 +0200 (EET) (envelope-from ru) Date: Tue, 31 Oct 2000 13:54:00 +0200 From: Ruslan Ermilov To: Bruce Evans Cc: Mike Smith , Bruce Evans , Konstantin Chuguev , Brian Somers , kargl@apl.washington.edu, freebsd-current@FreeBSD.ORG Subject: Re: platform byte order macros? Message-ID: <20001031135400.A64533@sunbay.com> Mail-Followup-To: Bruce Evans , Mike Smith , Bruce Evans , Konstantin Chuguev , Brian Somers , kargl@apl.washington.edu, freebsd-current@FreeBSD.ORG References: <20001027182758.A41742@sunbay.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from bde@zeta.org.au on Sat, Oct 28, 2000 at 04:13:46PM +1100 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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. 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 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