Skip to content

[API Proposal]: x86 PREFETCHW Intrinsics #106863

Open

Description

@MineCake147E

Background and motivation

AMD introduced 3DNow! in its K6-2, with PREFETCHW instruction that prefetches the specified memory region into the processor's cache while invalidating other cached copies, with the intention of overwriting there in the future.
Almost all instructions in 3DNow! are now deprecated in favor of SSE, but PREFETCH and PREFETCHW still remain and are implemented in Zen4.
Intel also started supporting PREFETCHW from CedarMill by treating them as NOP, and they even started actually implementing these functionalities since Broadwell.
It's nice to have support for PREFETCHW instruction, since we have one for Sse.Prefetch*.

API Proposal

namespace System.Runtime.Intrinsics.X86;

public abstract class PrefetchW : X86Base
{
    public static bool IsSupported { get; }
    public static unsafe void PrefetchWrite(void* address);

    public abstract class X64 : X86Base.X64
    {
        public static bool IsSupported { get; }
    }
}

API Usage

// Somewhere in a class
private uint v;

// In a function
PrefetchW.PrefetchWrite(Unsafe.AsPointer(ref v));
// some instructions
if (p < 0) v++;

Alternative Designs

  • Adding equivalent functions with scoped ref readonly T instead of void* would be fine since it shouldn't throw anything, even the read access to the same address would result in an AccessViolationException.

Risks

Nothing more than one for existing *.Prefetch* instructions

Activity

  1. added
    api-suggestion
    on Aug 23, 2024
  2. added
    untriaged
    on Aug 23, 2024
  3. dotnet-policy-service commented on Aug 23, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-runtime-intrinsics
    See info in area-owners.md if you want to be subscribed.

  4. added this to the Future milestone on Sep 17, 2024
  5. added
    needs-further-triage
    and removed
    untriaged
    on Sep 17, 2024
  6. touitou-dan commented on Jun 23, 2026

    @touitou-dan

    For anyone following this: I've opened a collection-level proposal that's a direct consumer of x86 prefetch intrinsics: batched + software-prefetch lookups and enumeration for large Dictionary / ImmutableDictionary: │ #129513.
    It uses Sse.Prefetch0 today; sharing as a concrete motivating use case for richer managed prefetch support. Measured roughly 2–3x on memory-bound workloads at 10M entries

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

    api-suggestionarea-System.Runtime.Intrinsicsneeds-further-triage

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions