Subject: Re: hto{le,be}{16,32,64}() proposal
To: Jason Thorpe <thorpej@nas.nasa.gov>
From: Simon Burge <simonb@netbsd.org>
List: tech-userlevel
Date: 06/26/1999 01:18:04
Jason Thorpe wrote:
> On Fri, 25 Jun 1999 21:54:09 +1000
> Simon Burge <simonb@netbsd.org> wrote:
>
> > I propose adding a set of macros to <machine/bswap.h> called
> > htole{16,32,64} and htobe{16,32,64} implemented in terms of bswap* and
> > no-ops. There would also be a matching group of {le,be}toh* which do
> > exactly the same thing.
>
> This is a wonderful idea :-) Many device drivers would like this :-)
>
> Don't forget HTO{BE,LE}{16,32,64}() and {BE,LE}TOH{16,32,64}() too :-)
Those are just the in-place versions, right?
> > I'm not 100% convinced that <machine/bswap.h> is the right place for
> > these. I'd be happier putting these in <machine/endian.h>, but then
> > that header file would have to include <machine/bswap.h> to get the
> > bswap* prototypes. Would doing this break anything?
>
> <machine/endian.h> is probably the right place, but we need to go on
> a namespace protection sweep in there.
Hmm, I didn't volunteer for that now, did I? I buggered up my last
namespace test :-)
Thinking about the location of this a little more, it seems that all the
arch-specific <machine/endian.h> files should be little more than:
#ifndef _MACHINE_ENDIAN_H_
#define _MACHINE_ENDIAN_H_
#define _BYTE_ORDER _{BIG,LITTLE}_ENDIAN
#include <sys/endian.h>
#endif /* _MACHINE_ENDIAN_H */
With all the repetitive magic done in <sys/endian.h>. There's an awful
lot of needless duplication in there at the moment... It looks like the
i386 and pc532 endian.h would have a little extra goo, but that'd be
about it. We could even have <sys/endian.h> contain:
#ifndef _MACHINE_ENDIAN_H
#include <machine/endian.h>
#endif
near the top and have in <machine/endian.h>:
#ifndef _SYS_ENDIAN_H
#include <sys/endian.h>
#endif
so that including either <machine/endian.h> or <sys/endian.h> would
DTRT.
Simon.