Open
Description
opened on Aug 23, 2024
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 ofvoid*
would be fine since it shouldn't throw anything, even the read access to the same address would result in anAccessViolationException
.
Risks
Nothing more than one for existing *.Prefetch*
instructions
Activity