From owner-freebsd-hackers@FreeBSD.ORG Tue Apr 3 17:41:06 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 83D4716A402 for ; Tue, 3 Apr 2007 17:41:06 +0000 (UTC) (envelope-from anderson@freebsd.org) Received: from mh1.centtech.com (moat3.centtech.com [64.129.166.50]) by mx1.freebsd.org (Postfix) with ESMTP id 5905813C458 for ; Tue, 3 Apr 2007 17:41:06 +0000 (UTC) (envelope-from anderson@freebsd.org) Received: from [10.177.171.220] (neutrino.centtech.com [10.177.171.220]) by mh1.centtech.com (8.13.8/8.13.8) with ESMTP id l33Hf5X6048129; Tue, 3 Apr 2007 12:41:05 -0500 (CDT) (envelope-from anderson@freebsd.org) Message-ID: <461291B1.2070303@freebsd.org> Date: Tue, 03 Apr 2007 12:41:05 -0500 From: Eric Anderson User-Agent: Thunderbird 1.5.0.10 (X11/20070320) MIME-Version: 1.0 To: Andriy Gapon References: <46128D47.50109@icyb.net.ua> In-Reply-To: <46128D47.50109@icyb.net.ua> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV 0.88.4/3007/Tue Apr 3 07:26:03 2007 on mh1.centtech.com X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=8.0 tests=AWL,BAYES_00 autolearn=ham version=3.1.6 X-Spam-Checker-Version: SpamAssassin 3.1.6 (2006-10-03) on mh1.centtech.com Cc: freebsd-hackers@freebsd.org Subject: Re: strange bit-shifting X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Apr 2007 17:41:06 -0000 On 04/03/07 12:22, Andriy Gapon wrote: > $ cat test_shl.c > #include > #include > > int main() > { > uint64_t l; > > l = 0; > l--; > printf("%.16lX\n", l); > l <<= 64; > printf("%.16lX\n", l); > return 0; > } > > $ cc test_shl.c -o test_shl > test_shl.c: In function `main': > test_shl.c:11: warning: left shift count >= width of type > $ ./test_shl > FFFFFFFFFFFFFFFF > FFFFFFFFFFFFFFFF > $ uname -srm > FreeBSD 6.2-RELEASE-p2 amd64 > $ gcc -v > Using built-in specs. > Configured with: FreeBSD/amd64 system compiler > Thread model: posix > gcc version 3.4.6 [FreeBSD] 20060305 > > What gives ? It looks like shift is actually done not by specified > number of bits but by that number modulo 64. > Please also mind that the same thing happens if I use a variable instead > of a constant in that expression. > I see the same thing on -CURRENT. I was doing something like: uint64_t l; l = 1 << 40; but instead did: l = (1 << 30) * 1024; which works fine. This was on i386. Eric