cvs commit: src/sys/sys endian.h src/share/man/man9 byteorder.9

Nate Lawson nate at root.org
Fri Apr 4 11:54:10 PST 2003


On Fri, 4 Apr 2003, Ruslan Ermilov wrote:
> > > On Thu, 3 Apr 2003, Poul-Henning Kamp wrote:
> > > >   Modified files:
> > > >     sys/sys              endian.h 
> > > >     share/man/man9       byteorder.9 
> > > >   Log:
> > > >   Add inline functions {be,le}{16,32,64}{enc,dec}() for encoding decoding
> > > >   into byte strings of unknown alignment.
> 
>  /*
> + * General byte order swapping macros.
> + */
> +#define	BSWAP16(x)	(uint16_t) \
> +	(((x) >> 8) | ((x) << 8))
> +
> +#define	BSWAP32(x)	(uint32_t) \
> +	(((x) >> 24) | (((x) >> 8) & 0xff00) | \
> +	(((x) << 8) & 0xff0000) | ((x) << 24))
> +
> +#define	BSWAP64(x)	(uint64_t) \
> +	(((x) >> 56) | (((x) >> 40) & 0xff00) | (((x) >> 24) & 0xff0000) | \
> +	(((x) >> 8) & 0xff000000) | (((x) << 8) & ((uint64_t)0xff << 32)) | \
> +	(((x) << 24) & ((uint64_t)0xff << 40)) | \
> +	(((x) << 40) & ((uint64_t)0xff << 48)) | (((x) << 56)))
> +
> +/*
>   * Host to big endian, host to little endian, big endian to host, and little
>   * endian to host byte order functions as detailed in byteorder(9).
>   */
>  #if _BYTE_ORDER == _LITTLE_ENDIAN
>  #define	htobe16(x)	bswap16((x))
> +#define	HTOBE16(x)	BSWAP16((x))

I don't mind the addition of the macros but I don't like the
implementation.  Too many unnecessary casts and overly complicated.

-Nate




More information about the cvs-src mailing list