From owner-svn-src-all@freebsd.org Fri Jan 19 18:41:07 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 65A6DEC13C5; Fri, 19 Jan 2018 18:41:07 +0000 (UTC) (envelope-from agapon@gmail.com) Received: from mail-lf0-f50.google.com (mail-lf0-f50.google.com [209.85.215.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E8A846E54C; Fri, 19 Jan 2018 18:41:06 +0000 (UTC) (envelope-from agapon@gmail.com) Received: by mail-lf0-f50.google.com with SMTP id f136so3204212lff.8; Fri, 19 Jan 2018 10:41:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=1GqNRBvUjpPfzjJ3vrfofGHjo6EEL08Lkb9tgp2derU=; b=CelqFqeC2jUe3uC2TEi/sper2ENpvuE/ucuouNGcdb+qNmaDa6CNaxFxJaZDi3mLi+ ZKMQkZE2/bymrVA2McAA40I9tkbMTjTwZN+asR7xmd91U8d+GYKKiewIuEsXoyJlaJcf ELr7x7Nk2q8+LIg5bFaZdekJZlkT3BSZXwmYEWMItrTPFwOLpARZhIAogM9dWATFp9kz 6ZzP/yZHrugIq1Uwy2YZ1C1tTkTqrBYnxoHM6lw5eW9+ZHXr58wgDIx/whx3kwSXNLa9 DdGu5VIqBkBo0PzaBEBLCeUjq/hZ3h2NG5ZH3cmYpD3St7DZLjEVqtD6AyTK3b+DNJTj 7X9g== X-Gm-Message-State: AKwxytd9P63iOFk+o4S1h66p0rNRaNoM1HiuclRidfr0ipkHUTagdwKU UASyHOqN1SvrG5apNKCxCHRvVLA7EM4= X-Google-Smtp-Source: AH8x226lcWau262xoP8hBr3YTkuONjXdPooSUx0TH4jlJULrvZ4ECB2V7m6bjqTmHYoA0cx+gsxbXw== X-Received: by 10.46.99.75 with SMTP id x72mr1206070ljb.136.1516387258974; Fri, 19 Jan 2018 10:40:58 -0800 (PST) Received: from [192.168.0.88] (east.meadow.volia.net. [93.72.151.96]) by smtp.googlemail.com with ESMTPSA id k77sm1745679lfe.48.2018.01.19.10.40.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 10:40:57 -0800 (PST) Subject: Re: svn commit: r328159 - head/sys/modules To: cem@freebsd.org Cc: "Rodney W. Grimes" , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org References: <201801191737.w0JHbM90073097@pdx.rh.CN85.dnsmgr.net> From: Andriy Gapon Message-ID: Date: Fri, 19 Jan 2018 20:40:56 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 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: Fri, 19 Jan 2018 18:41:07 -0000 On 19/01/2018 20:30, Conrad Meyer wrote: > On Fri, Jan 19, 2018 at 9:37 AM, Rodney W. Grimes > wrote: >> If you think in assembler it is easy to understand why this is UB, >> most (all) architectures Right Logic or Arithmetic Shift only accept an >> operand that is a size that can hold log2(wordsize). > > This is a logical right shift by a constant larger than the width of > the left operand. As a result, it would a constant zero in any > emitted machine code. It is a bug in the C standard and a concession > to naive, non-optimizing compilers that this is considered UB. > Are you sure? I seem to recall that the actual shift happens to be N % 32 for 32-bit registers (at least on some processors). [Goes to check AMD Programmer's manual] Ah, here you are: The processor masks the upper three bits of the count operand, thus restricting the count to a number between 0 and 31. When the destination is 64 bits wide, the processor masks the upper two bits of the count, providing a count in the range of 0 to 63. -- Andriy Gapon