‹ BackHN Continuity

Thread

Fearless SIMD v1.0

318 points · 52 comments · verdagon

  1. modulovalue · · focus · HN ↗
    I’m currently working on adding better SIMD support to Dart (<a href="https:&#x2F;&#x2F;github.com&#x2F;dart-lang&#x2F;sdk&#x2F;issues&#x2F;64170" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dart-lang&#x2F;sdk&#x2F;issues&#x2F;64170) and I have a question for the author or others here.

    Does Rust or any other language support customizing the compiler so that interprocedural analyses can track custom subsets of, for example, doubles so that the compiler can choose the most efficient instruction sequence for example for min&#x2F;max? If we know a double is never NaN then we can emit only one instruction on x86, but have to emit one more on arm64. If we know a double is never zero and never NaN, we can emit a single instruction on both.

    This whole conversation between relaxed SIMD and deterministic SIMD seems to only exist because our compilers are not smart enough and&#x2F;or their whole program analyses don’t support any plugin-like capabilities.

    There are other examples where if we know a SIMD bitmask is canonical (all 1s per lane) then we can implement horizontal reductions more efficiently. This is very niche and I doubt that any language supports interprocedural analyses with such a rich domain, so it feels like a hole in the programming language space.

    1. athrowaway3z · · focus · HN ↗
      Last time i checked; no.

      But I suspect you&#x27;re overvaluing the potential savings. Knowing when a float is 0.0 or NaN beforehand is almost entirely impossible, except for the most trivial of cases - like when you first initialize a variable or first enter a loop. Everything after that is very hard or impossible with floats as they are.

      Those cases can be const folded at compile time.

      Those cases are never a measurable bottleneck.

      The closest thing I know of in the realm of the optimization you&#x27;re curious about is Rust NonZero* variants, but they&#x27;re used for enum compression afaik.

      1. modulovalue · · focus · HN ↗
        I’m not sure I agree on the impossible part, I feel like a sufficiently smart interprocedural analysis that also implements range analysis interprocedurally could prove a lot to where it becomes useful.

        I guess what I would like to see is SIMD libraries being able to confidently say nobody needs to use intrinsics (or differentiate between relaxed&#x2F;normal SIMD on the user API level) because the language + high level SIMD APIs are smart enough to choose the right implementation.

        IIRC IEEE min&#x2F;max with proper NaN handling needs 8 instructions on x86 vs 1 on arm64 I find it very sad that we apparently haven’t really solved that yet without forcing the user to use different APIs.

        1. nnevatie · · focus · HN ↗
          &gt; nobody needs to use intrinsics

          Funnily enough, intrinsics have become almost trivial to write, with agentic tooling. I used to be an ISPC advocate but now I&#x27;m finding myself gravitate to direct use of intrinsics with bespoke dynamic&#x2F;runtime dispatching more than ever.

          1. janwas · · focus · HN ↗
            +1 on agents making library&#x2F;DIY a lot more attractive than bespoke compilers.

            In C++, one can also have portable intrinsics plus simpler runtime dispatching using our Highway library :)

            1. nnevatie · · focus · HN ↗
              &gt; using our Highway library

              Yes, Highway is pretty nice but also quite elaborate when it comes to dealing with multiple vectorized versions and dispatch. The macros burn my eyes still.

              1. janwas · · focus · HN ↗
                :) Yeah, those are best copy-pasted from existing code.

                I do think we&#x27;ve converged on the best that&#x27;s possible in C++.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.