I have the following two repro methods along with their x64 codegen using the latest RyuJIT.
[MethodImpl(MethodImplOptions.NoInlining)]
public static bool MethodFoo(byte x)
{
return ((byte)x < 128);
}
ConsoleApp12!ConsoleApp12.Program.MethodFoo(Byte):
00007ffe`2cb01630 80f980 cmp cl,80h
00007ffe`2cb01633 0f92c0 setb al
00007ffe`2cb01636 0fb6c0 movzx eax,al
00007ffe`2cb01639 c3 ret
[MethodImpl(MethodImplOptions.NoInlining)]
public static bool MethodBar(byte x)
{
return ((sbyte)x < -64);
}
ConsoleApp12!ConsoleApp12.Program.MethodBar(Byte):
00007ffe`2cb01650 0fb6c1 movzx eax,cl
00007ffe`2cb01653 480fbec0 movsx rax,al
00007ffe`2cb01657 83f8c0 cmp eax,0FFFFFFC0h
00007ffe`2cb0165a 0f9cc0 setl al
00007ffe`2cb0165d 0fb6c0 movzx eax,al
00007ffe`2cb01660 c3 ret
The Foo method checks to see if the high bit is clear, and the Bar method checks to see if the byte has input pattern 10xxxxxx. These are both common operations when performing UTF-8 text processing. In the examples above, the Bar method has suboptimal codegen. I would instead expect the codegen to be the following.
cmp cl,C0h
setl al
movzx eax,al
ret
category:cq
theme:basic-cq
skill-level:intermediate
cost:small
I have the following two repro methods along with their x64 codegen using the latest RyuJIT.
The Foo method checks to see if the high bit is clear, and the Bar method checks to see if the byte has input pattern
10xxxxxx. These are both common operations when performing UTF-8 text processing. In the examples above, the Bar method has suboptimal codegen. I would instead expect the codegen to be the following.category:cq
theme:basic-cq
skill-level:intermediate
cost:small