Skip to content

Add prefetch support for Windows on X64 and AArch64#56

Closed
raneashay wants to merge 1 commit intomicrosoft:mainfrom
raneashay:ashay/fix-windows-prefetch
Closed

Add prefetch support for Windows on X64 and AArch64#56
raneashay wants to merge 1 commit intomicrosoft:mainfrom
raneashay:ashay/fix-windows-prefetch

Conversation

@raneashay
Copy link
Copy Markdown

This patch largely mimics the prefetch support for Linux on X64 and
AArch64 to apply for Windows. One key change, however, is that instead
of using inline assembly, which isn't supported by MSVC, this patch uses
compiler builtins (__prefetch2() on AArch64 and _mm_prefetch() on
X64).

This patch largely mimics the prefetch support for Linux on X64 and
AArch64 to apply for Windows.  One key change, however, is that instead
of using inline assembly, which isn't supported by MSVC, this patch uses
compiler builtins (`__prefetch2()` on AArch64 and `_mm_prefetch()` on
X64).

inline void Prefetch::read (const void *loc, intx interval) {
if (interval >= 0) {
__prefetch2((const char*) loc + interval, /* PLD + L1 + KEEP */ 0);
Copy link
Copy Markdown
Author

@raneashay raneashay Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirm whether loc and interval should be added and whether this initiates the prefetch or ensures that it is completed before the call returns.

#include <xmmintrin.h>

inline void Prefetch::read (const void *loc, intx interval) {
_mm_prefetch((const char*) loc + interval, _MM_HINT_T0);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding the condition interval >= 0.

@raneashay
Copy link
Copy Markdown
Author

Create a JMH benchmark to demonstrate improvement.

@raneashay raneashay closed this Mar 31, 2026
@raneashay raneashay deleted the ashay/fix-windows-prefetch branch March 31, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant