From owner-freebsd-current Tue Oct 31 22:47:14 2000 Delivered-To: freebsd-current@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 248D837B479; Tue, 31 Oct 2000 22:47:08 -0800 (PST) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.8.7/8.8.7) with ESMTP id RAA10465; Wed, 1 Nov 2000 17:47:01 +1100 Date: Wed, 1 Nov 2000 17:46:48 +1100 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: Ruslan Ermilov Cc: Mike Smith , Bruce Evans , Konstantin Chuguev , Brian Somers , kargl@apl.washington.edu, freebsd-current@FreeBSD.ORG Subject: Re: platform byte order macros? In-Reply-To: <20001031135400.A64533@sunbay.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, 31 Oct 2000, Ruslan Ermilov wrote: > 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. This seems to have been fixed. Do you remember when compiling certain libraries with -O0 -W -Werror broke the world because stdio.h has some static inline functions and there were warnings about these functions being unused? IIRC, code was generated for the functions, so the warning was appropriate. I can't reproduce this behaviour with the current gcc. > > 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: > ... > -#APP > - xchgb %ah, %al > -#NO_APP > + rolw $8,%ax Good, except there may be a problem with partial register stores (are xchgb's handled better than rolw?). I think we should use a non-asm version for the 16-bit swap. gcc didn't do so well for the 32-bit swap. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message