You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CastHelpers.IsInstanceOfInterface and CastHelpers.ChkCastInterface scan the MethodTable interface map using an unrolled scalar loop. For types with larger interface maps, the scan is a sequence of independent pointer comparisons that may be suitable for SIMD.
For example, a 128-bit vector can compare two 64-bit interface MethodTable pointers at once on 64-bit targets, and a 256-bit AVX2 vector can compare four. Wasm SIMD and Arm64 AdvSimd provide analogous 128-bit operations.
Proposal
Investigate a vectorized interface-map scan using the portable Vector128/Vector256 APIs where possible, while retaining the scalar path for small maps and unsupported targets.
A safe and efficient implementation may require changing interface-map allocation/layout so that vector loads cannot read beyond the allocation. Options include vector-width padding with a sentinel value that cannot match a valid MethodTable, or a scalar/masked tail. Alignment guarantees should be evaluated, but unaligned vector loads may be sufficient on supported targets.
The same shared scan should serve both IsInstanceOfInterface and ChkCastInterface so their fast paths remain consistent.
Validation
Benchmark small and large interface maps; SIMD setup can lose for common small maps.
Measure x64 with SSE2/AVX2, Arm64, and Wasm SIMD where available.
Run with hardware intrinsics disabled to validate the scalar fallback.
Add boundary tests, ideally using guarded memory, for counts around each vector width and non-multiple tails.
Verify that padding or sentinel choices cannot be mistaken for a valid interface MethodTable and do not break interface-map consumers.
Background
CastHelpers.IsInstanceOfInterfaceandCastHelpers.ChkCastInterfacescan the MethodTable interface map using an unrolled scalar loop. For types with larger interface maps, the scan is a sequence of independent pointer comparisons that may be suitable for SIMD.For example, a 128-bit vector can compare two 64-bit interface MethodTable pointers at once on 64-bit targets, and a 256-bit AVX2 vector can compare four. Wasm SIMD and Arm64 AdvSimd provide analogous 128-bit operations.
Proposal
Investigate a vectorized interface-map scan using the portable
Vector128/Vector256APIs where possible, while retaining the scalar path for small maps and unsupported targets.A safe and efficient implementation may require changing interface-map allocation/layout so that vector loads cannot read beyond the allocation. Options include vector-width padding with a sentinel value that cannot match a valid MethodTable, or a scalar/masked tail. Alignment guarantees should be evaluated, but unaligned vector loads may be sufficient on supported targets.
The same shared scan should serve both
IsInstanceOfInterfaceandChkCastInterfaceso their fast paths remain consistent.Validation
Note
This issue was drafted with GitHub Copilot.