Skip to content

[API Proposal]: x86 PREFETCHW Intrinsics #106863

Open
@MineCake147E

Description

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

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

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Runtime.Intrinsicsneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions