On Mon, 18 Apr 2022 03:48:13 GMT, Quan Anh Mai <d...@openjdk.java.net> wrote:

> Because unsigned cast should operate on unsigned types, the more appropriate 
> usage is `(src[i] & 0xFF) >>> 3`, with the `&` operation is the cast from 
> unsigned byte to int. Actually, I fail to understand the intention of your 
> example, why not use signed shift instead, what does unsigned shift provide 
> here apart from extra cognitive load in reasoning the operation.


The fact is that you can't prevent developers from using `>>>` upon negative 
elements since neither the JVMS nor the JLS prevents it.


> May you provide a more concrete example to the utilisation of unsigned shift 
> on signed subword types, please. The example provided by @fg1417 in #7979 
> seems to indicate the real intention is to right shifting unsigned bytes, 
> with the unsigned cast sometimes omitted (changed to a signed cast) because 
> the shift results are masked by a stricter mask immediately.

Sorry, I can't show the detail of our customer's code.
However, just image that someone would like to optimize some code segments of 
bytes/shorts `>>>`, how can you say there should be always non-negative 
operands?

-------------

PR: https://git.openjdk.java.net/jdk/pull/8276

Reply via email to