From owner-svn-src-head@FreeBSD.ORG Fri Mar 30 08:25:35 2012 Return-Path: Delivered-To: svn-src-head@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B2C0B106566C; Fri, 30 Mar 2012 08:25:35 +0000 (UTC) (envelope-from ache@vniz.net) Received: from vniz.net (vniz.net [194.87.13.69]) by mx1.freebsd.org (Postfix) with ESMTP id CFABE8FC1A; Fri, 30 Mar 2012 08:25:31 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by vniz.net (8.14.5/8.14.5) with ESMTP id q2U8PT7i047248; Fri, 30 Mar 2012 12:25:29 +0400 (MSK) (envelope-from ache@vniz.net) Received: (from ache@localhost) by localhost (8.14.5/8.14.5/Submit) id q2U8PTuG047247; Fri, 30 Mar 2012 12:25:29 +0400 (MSK) (envelope-from ache) Date: Fri, 30 Mar 2012 12:25:28 +0400 From: Andrey Chernov To: Dimitry Andric Message-ID: <20120330082528.GA47173@vniz.net> Mail-Followup-To: Andrey Chernov , Dimitry Andric , src-committers@FreeBSD.ORG, svn-src-all@FreeBSD.ORG, svn-src-head@FreeBSD.ORG References: <201203292331.q2TNVmwN014920@svn.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201203292331.q2TNVmwN014920@svn.freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: svn-src-head@FreeBSD.ORG, svn-src-all@FreeBSD.ORG, src-committers@FreeBSD.ORG Subject: Re: svn commit: r233684 - head/sys/x86/include X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Mar 2012 08:25:35 -0000 On Thu, Mar 29, 2012 at 11:31:48PM +0000, Dimitry Andric wrote: > 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. Is sign extension considered in that place? Shifting any signed value to ">>" direction (char, short, int, etc.) replicates sign bit, so cast to corresponding unsigned value must be done first, which may take less instructions, than masking (I am not sure about this part, just guessing). Casting in that case applies to the argument (x) not to result (x >> YY). > > #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) \ -- http://ache.vniz.net/