Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Jan 2018 20:40:56 +0200
From:      Andriy Gapon <avg@FreeBSD.org>
To:        cem@freebsd.org
Cc:        "Rodney W. Grimes" <rgrimes@freebsd.org>, src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r328159 - head/sys/modules
Message-ID:  <a4402f31-a6c8-7f41-d49e-885e41e548d8@FreeBSD.org>
In-Reply-To: <CAG6CVpUj3SfiuHAaPMB1zGXpXPw=U-CsHgk%2BivEPyrzhvrrPKw@mail.gmail.com>
References:  <CAG6CVpV6Suft3v-=08f5UH6BTH2NEJgU_4kYd-UphLZ6yoJB4Q@mail.gmail.com> <201801191737.w0JHbM90073097@pdx.rh.CN85.dnsmgr.net> <CAG6CVpUj3SfiuHAaPMB1zGXpXPw=U-CsHgk%2BivEPyrzhvrrPKw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 19/01/2018 20:30, Conrad Meyer wrote:
> On Fri, Jan 19, 2018 at 9:37 AM, Rodney W. Grimes
> <freebsd@pdx.rh.cn85.dnsmgr.net> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a4402f31-a6c8-7f41-d49e-885e41e548d8>