Date: Fri, 4 Apr 2003 11:54:07 -0800 (PST) From: Nate Lawson <nate@root.org> To: Ruslan Ermilov <ru@FreeBSD.org> Cc: Mike Barcroft <mike@FreeBSD.org> Subject: Re: cvs commit: src/sys/sys endian.h src/share/man/man9 byteorder.9 Message-ID: <Pine.BSF.4.21.0304041150530.17052-100000@root.org> In-Reply-To: <20030404085200.GA1765@sunbay.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0304041150530.17052-100000>