[code-reflection] RFR: Implement shift ops

Paul Sandoz psandoz at openjdk.org
Thu Apr 11 22:10:05 UTC 2024


On Wed, 10 Apr 2024 15:31:15 GMT, Hannes Greule <hgreule at openjdk.org> wrote:

> This PR implements the three shift operations. There are a few points to discuss:
> 
>     * naming: I chose the names as the operators are called in the JLS, but e.g. for comparisons we currently have short names. The Compiler also uses a different naming scheme here. Which way do we want to go here?
> 

The naming seems fine for these operations, and the compiler mnemonics are a little less clear IMO that those for comparisons. If you want to use something more mnemonic-like i suggest you use the same names we use for operators in the Vector API (see `jdk.incubator.vector.VectorOperators`), in fact i lean towards than naming.


>     * shift operations are different from other binary ops as their operands undergo unary numeric promotion rather than binary numeric promotion. However, on bytecode level the rhs will always be an int anyway. I'm currently handling that in the bytecode generator, and the model is close to the JLS otherwise. Any objections here?
> 

Hmm... interesting. When `byte` is on the rhs I presume it will be widened to `int`, and there will be a conversion operation inserted into the code model?

I am uncomfortable with these binary operations have different operand integral types in some cases (long << int, or int << long). It may be better to more uniform for the compiler generated code models and insert conversion operations (which i believe should not change program meaning, and we can optimize for bytecode generation). @mcimadamore WDYT?


>     * I reworked the testing to allow for combinations of different types, as that's important for the current design of shifts (especially `int shift long` should result in an int again)

Nice!

> 
> 
> I also noticed that I missed assignment operators when I did and, or, xor before. I left it out here as well, as this needs additional care, at least for the interpreter. Code like
> 
> ```java
> void m(byte b) {
>     b *= 2;
> }
> ```
> 
> doesn't run when using the interpreter currently. Should I add assignment operator handling here anyway?
>

Follow on PR?

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

PR Comment: https://git.openjdk.org/babylon/pull/49#issuecomment-2050638796


More information about the babylon-dev mailing list