From owner-svn-src-all@FreeBSD.ORG Thu Mar 29 23:31:49 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 309261065673; Thu, 29 Mar 2012 23:31:49 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1C1B88FC1C; Thu, 29 Mar 2012 23:31:49 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q2TNVmLv014922; Thu, 29 Mar 2012 23:31:48 GMT (envelope-from dim@svn.freebsd.org) Received: (from dim@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q2TNVmwN014920; Thu, 29 Mar 2012 23:31:48 GMT (envelope-from dim@svn.freebsd.org) Message-Id: <201203292331.q2TNVmwN014920@svn.freebsd.org> From: Dimitry Andric Date: Thu, 29 Mar 2012 23:31:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r233684 - head/sys/x86/include X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Mar 2012 23:31:49 -0000 Author: dim Date: Thu Mar 29 23:31:48 2012 New Revision: 233684 URL: http://svn.freebsd.org/changeset/base/233684 Log: Fix an issue introduced in sys/x86/include/endian.h with r232721. In that revision, the bswapXX_const() macros were renamed to bswapXX_gen(). Also, bswap64_gen() was implemented as two calls to bswap32(), and similarly, bswap32_gen() as two calls to bswap16(). This mainly helps our base gcc to produce more efficient assembly. However, the arguments are not properly masked, which results in the wrong value being calculated in some instances. For example, bswap32(0x12345678) returns 0x7c563412, and bswap64(0x123456789abcdef0) returns 0xfcdefc9a7c563412. Fix this by appropriately masking the arguments to bswap16() in bswap32_gen(), and to bswap32() in bswap64_gen(). This should also silence warnings from clang. Submitted by: jh Modified: head/sys/x86/include/endian.h Modified: head/sys/x86/include/endian.h ============================================================================== --- head/sys/x86/include/endian.h Thu Mar 29 23:30:17 2012 (r233683) +++ head/sys/x86/include/endian.h Thu Mar 29 23:31:48 2012 (r233684) @@ -65,9 +65,9 @@ #define __bswap16_gen(x) (__uint16_t)((x) << 8 | (x) >> 8) #define __bswap32_gen(x) \ - (((__uint32_t)__bswap16(x) << 16) | __bswap16((x) >> 16)) + (((__uint32_t)__bswap16((x) & 0xffff) << 16) | __bswap16((x) >> 16)) #define __bswap64_gen(x) \ - (((__uint64_t)__bswap32(x) << 32) | __bswap32((x) >> 32)) + (((__uint64_t)__bswap32((x) & 0xffffffff) << 32) | __bswap32((x) >> 32)) #ifdef __GNUCLIKE_BUILTIN_CONSTANT_P #define __bswap16(x) \