-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand String.EndsWith/MemoryExtensions.EndsWith in JIT #98593
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsIt turns out it's not difficult to extend the existing
const string corelib = "System.Private.CoreLib.dll";
bool Test() => str.EndsWith(corelib, StringComparison.OrdinalIgnoreCase);
// Same for Span<char>/ReadOnlySpan<char> APIs Old codegen:; Assembly listing for method Program:Test
mov rdx, 0x20D80109480 ; 'System.Private.CoreLib.dll'
mov r8d, 5
cmp dword ptr [rcx], ecx
tail.jmp [System.String:EndsWith(System.String,int):ubyte:this] New codegen:; Assembly listing for method Program:Test
cmp dword ptr [rcx+0x08], 26
jl SHORT G_M64019_IG04
mov eax, dword ptr [rcx+0x08]
lea rax, bword ptr [rcx+2*rax-0x34]
vmovups ymm0, ymmword ptr [rax+0x0C]
vpor ymm0, ymm0, ymmword ptr [reloc @RWD00]
vpxor ymm0, ymm0, ymmword ptr [reloc @RWD32]
vmovups ymm1, ymmword ptr [rax+0x20]
vpor ymm1, ymm1, ymmword ptr [reloc @RWD64]
vpxor ymm1, ymm1, ymmword ptr [reloc @RWD96]
vpor ymm0, ymm1, ymm0
vptest ymm0, ymm0
sete al
movzx rax, al
jmp SHORT G_M64019_IG05
G_M64019_IG04:
xor eax, eax
G_M64019_IG05:
movzx rax, al
vzeroupper
ret
RWD00 dq 0020002000200020h, 0020000000200020h, ...
RWD32 dq 0074007300790073h, 0070002E006D0065h, ...
RWD64 dq 0020002000200020h, 0020002000200000h, ...
RWD96 dq 0065007400610076h, 0072006F0063002Eh, ...
|
@AndyAyersMS @jakobbotsch @dotnet/jit-contrib PTAL. Simple change to extend |
Actually, some of the unrolling can probably be removed entirely since we already have a generic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM otherwise
Co-authored-by: Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>
CI Failure is #98406 |
It turns out it's not difficult to extend the existing
*.StartsWith
expansion to cover*.EndsWith
as well. Example:Old codegen:
New codegen: