Skip to content

Commit d5832a5

Browse files
Add RhpResolveInterfaceMethodFast for all platforms
Add unoptimized implementations of RhpResolveInterfaceMethodFast for platforms that were missing it: Windows i386, Linux amd64, Linux arm64, Linux arm32, Linux loongarch64, and Linux riscv64. Each implementation performs a null check (triggering an AV that EHHelpers translates to NullReferenceException) then falls through to RhpCidResolve via RhpUniversalTransitionTailCall, matching the established RhpInterfaceDispatchSlow pattern for the platform. ARM32 omits the null check due to register pressure (no free scratch register), consistent with its existing RhpInitialDynamicInterfaceDispatch. The CMakeLists.txt entry is moved from a conditional block (Windows amd64/arm64 only) to the unconditional RUNTIME_SOURCES_ARCH_ASM list. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 05d32f8 commit d5832a5

7 files changed

Lines changed: 140 additions & 8 deletions

File tree

src/coreclr/nativeaot/Runtime/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ endif (CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_AMD64)
223223

224224
list(APPEND RUNTIME_SOURCES_ARCH_ASM
225225
${RUNTIME_DIR}/${ARCH_SOURCES_DIR}/AllocFast.${ASM_SUFFIX}
226+
${ARCH_SOURCES_DIR}/DispatchResolve.${ASM_SUFFIX}
226227
${ARCH_SOURCES_DIR}/ExceptionHandling.${ASM_SUFFIX}
227228
${ARCH_SOURCES_DIR}/GcProbe.${ASM_SUFFIX}
228229
${ARCH_SOURCES_DIR}/MiscStubs.${ASM_SUFFIX}
@@ -233,14 +234,6 @@ list(APPEND RUNTIME_SOURCES_ARCH_ASM
233234
${RUNTIME_DIR}/${ARCH_SOURCES_DIR}/WriteBarriers.${ASM_SUFFIX}
234235
)
235236

236-
if(CLR_CMAKE_TARGET_WIN32)
237-
if (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
238-
list(APPEND RUNTIME_SOURCES_ARCH_ASM
239-
${ARCH_SOURCES_DIR}/DispatchResolve.${ASM_SUFFIX}
240-
)
241-
endif()
242-
endif()
243-
244237
# Add architecture specific folder for looking up headers.
245238
convert_to_absolute_path(ARCH_SOURCES_DIR ${ARCH_SOURCES_DIR})
246239
include_directories(${ARCH_SOURCES_DIR})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
.intel_syntax noprefix
5+
#include <unixasmmacros.inc>
6+
7+
LEAF_ENTRY RhpResolveInterfaceMethodFast, _TEXT
8+
9+
// Load the MethodTable from the object instance in rdi.
10+
// Trigger an AV if we're dispatching on a null this.
11+
// The exception handling infrastructure is aware of the fact that this is the first
12+
// instruction of RhpResolveInterfaceMethodFast and uses it to translate an AV here
13+
// to a NullReferenceException at the callsite.
14+
mov r10, [rdi]
15+
16+
// r11 currently contains the indirection cell address.
17+
lea r10, [C_VAR(RhpCidResolve)]
18+
jmp C_FUNC(RhpUniversalTransitionTailCall)
19+
20+
LEAF_END RhpResolveInterfaceMethodFast, _TEXT
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
.syntax unified
5+
.thumb
6+
7+
#include <unixasmmacros.inc>
8+
9+
LEAF_ENTRY RhpResolveInterfaceMethodFast, _TEXT
10+
11+
// r12 contains the indirection cell address.
12+
// Store it in the red zone for the universal transition thunk.
13+
str r12, [sp, #-8]
14+
PREPARE_EXTERNAL_VAR RhpCidResolve, r12
15+
str r12, [sp, #-4]
16+
17+
b C_FUNC(RhpUniversalTransitionTailCall)
18+
19+
LEAF_END RhpResolveInterfaceMethodFast, _TEXT
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#include <unixasmmacros.inc>
5+
6+
LEAF_ENTRY RhpResolveInterfaceMethodFast, _TEXT
7+
8+
// Load the MethodTable from the object instance in x0.
9+
// Trigger an AV if we're dispatching on a null this.
10+
// The exception handling infrastructure is aware of the fact that this is the first
11+
// instruction of RhpResolveInterfaceMethodFast and uses it to translate an AV here
12+
// to a NullReferenceException at the callsite.
13+
ldr x12, [x0]
14+
15+
// x11 currently contains the indirection cell address.
16+
PREPARE_EXTERNAL_VAR RhpCidResolve, xip0
17+
mov xip1, x11
18+
b C_FUNC(RhpUniversalTransitionTailCall)
19+
20+
LEAF_END RhpResolveInterfaceMethodFast, _TEXT
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
;; Licensed to the .NET Foundation under one or more agreements.
2+
;; The .NET Foundation licenses this file to you under the MIT license.
3+
4+
.586
5+
.model flat
6+
option casemap:none
7+
.code
8+
9+
include AsmMacros.inc
10+
11+
EXTERN RhpCidResolve : PROC
12+
EXTERN _RhpUniversalTransitionTailCall@0 : PROC
13+
14+
FASTCALL_FUNC RhpResolveInterfaceMethodFast, 0
15+
ALTERNATE_ENTRY _RhpResolveInterfaceMethodFast
16+
17+
;; Trigger an AV if we're dispatching on a null this.
18+
;; The exception handling infrastructure is aware of the fact that this is the first
19+
;; instruction of RhpResolveInterfaceMethodFast and uses it to translate an AV here
20+
;; to a NullReferenceException at the callsite.
21+
cmp dword ptr [ecx], ecx
22+
23+
;; eax currently contains the indirection cell address.
24+
;; Setup call to Universal Transition thunk
25+
push ebp
26+
mov ebp, esp
27+
push eax
28+
lea eax, [RhpCidResolve]
29+
push eax
30+
31+
jmp _RhpUniversalTransitionTailCall@0
32+
33+
FASTCALL_ENDFUNC
34+
35+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#include <unixasmmacros.inc>
5+
6+
LEAF_ENTRY RhpResolveInterfaceMethodFast, _TEXT
7+
8+
// Load the MethodTable from the object instance in a0.
9+
// Trigger an AV if we're dispatching on a null this.
10+
// The exception handling infrastructure is aware of the fact that this is the first
11+
// instruction of RhpResolveInterfaceMethodFast and uses it to translate an AV here
12+
// to a NullReferenceException at the callsite.
13+
ld.d $zero, $a0, 0
14+
15+
// $t8 currently contains the indirection cell address.
16+
// Calling convention of the universal thunk is:
17+
// $t7: target address for the thunk to call
18+
// $t8: parameter of the thunk's target
19+
PREPARE_EXTERNAL_VAR RhpCidResolve, $t7
20+
b C_FUNC(RhpUniversalTransitionTailCall)
21+
22+
LEAF_END RhpResolveInterfaceMethodFast, _TEXT
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#include <unixasmmacros.inc>
5+
6+
LEAF_ENTRY RhpResolveInterfaceMethodFast, _TEXT
7+
8+
// Load the MethodTable from the object instance in a0.
9+
// Trigger an AV if we're dispatching on a null this.
10+
// The exception handling infrastructure is aware of the fact that this is the first
11+
// instruction of RhpResolveInterfaceMethodFast and uses it to translate an AV here
12+
// to a NullReferenceException at the callsite.
13+
ld zero, 0(a0)
14+
15+
// t5 currently contains the indirection cell address.
16+
// Calling convention of the universal thunk is:
17+
// t0: target address for the thunk to call
18+
// t1: parameter of the thunk's target
19+
PREPARE_EXTERNAL_VAR RhpCidResolve, t0
20+
mv t1, t5
21+
tail C_FUNC(RhpUniversalTransitionTailCall)
22+
23+
LEAF_END RhpResolveInterfaceMethodFast, _TEXT

0 commit comments

Comments
 (0)