-
-
Save EgorBo/88196a218559ec93a197a7d1d5600548 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <chrono> | |
// clang++ apple-silicon-ldp-repro.cpp -O2 -o ldp && ./ldp | |
// uncomment to use ldp: | |
// | |
//#define USE_LDP | |
__attribute__((noinline)) | |
void Stall(int* ptr) | |
{ | |
for (int i=0; i<1000000000; i++) | |
{ | |
int tmp1, tmp2; | |
__asm__ volatile( | |
#ifdef USE_LDP | |
"ldp %w0, %w1, [%2]\n" | |
#else | |
// same, but without ldp: | |
"ldr %w0, [%2]\n" | |
"ldr %w1, [%2, #4]\n" | |
#endif | |
"str %w0, [%2]\n" | |
"str %w1, [%2, #4]\n" | |
// NOTE: stp also ruins perf | |
: "=&r" (tmp1), "=&r" (tmp2) | |
: "r" (ptr) | |
: | |
); | |
} | |
} | |
int main() | |
{ | |
int data[64]; | |
while (true) | |
{ | |
using namespace std::chrono; | |
auto start = high_resolution_clock::now(); | |
Stall(data); | |
auto stop = high_resolution_clock::now(); | |
double elapsed = duration_cast<milliseconds>(stop - start).count() / 1000.0; | |
printf("it took: %f ms.\n", elapsed); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment