Skip to content

Investigate SIMD interface-map scans in CastHelpers #134684

Description

@davidwrighton

Background

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.

Note

This issue was drafted with GitHub Copilot.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-VM-coreclrenhancementProduct code improvement that does NOT require public API changes/additionsuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions