dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.98k stars 4.66k forks source link

[API Proposal]: x86 PREFETCHW Intrinsics #106863

Open MineCake147E opened 3 weeks ago

MineCake147E commented 3 weeks ago

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

Risks

Nothing more than one for existing *.Prefetch* instructions

dotnet-policy-service[bot] commented 3 weeks ago

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