[ Charset UTF-8 unsupported, converting... ]
> On Fri, Jan 19, 2018 at 6:56 AM, David Chisnall <thera...@freebsd.org> wrote:
> > In C, a right-shift of a signed type propagates the sign bit.  Right 
> > shifting a negative 32-bit int by 16 and then again by 16 is not undefined 
> > behaviour (though doing the shift as a single operation is) and will give 
> > you a value of -1.
> 
> The left hand operand under discussion is unsigned.  In LLVM/assembler
> terms, this is a logical right shift, not an arithmetic right shift.
> It is by definition zero filled from the left.

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).

Do you want the compiler to emmit multiple Shift instructions for your
oversized operand?    Do you want it to emmit a loop reducing your
oversized operand by log2(wordsize) each time through the loop until
your operand is < log2(wordsize)?

Bite the bullet, this is bad code, and should be fixed, not
simply sweep under the carpet cause it fails on i386.


-- 
Rod Grimes                                                 rgri...@freebsd.org
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to