From owner-cvs-src@FreeBSD.ORG Fri Apr 4 12:15:00 2003 Return-Path: Delivered-To: cvs-src@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 25D7237B407; Fri, 4 Apr 2003 12:15:00 -0800 (PST) Received: from whale.sunbay.crimea.ua (whale.sunbay.crimea.ua [212.110.138.65]) by mx1.FreeBSD.org (Postfix) with ESMTP id BE36443F75; Fri, 4 Apr 2003 12:14:55 -0800 (PST) (envelope-from ru@whale.sunbay.crimea.ua) Received: from whale.sunbay.crimea.ua (ru@localhost [127.0.0.1]) h34KEhgg086468 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 4 Apr 2003 23:14:44 +0300 (EEST) (envelope-from ru@whale.sunbay.crimea.ua) Received: (from ru@localhost) by whale.sunbay.crimea.ua (8.12.9/8.12.8/Submit) id h34KEhBq086463; Fri, 4 Apr 2003 23:14:43 +0300 (EEST) (envelope-from ru) Date: Fri, 4 Apr 2003 23:14:43 +0300 From: Ruslan Ermilov To: Nate Lawson Message-ID: <20030404201443.GA82587@sunbay.com> References: <20030404085200.GA1765@sunbay.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="G4iJoqBmSsgzjUCe" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.4i cc: src-committers@FreeBSD.org cc: Poul-Henning Kamp cc: David O'Brien cc: cvs-src@FreeBSD.org cc: cvs-all@FreeBSD.org cc: Mike Barcroft Subject: Re: cvs commit: src/sys/sys endian.h src/share/man/man9 byteorder.9 X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Apr 2003 20:15:00 -0000 --G4iJoqBmSsgzjUCe Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 04, 2003 at 11:54:07AM -0800, Nate Lawson wrote: > On Fri, 4 Apr 2003, Ruslan Ermilov wrote: > > > > On Thu, 3 Apr 2003, Poul-Henning Kamp wrote: > > > > > Modified files: > > > > > sys/sys endian.h=20 > > > > > share/man/man9 byteorder.9=20 > > > > > Log: > > > > > Add inline functions {be,le}{16,32,64}{enc,dec}() for encoding = decoding > > > > > into byte strings of unknown alignment. > >=20 > > /* > > + * 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 =3D=3D _LITTLE_ENDIAN > > #define htobe16(x) bswap16((x)) > > +#define HTOBE16(x) BSWAP16((x)) >=20 > I don't mind the addition of the macros but I don't like the > implementation. Too many unnecessary casts and overly complicated. >=20 I've borrowed them from sys/sparc64/include/endian.h. The type casts are necessary, otherwise you'll get ``warning: left shift count >=3D width of type'', and it should be trivial to test with this program: #include #include #include int main(void) { uint64_t i =3D 0xefcdab8967452301; printf("%jx\n", i); i =3D BSWAP64(i); printf("%jx\n", i); return (0); } Cheers, --=20 Ruslan Ermilov Sysadmin and DBA, ru@sunbay.com Sunbay Software AG, ru@FreeBSD.org FreeBSD committer, +380.652.512.251 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age --G4iJoqBmSsgzjUCe Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (FreeBSD) iD8DBQE+jeezUkv4P6juNwoRAo1DAJ9VpbRVojIELdXmWu5EQKBnNwBcvACfYhqm WLhVhnjsjuc0UEfrJP4shfU= =qe6b -----END PGP SIGNATURE----- --G4iJoqBmSsgzjUCe--