Subject: Re: Converting to little endian
To: Lennart Augustsson <augustss@cs.chalmers.se>
From: Todd Vierling <tv@pobox.com>
List: tech-kern
Date: 12/28/1998 09:49:03
On Mon, 28 Dec 1998, Lennart Augustsson wrote:

: > #include <sys/param.h>
: > #include <machine/bswap.h>
: > ...
: > 
: > 	u_int32_t x;
: > 	...
: > #if BYTE_ORDER == BIG_ENDIAN
: > 	x = bswap32(x);
: > #endif
: You must run a different NetBSD than I do.  There is no bswap.h
: header file on my machine.

Excuse me, I burped.  <sys/param.h> should include TRT automagically.

:  endian.h works though, but the definition of bswap32 in that file is
: not at all as efficient as ntohl().

Then improve it.  Note that ntohl() is a no-op on big endian machines--the
ones where you need this behavior!  Yes, there are arches where an inline
version of bswap would help--and you can help by writing one.

:  Besides, I would think that converting to little endian would be common
: enough that it merits a special function?

That's the reason bswap was invented.  See the FFS_EI stuff for which Manuel
put in these functions.

-- 
-- Todd Vierling (Personal tv@pobox.com; Bus. todd_vierling@xn.xerox.com)