-
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
Remove invalid Unsafe.As from array helpers #99778
Conversation
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs
Outdated
Show resolved
Hide resolved
|
What's the |
I think we build |
Do we want to cleanup the code then and remove those paths later (and keep it as is for now)? Or should I also change the |
Any of these options is fine with me. |
Is the code for helper same or better with this change? |
The codegen for normal path is almost the same (the operands for G_M56901_IG04:
- call CORINFO_HELP_RNGCHKFAIL
- ;; size=5 bbWeight=0 PerfScore 0.00
-G_M56901_IG05:
mov rax, 0xD1FFAB1E ; code for System.Runtime.CompilerServices.CastHelpers:ThrowArrayMismatchException():byref
call [rax]System.Runtime.CompilerServices.CastHelpers:ThrowArrayMismatchException():byref
+ ;; size=12 bbWeight=0 PerfScore 0.00
+G_M56901_IG05:
+ mov rax, 0xD1FFAB1E ; code for System.Runtime.CompilerServices.CastHelpers:ThrowIndexOutOfRangeException()
+ call [rax]System.Runtime.CompilerServices.CastHelpers:ThrowIndexOutOfRangeException()
int3
;; size=13 bbWeight=0 PerfScore 0.00 |
@jkotas Do you know what's going on with the CI refusing to run pipelines on PRs as of recently? |
Yes, it is broken. The people responsible for our eng system are not on-call during the weekend, so it may take till Monday to resolve. It actually runs them, just the github status is not updating. For example, here is the pipeline link for this PR |
|
||
#if INPLACE_RUNTIME | ||
if ((nuint)index >= (uint)array.Length) | ||
ThrowIndexOutOfRangeException(array); |
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.
This can just use ThrowHelper.ThrowIndexOutOfRangeException
given that is for INPLACE_RUNTIME
. It is unnecessary to go through GetClasslibException
indirection for INPLACE_RUNTIME
. The main point of INPLACE_RUNTIME
is to avoid these indirections.
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.
I wanted to remove the !INPLACE_RUNTIME
code in the next PR and to keep this like earlier for now.
Also I think that ThrowHelper
is not in the Test.CoreLib
(not sure what that is for tbh but right now there's a build failure here due to MemoryMarshal
not being there too).
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.
Test.CoreLib is very minimal implementation of CoreLib for testing, debugging and various experiments. It is fine to add minimal implementations of MemoryMarshal or ThrowHelper to it to keep it working.
...System.Private.Reflection.Execution/src/Internal/Reflection/Execution/TypeLoader/TypeCast.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@jkotas This caused |
Does it affect performance of any of the fast paths?
|
Ah wait nevermind, I've accidentally diffed The non cached one being inlined is the only difference now then: MihuBot/runtime-utils#332 (comment) |
I wonder what the problem would be. Is there any context? |
|
@MichalPetryka Did you have a chance to check the perf impact of these changes? |
I'll do so today. |
@jkotas I've benchmarked with Full codegen: .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI; ConsoleApp7.Benchmark.WriteNull(System.String)
push rdi
push rsi
push rbp
push rbx
sub rsp,28
mov rbx,rdx
mov rsi,[rcx+8]
xor edi,edi
mov ebp,[rsi+8]
test ebp,ebp
jle short M00_L01
M00_L00:
movsxd rdx,edi
mov rcx,rsi
mov r8,rbx
call System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Array, IntPtr, System.Object)
inc edi
cmp ebp,edi
jg short M00_L00
M00_L01:
add rsp,28
pop rbx
pop rbp
pop rsi
pop rdi
ret
; Total bytes of code 53 ; System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Array, IntPtr, System.Object)
sub rsp,28
mov eax,[rcx+8]
cmp rdx,rax
jae short M01_L02
lea rax,[rcx+rdx*8+10]
mov rdx,[rcx]
mov rdx,[rdx+38]
test r8,r8
jne short M01_L00
xor ecx,ecx
mov [rax],rcx
add rsp,28
ret
M01_L00:
cmp rdx,[r8]
je short M01_L01
mov r10,offset MT_System.Object[]
cmp [rcx],r10
je short M01_L01
mov rcx,rax
add rsp,28
jmp qword ptr [7FFB68CB4498]; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper(System.Object ByRef, Void*, System.Object)
M01_L01:
mov rcx,rax
mov rdx,r8
add rsp,28
jmp near ptr System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
M01_L02:
call CORINFO_HELP_RNGCHKFAIL
int 3
; Total bytes of code 93 ; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper(System.Object ByRef, Void*, System.Object)
push rdi
push rsi
push rbx
sub rsp,20
mov rdi,rcx
mov rbx,rdx
mov rsi,r8
mov rcx,290F9800B80
mov rcx,[rcx]
mov rax,[rsi]
add rcx,10
rorx rdx,rax,20
xor rdx,rbx
mov r8,9E3779B97F4A7C15
imul rdx,r8
mov r8d,[rcx]
shrx rdx,rdx,r8
xor r8d,r8d
M02_L00:
lea r10d,[rdx+1]
movsxd r10,r10d
lea r10,[r10+r10*2]
lea r10,[rcx+r10*8]
mov r9d,[r10]
mov r11,[r10+8]
and r9d,0FFFFFFFE
cmp r11,rax
jne short M02_L01
mov r11,rbx
xor r11,[r10+10]
cmp r11,1
jbe short M02_L02
M02_L01:
test r9d,r9d
je short M02_L03
inc r8d
add edx,r8d
and edx,[rcx+4]
cmp r8d,8
jl short M02_L00
jmp short M02_L03
M02_L02:
cmp r9d,[r10]
jne short M02_L03
cmp r11d,1
jne short M02_L03
mov rcx,7FFB69DC54C8
call CORINFO_HELP_COUNTPROFILE32
mov rcx,rdi
mov rdx,rsi
call System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
nop
add rsp,20
pop rbx
pop rsi
pop rdi
ret
M02_L03:
mov rcx,7FFB69DC54CC
call CORINFO_HELP_COUNTPROFILE32
mov rcx,rdi
mov rdx,rbx
mov r8,rsi
call qword ptr [7FFB68CB44B0]; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper_NoCacheLookup(System.Object ByRef, Void*, System.Object)
nop
add rsp,20
pop rbx
pop rsi
pop rdi
ret
; Total bytes of code 221 ; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper_NoCacheLookup(System.Object ByRef, Void*, System.Object)
push rdi
push rsi
push rbx
sub rsp,20
mov rsi,rcx
mov rdi,rdx
mov rbx,r8
test rbx,rbx
jne short M03_L00
mov rdx,2D18E150008
mov rcx,rdx
call qword ptr [7FFB68D1D3B0]
M03_L00:
mov rcx,rdi
mov rdx,rbx
call System.Runtime.CompilerServices.CastHelpers.IsInstanceOfAny_NoCacheLookup(Void*, System.Object)
mov rbx,rax
test rbx,rbx
je short M03_L01
mov rcx,rsi
mov rdx,rbx
add rsp,20
pop rbx
pop rsi
pop rdi
jmp near ptr System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
M03_L01:
mov rcx,offset MT_System.ArrayTypeMismatchException
call CORINFO_HELP_NEWSFAST
mov rbx,rax
mov rcx,rbx
call qword ptr [7FFB69827C78]
mov rcx,rbx
call CORINFO_HELP_THROW
int 3
; Total bytes of code 113 Extern method .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI; ConsoleApp7.Benchmark.WriteNull(System.String)
push rdi
push rsi
push rbp
push rbx
sub rsp,28
mov rbx,rdx
mov rsi,[rcx+8]
xor edi,edi
mov ebp,[rsi+8]
test ebp,ebp
jle short M00_L01
M00_L00:
movsxd rdx,edi
mov rcx,rsi
mov r8,rbx
call System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Object[], IntPtr, System.Object)
inc edi
cmp ebp,edi
jg short M00_L00
M00_L01:
add rsp,28
pop rbx
pop rbp
pop rsi
pop rdi
ret
; Total bytes of code 53 ; System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Object[], IntPtr, System.Object)
sub rsp,28
mov eax,[rcx+8]
cmp rax,rdx
jbe short M01_L01
lea rax,[rcx+rdx*8+10]
mov rdx,[rcx]
mov rdx,[rdx+30]
test r8,r8
jne short M01_L02
xor ecx,ecx
mov [rax],rcx
add rsp,28
ret
M01_L00:
mov r10,offset MT_System.Object[]
cmp [rcx],r10
je short M01_L03
mov rcx,rax
add rsp,28
jmp qword ptr [7FFB6BDB44B0]; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper(System.Object ByRef, Void*, System.Object)
M01_L01:
call qword ptr [7FFB6BDB4450]
int 3
M01_L02:
cmp rdx,[r8]
jne short M01_L00
M01_L03:
mov rcx,rax
mov rdx,r8
add rsp,28
jmp near ptr System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
; Total bytes of code 94 ; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper(System.Object ByRef, Void*, System.Object)
push rdi
push rsi
push rbx
sub rsp,20
mov rdi,rcx
mov rbx,rdx
mov rsi,r8
call qword ptr [7FFBC8B31840]
mov rdx,[rax+0B50]
mov rax,[rsi]
add rdx,10
mov r8,rax
rol r8,20
xor r8,rbx
mov r10,9E3779B97F4A7C15
imul r8,r10
mov ecx,[rdx]
shr r8,cl
xor ecx,ecx
M02_L00:
lea r10d,[r8+1]
movsxd r10,r10d
lea r10,[r10+r10*2]
lea r10,[rdx+r10*8]
mov r9d,[r10]
mov r11,[r10+8]
and r9d,0FFFFFFFE
cmp r11,rax
jne short M02_L01
mov r11,rbx
xor r11,[r10+10]
cmp r11,1
jbe short M02_L02
M02_L01:
test r9d,r9d
je short M02_L03
inc ecx
add r8d,ecx
and r8d,[rdx+4]
cmp ecx,8
jl short M02_L00
jmp short M02_L03
M02_L02:
cmp r9d,[r10]
jne short M02_L03
cmp r11d,1
jne short M02_L03
mov rcx,rdi
mov rdx,rsi
call qword ptr [7FFBC8B4A2A8]; System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
nop
add rsp,20
pop rbx
pop rsi
pop rdi
ret
M02_L03:
mov rcx,rbx
mov rdx,rsi
call qword ptr [7FFBC8B4A288]; System.Runtime.CompilerServices.CastHelpers.IsInstanceOfAny_NoCacheLookup(Void*, System.Object)
test rax,rax
je short M02_L04
mov rcx,rdi
mov rdx,rax
call qword ptr [7FFBC8B4A2A8]; System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
nop
add rsp,20
pop rbx
pop rsi
pop rdi
ret
M02_L04:
call qword ptr [7FFBC8B4A2E0]
int 3
; Total bytes of code 209 Extern method .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI; ConsoleApp7.Benchmark.WriteNull(System.String)
push rdi
push rsi
push rbp
push rbx
sub rsp,28
mov rbx,rdx
mov rsi,[rcx+8]
xor edi,edi
mov ebp,[rsi+8]
test ebp,ebp
jle short M00_L01
M00_L00:
movsxd rdx,edi
mov rcx,rsi
mov r8,rbx
call CORINFO_HELP_ARRADDR_ST
inc edi
cmp ebp,edi
jg short M00_L00
M00_L01:
add rsp,28
pop rbx
pop rbp
pop rsi
pop rdi
ret
; Total bytes of code 53 .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI; ConsoleApp7.Benchmark.WriteToObject(System.String)
push rdi
push rsi
push rbp
push rbx
sub rsp,28
mov rbx,rdx
mov rsi,[rcx+8]
xor edi,edi
mov ebp,[rsi+8]
test ebp,ebp
jle short M00_L01
M00_L00:
movsxd rdx,edi
mov rcx,rsi
mov r8,rbx
call System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Array, IntPtr, System.Object)
inc edi
cmp ebp,edi
jg short M00_L00
M00_L01:
add rsp,28
pop rbx
pop rbp
pop rsi
pop rdi
ret
; Total bytes of code 53 ; System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Array, IntPtr, System.Object)
sub rsp,28
mov eax,[rcx+8]
cmp rdx,rax
jae short M01_L02
lea rax,[rcx+rdx*8+10]
mov rdx,[rcx]
mov rdx,[rdx+38]
test r8,r8
je short M01_L01
cmp rdx,[r8]
je short M01_L00
mov r10,offset MT_System.Object[]
cmp [rcx],r10
jne short M01_L03
M01_L00:
mov rcx,rax
mov rdx,r8
add rsp,28
jmp near ptr System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
M01_L01:
xor ecx,ecx
mov [rax],rcx
add rsp,28
ret
M01_L02:
call CORINFO_HELP_RNGCHKFAIL
M01_L03:
mov rcx,rax
add rsp,28
jmp qword ptr [7FFB68CD4498]; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper(System.Object ByRef, Void*, System.Object)
; Total bytes of code 92 ; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper(System.Object ByRef, Void*, System.Object)
push rdi
push rsi
push rbx
sub rsp,20
mov rdi,rcx
mov rbx,rdx
mov rsi,r8
call qword ptr [7FFBC7912090]
mov rdx,[rax+0B48]
mov r8,[rsi]
add rdx,10
mov rax,r8
rol rax,20
xor rax,rbx
mov r10,9E3779B97F4A7C15
imul rax,r10
mov ecx,[rdx]
shr rax,cl
xor ecx,ecx
M02_L00:
lea r10d,[rax+1]
movsxd r10,r10d
lea r10,[r10+r10*2]
lea r10,[rdx+r10*8]
mov r9d,[r10]
mov r11,[r10+8]
and r9d,0FFFFFFFE
cmp r11,r8
jne short M02_L01
mov r11,rbx
xor r11,[r10+10]
cmp r11,1
jbe short M02_L02
M02_L01:
test r9d,r9d
je short M02_L03
inc ecx
add eax,ecx
and eax,[rdx+4]
cmp ecx,8
jl short M02_L00
jmp short M02_L03
M02_L02:
cmp r9d,[r10]
jne short M02_L03
cmp r11d,1
jne short M02_L03
mov rcx,rdi
mov rdx,rsi
call qword ptr [7FFBC792CD88]; System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
nop
add rsp,20
pop rbx
pop rsi
pop rdi
ret
M02_L03:
mov rcx,rdi
mov rdx,rbx
mov r8,rsi
call qword ptr [7FFBC792CDC8]; Precode of System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper_NoCacheLookup(System.Object ByRef, Void*, System.Object)
nop
add rsp,20
pop rbx
pop rsi
pop rdi
ret
; Total bytes of code 186 Extern method .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI; ConsoleApp7.Benchmark.WriteToObject(System.String)
push rdi
push rsi
push rbp
push rbx
sub rsp,28
mov rbx,rdx
mov rsi,[rcx+8]
xor edi,edi
mov ebp,[rsi+8]
test ebp,ebp
jle short M00_L01
M00_L00:
movsxd rdx,edi
mov rcx,rsi
mov r8,rbx
call System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Object[], IntPtr, System.Object)
inc edi
cmp ebp,edi
jg short M00_L00
M00_L01:
add rsp,28
pop rbx
pop rbp
pop rsi
pop rdi
ret
; Total bytes of code 53 ; System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Object[], IntPtr, System.Object)
sub rsp,28
mov eax,[rcx+8]
cmp rax,rdx
jbe short M01_L02
lea rax,[rcx+rdx*8+10]
mov rdx,[rcx]
mov rdx,[rdx+30]
test r8,r8
je short M01_L01
cmp rdx,[r8]
je short M01_L00
mov r10,offset MT_System.Object[]
cmp [rcx],r10
jne short M01_L03
M01_L00:
mov rcx,rax
mov rdx,r8
add rsp,28
jmp near ptr System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
M01_L01:
xor ecx,ecx
mov [rax],rcx
add rsp,28
ret
M01_L02:
call qword ptr [7FFB68CA4450]
int 3
M01_L03:
mov rcx,rax
add rsp,28
jmp qword ptr [7FFB68CA44B0]; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper(System.Object ByRef, Void*, System.Object)
; Total bytes of code 94 ; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper(System.Object ByRef, Void*, System.Object)
push rdi
push rsi
push rbx
sub rsp,20
mov rdi,rcx
mov rbx,rdx
mov rsi,r8
call qword ptr [7FFBC8661840]
mov rdx,[rax+0B50]
mov rax,[rsi]
add rdx,10
mov r8,rax
rol r8,20
xor r8,rbx
mov r10,9E3779B97F4A7C15
imul r8,r10
mov ecx,[rdx]
shr r8,cl
xor ecx,ecx
M02_L00:
lea r10d,[r8+1]
movsxd r10,r10d
lea r10,[r10+r10*2]
lea r10,[rdx+r10*8]
mov r9d,[r10]
mov r11,[r10+8]
and r9d,0FFFFFFFE
cmp r11,rax
jne short M02_L01
mov r11,rbx
xor r11,[r10+10]
cmp r11,1
jbe short M02_L02
M02_L01:
test r9d,r9d
je short M02_L03
inc ecx
add r8d,ecx
and r8d,[rdx+4]
cmp ecx,8
jl short M02_L00
jmp short M02_L03
M02_L02:
cmp r9d,[r10]
jne short M02_L03
cmp r11d,1
jne short M02_L03
mov rcx,rdi
mov rdx,rsi
call qword ptr [7FFBC867A2A8]; System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
nop
add rsp,20
pop rbx
pop rsi
pop rdi
ret
M02_L03:
mov rcx,rbx
mov rdx,rsi
call qword ptr [7FFBC867A288]; System.Runtime.CompilerServices.CastHelpers.IsInstanceOfAny_NoCacheLookup(Void*, System.Object)
test rax,rax
je short M02_L04
mov rcx,rdi
mov rdx,rax
call qword ptr [7FFBC867A2A8]; System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
nop
add rsp,20
pop rbx
pop rsi
pop rdi
ret
M02_L04:
call qword ptr [7FFBC867A2E0]
int 3
; Total bytes of code 209 Extern method .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI; ConsoleApp7.Benchmark.WriteToObject(System.String)
push rdi
push rsi
push rbp
push rbx
sub rsp,28
mov rbx,rdx
mov rsi,[rcx+8]
xor edi,edi
mov ebp,[rsi+8]
test ebp,ebp
jle short M00_L01
M00_L00:
movsxd rdx,edi
mov rcx,rsi
mov r8,rbx
call CORINFO_HELP_ARRADDR_ST
inc edi
cmp ebp,edi
jg short M00_L00
M00_L01:
add rsp,28
pop rbx
pop rbp
pop rsi
pop rdi
ret
; Total bytes of code 53 .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI; ConsoleApp7.Benchmark.WriteToInterface(System.String)
push rdi
push rsi
push rbp
push rbx
sub rsp,28
mov rbx,rdx
mov rsi,[rcx+10]
xor edi,edi
mov ebp,[rsi+8]
test ebp,ebp
jle short M00_L01
M00_L00:
movsxd rdx,edi
mov rcx,rsi
mov r8,rbx
call System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Array, IntPtr, System.Object)
inc edi
cmp ebp,edi
jg short M00_L00
M00_L01:
add rsp,28
pop rbx
pop rbp
pop rsi
pop rdi
ret
; Total bytes of code 53 ; System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Array, IntPtr, System.Object)
sub rsp,28
mov eax,[rcx+8]
cmp rdx,rax
jae short M01_L00
lea rax,[rcx+rdx*8+10]
mov rdx,[rcx]
mov rdx,[rdx+38]
test r8,r8
je short M01_L02
cmp rdx,[r8]
je short M01_L01
mov r10,offset MT_System.Object[]
cmp [rcx],r10
je short M01_L01
mov rcx,rax
add rsp,28
jmp qword ptr [7FFB68CD4498]; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper(System.Object ByRef, Void*, System.Object)
M01_L00:
call CORINFO_HELP_RNGCHKFAIL
M01_L01:
mov rcx,rax
mov rdx,r8
add rsp,28
jmp near ptr System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
M01_L02:
xor ecx,ecx
mov [rax],rcx
add rsp,28
ret
; Total bytes of code 92 ; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper(System.Object ByRef, Void*, System.Object)
push rdi
push rsi
push rbx
sub rsp,20
mov rax,25A67800B80
mov rax,[rax]
mov r10,[r8]
add rax,10
rorx r9,r10,20
xor r9,rdx
mov r11,9E3779B97F4A7C15
imul r9,r11
mov r11d,[rax]
shrx r9,r9,r11
xor r11d,r11d
M02_L00:
lea ebx,[r9+1]
movsxd rbx,ebx
lea rbx,[rbx+rbx*2]
lea rbx,[rax+rbx*8]
mov esi,[rbx]
mov rdi,[rbx+8]
and esi,0FFFFFFFE
cmp rdi,r10
jne short M02_L01
mov rdi,rdx
xor rdi,[rbx+10]
cmp rdi,1
jbe short M02_L02
M02_L01:
test esi,esi
je short M02_L03
inc r11d
add r9d,r11d
and r9d,[rax+4]
cmp r11d,8
jl short M02_L00
jmp short M02_L03
M02_L02:
cmp esi,[rbx]
jne short M02_L03
cmp edi,1
jne short M02_L03
mov rdx,r8
call System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
nop
add rsp,20
pop rbx
pop rsi
pop rdi
ret
M02_L03:
call qword ptr [7FFB68CD44B0]; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper_NoCacheLookup(System.Object ByRef, Void*, System.Object)
nop
add rsp,20
pop rbx
pop rsi
pop rdi
ret
; Total bytes of code 166 ; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper_NoCacheLookup(System.Object ByRef, Void*, System.Object)
push rdi
push rsi
push rbx
sub rsp,20
mov rsi,rcx
mov rdi,rdx
mov rbx,r8
test rbx,rbx
jne short M03_L00
mov rcx,[7FFBC79636C8]
mov rdx,[rcx]
mov rcx,rdx
call qword ptr [7FFBC79300B8]
M03_L00:
mov rcx,rdi
mov rdx,rbx
call qword ptr [7FFBC792CD68]; System.Runtime.CompilerServices.CastHelpers.IsInstanceOfAny_NoCacheLookup(Void*, System.Object)
mov rbx,rax
test rbx,rbx
je short M03_L01
mov rdx,rbx
mov rcx,rsi
lea rax,[7FFBC792CD90]
add rsp,20
pop rbx
pop rsi
pop rdi
jmp qword ptr [rax]
M03_L01:
call qword ptr [7FFBC791B5E8]
mov rbx,rax
mov rcx,rbx
call qword ptr [7FFBC7924598]
mov rcx,rbx
call qword ptr [7FFBC7911760]; CORINFO_HELP_THROW
int 3
; Total bytes of code 111 Extern method .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI; ConsoleApp7.Benchmark.WriteToInterface(System.String)
push rdi
push rsi
push rbp
push rbx
sub rsp,28
mov rbx,rdx
mov rsi,[rcx+10]
xor edi,edi
mov ebp,[rsi+8]
test ebp,ebp
jle short M00_L01
M00_L00:
movsxd rdx,edi
mov rcx,rsi
mov r8,rbx
call System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Object[], IntPtr, System.Object)
inc edi
cmp ebp,edi
jg short M00_L00
M00_L01:
add rsp,28
pop rbx
pop rbp
pop rsi
pop rdi
ret
; Total bytes of code 53 ; System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Object[], IntPtr, System.Object)
sub rsp,28
mov eax,[rcx+8]
cmp rax,rdx
jbe short M01_L00
lea rax,[rcx+rdx*8+10]
mov rdx,[rcx]
mov rdx,[rdx+30]
test r8,r8
je short M01_L02
cmp rdx,[r8]
je short M01_L01
mov r10,offset MT_System.Object[]
cmp [rcx],r10
je short M01_L01
mov rcx,rax
add rsp,28
jmp qword ptr [7FFB68CC44B0]; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper(System.Object ByRef, Void*, System.Object)
M01_L00:
call qword ptr [7FFB68CC4450]
int 3
M01_L01:
mov rcx,rax
mov rdx,r8
add rsp,28
jmp near ptr System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
M01_L02:
xor ecx,ecx
mov [rax],rcx
add rsp,28
ret
; Total bytes of code 94 ; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper(System.Object ByRef, Void*, System.Object)
push rdi
push rsi
push rbx
sub rsp,20
mov rax,21C53C00B88
mov rax,[rax]
mov r10,[r8]
add rax,10
rorx r9,r10,20
xor r9,rdx
mov r11,9E3779B97F4A7C15
imul r9,r11
mov r11d,[rax]
shrx r9,r9,r11
xor r11d,r11d
M02_L00:
lea ebx,[r9+1]
movsxd rbx,ebx
lea rbx,[rbx+rbx*2]
lea rbx,[rax+rbx*8]
mov esi,[rbx]
mov rdi,[rbx+8]
and esi,0FFFFFFFE
cmp rdi,r10
jne short M02_L01
mov rdi,rdx
xor rdi,[rbx+10]
cmp rdi,1
jbe short M02_L02
M02_L01:
test esi,esi
je short M02_L03
inc r11d
add r9d,r11d
and r9d,[rax+4]
cmp r11d,8
jl short M02_L00
jmp short M02_L03
M02_L02:
cmp esi,[rbx]
jne short M02_L03
cmp edi,1
jne short M02_L03
mov rdx,r8
call System.Runtime.CompilerServices.CastHelpers.WriteBarrier(System.Object ByRef, System.Object)
nop
add rsp,20
pop rbx
pop rsi
pop rdi
ret
M02_L03:
call qword ptr [7FFB68CC44C8]; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper_NoCacheLookup(System.Object ByRef, Void*, System.Object)
nop
add rsp,20
pop rbx
pop rsi
pop rdi
ret
; Total bytes of code 166 ; System.Runtime.CompilerServices.CastHelpers.StelemRef_Helper_NoCacheLookup(System.Object ByRef, Void*, System.Object)
push rbx
sub rsp,20
mov rbx,rcx
mov rax,r8
mov rcx,rdx
mov rdx,rax
call qword ptr [7FFBC867A288]; System.Runtime.CompilerServices.CastHelpers.IsInstanceOfAny_NoCacheLookup(Void*, System.Object)
test rax,rax
je short M03_L00
mov rdx,rax
mov rcx,rbx
lea rax,[7FFBC867A2B0]
add rsp,20
pop rbx
jmp qword ptr [rax]
M03_L00:
call qword ptr [7FFBC867A2E0]
int 3
; Total bytes of code 56 Extern method .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI; ConsoleApp7.Benchmark.WriteToInterface(System.String)
push rdi
push rsi
push rbp
push rbx
sub rsp,28
mov rbx,rdx
mov rsi,[rcx+10]
xor edi,edi
mov ebp,[rsi+8]
test ebp,ebp
jle short M00_L01
M00_L00:
movsxd rdx,edi
mov rcx,rsi
mov r8,rbx
call CORINFO_HELP_ARRADDR_ST
inc edi
cmp ebp,edi
jg short M00_L00
M00_L01:
add rsp,28
pop rbx
pop rbp
pop rsi
pop rdi
ret
; Total bytes of code 53 .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI; ConsoleApp7.Benchmark.WriteToType(System.String)
push rdi
push rsi
push rbp
push rbx
sub rsp,28
mov rbx,rdx
mov rsi,[rcx+18]
xor edi,edi
mov ebp,[rsi+8]
test ebp,ebp
jle short M00_L01
nop dword ptr [rax+rax]
M00_L00:
lea rcx,[rsi+rdi*8+10]
mov rdx,rbx
call CORINFO_HELP_ASSIGN_REF
inc edi
cmp ebp,edi
jg short M00_L00
M00_L01:
add rsp,28
pop rbx
pop rbp
pop rsi
pop rdi
ret
; Total bytes of code 60 .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI; ConsoleApp7.Benchmark.WriteToType(System.String)
push rdi
push rsi
push rbp
push rbx
sub rsp,28
mov rbx,rdx
mov rsi,[rcx+18]
xor edi,edi
mov ebp,[rsi+8]
test ebp,ebp
jle short M00_L01
nop dword ptr [rax+rax]
M00_L00:
lea rcx,[rsi+rdi*8+10]
mov rdx,rbx
call CORINFO_HELP_ASSIGN_REF
inc edi
cmp ebp,edi
jg short M00_L00
M00_L01:
add rsp,28
pop rbx
pop rbp
pop rsi
pop rdi
ret
; Total bytes of code 60 .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI; ConsoleApp7.Benchmark.WriteToType(System.String)
push rdi
push rsi
push rbp
push rbx
mov rbx,rdx
mov rsi,[rcx+18]
xor edi,edi
mov ebp,[rsi+8]
test ebp,ebp
jle short M00_L01
nop dword ptr [rax]
nop dword ptr [rax+rax]
M00_L00:
mov ecx,edi
lea rcx,[rsi+rcx*8+10]
mov rdx,rbx
call CORINFO_HELP_ASSIGN_REF
inc edi
cmp ebp,edi
jg short M00_L00
M00_L01:
pop rbx
pop rbp
pop rsi
pop rdi
ret
; Total bytes of code 58 |
I agree that the cold blocks ordering with PGO can be better in some case. I do not see any material code difference caused by this change. The exact code for these helpers can differ from workload to workload and from run to run depending on how PGO rolls the dice. I have pushed a commit with a minor cleanup as I was looking at the code. |
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.
Thank you!
This probably doesn't cause issues today but it might start to do so when we start inlining helpers.
Causes almost no diffs outside of calling a managed throw helper now.