Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Nov 2000 17:46:48 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Ruslan Ermilov <ru@FreeBSD.ORG>
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:  <Pine.BSF.4.21.0011011719120.55999-100000@besplex.bde.org>
In-Reply-To: <20001031135400.A64533@sunbay.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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.  <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.

This seems to have been fixed.  Do you remember when compiling certain
libraries with -O0 -W<a lot> -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 <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:

> ...
> -#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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0011011719120.55999-100000>