Skip to content

Rework the safe_wrappers feature / downcasting ability #166

Closed

Description

@valadaptive

There's a proof-of-concept safe_wrappers feature that's supposed to let you use your own custom architecture-specific SIMD code if you want to, by obtaining an architecture-specific SIMD token from Level using as_neon, as_avx2, etc.

This isn't the ideal abstraction for a couple reasons:

  1. You need to pass the Level all the way down into every SIMD function you use.
  2. The as_[platform] methods on Level incur a runtime cost. When a SIMD-using function calls some method on the Simd token it's passed, that token's type is statically known, because it's a type parameter. Level, however, is always an enum.

I think #108 starts to move in a different direction, but it creates a lot of autogenerated code, is not fully implemented (WASM is missing), and doesn't actually tie into fearless_simd as implemented. It also seems to have stalled out.

In the meantime, I propose adding as_[platform] methods on the Simd trait itself. The default method implementations would all return None, and individual implementations (Sse4_2, Neon, etc.) could override specific methods to all return Some(self). This means we don't need to pass down the Level, and the new as_[platform] methods would be statically dispatched.

(/cc @DJMcNab; how much does this relate to #108?)

Activity

  1. DJMcNab commented on Jan 7, 2026

    @DJMcNab
    Member

    is not fully implemented (WASM is missing)

    So, #108 can't change anything about WASM, because the SIMD level is always global on WASM.
    It is the case that it's not implemented for aarch64 (to be specific, the core abstraction works for all platforms, but the).

    doesn't actually tie into fearless_simd as implemented.

    Yes, that's correct; I still believe that the abstraction is valuable for consumers of Fearless SIMD, but I'm less certain about my prior comments around using it to implement Fearless SIMD itself; I do suspect that the overhead would be too much. Ideally, of course, rustc would just give us rust-lang/rfcs#3820 (which is implemented in rust-lang/rust#145573), making that need moot.

    It also seems to have stalled out.

    I've just revisited it as part of writing this comment, and realised that this stalling out is my fault. Hopefully we can get it back into gear now.


    I'm in favour of the proposed as_platform methods. Those wouldn't be needed in a world with #108 (or at least, the natural extension to it), but that could take a while to actually get moving.

  2. Shnatsel commented on Jun 18, 2026

    @Shnatsel
    Contributor

    Fulfilled by #214 and #216

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions