On Sat, 18 Mar 2023 17:06:52 GMT, jmehrens <d...@openjdk.org> wrote:

>> We could, but benchmarks show no performance improvements over the current 
>> PR. I think the current code is perhaps slightly more readable.
>
> Does non-short-circuit logical AND operator perform similar to baseline?  In 
> this very specific case there is no risk of side effects due to method calls, 
> no risk of null pointer exception because of primitives, and there is not an 
> excessive amount of conditions.  Therefore, I would think either `&` or `&&` 
> are viable options.
> 
> `if (ch >= 0 & ch <= 0xFF) {`
> 
> I ask just for the sake of my own learning on this topic as it relates to 
> performance as opposed to code readability preferences.

Both choices of operators en up with identical generated code on my Intel Mac.

For reference, I did a comparison between the generated code for the current 
code, and the one in this PR:

Current generated code start like this:


movl            %eax, -0x14000(%rsp)
pushq           %rbp
subq            $0x20, %rsp
cmpl            $1, 0x20(%r15)
jne             0x119cae072
movl            %esi, %r11d
shrl            $8, %r11d
testl           %r11d, %r11d
jne             0x119cae043
movabsq         $0x70fe03c90, %rax  ;   {oop(a 
'java/lang/CharacterDataLatin1'{0x000000070fe03c90})}
``` 

While the PR generated code starts like this:


movl            %eax, -0x14000(%rsp)
pushq           %rbp
subq            $0x20, %rsp
cmpl            $1, 0x20(%r15)
jne             0x1171d41f2
nopw            (%rax, %rax)
cmpl            $0x100, %esi
jae             0x1171d41c5
movabsq         $0x70fe03c90, %rax  ;   {oop(a 
'java/lang/CharacterDataLatin1'{0x000000070fe03c90})}


The rest of the code seems identical.

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

PR: https://git.openjdk.org/jdk/pull/13040

Reply via email to