From owner-cvs-src@FreeBSD.ORG Fri Apr 4 23:08:21 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 E1AD437B401; Fri, 4 Apr 2003 23:08:21 -0800 (PST) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5E10243FB1; Fri, 4 Apr 2003 23:08:19 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from katana.zip.com.au (katana.zip.com.au [61.8.7.246]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id RAA29197; Sat, 5 Apr 2003 17:08:12 +1000 Date: Sat, 5 Apr 2003 17:08:11 +1000 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: "M. Warner Losh" In-Reply-To: <20030404.160823.91026001.imp@bsdimp.com> Message-ID: <20030405165535.X37179@gamplex.bde.org> References: <20030404085200.GA1765@sunbay.com> <20030404.160823.91026001.imp@bsdimp.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: cvs-src@FreeBSD.org cc: src-committers@FreeBSD.org cc: ru@FreeBSD.org cc: phk@FreeBSD.org cc: nate@root.org cc: obrien@FreeBSD.org cc: cvs-all@FreeBSD.org cc: mike@FreeBSD.org 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: Sat, 05 Apr 2003 07:08:22 -0000 On Fri, 4 Apr 2003, M. Warner Losh wrote: > In message: <20030404085200.GA1765@sunbay.com> > Ruslan Ermilov writes: > : +#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))) > > 0xffull or 0xffULL might be better than the casts here. This does > assume that 0ull == (uint64_t)0, which does hold for all our > architectures... It would be worse because it breaks compilation by C compilers (C90), but not because it assumes that 0ull == (uint64_t)0. Unsigned long long has at least 64 bits in C99, and nothing more or less is needed for the casts of the literal constants. Casting of all of the instances of (x) that aren't masked later, and of the result, is needed if x can have any type other than uint64_t. E.g., if x is uint128_t and all of its bits are 1's then, (x) >> 56 is too large; if x is int64_t and negative and has any value other than -1, then (x) >> 56 leaves too many bits set. Bruce