-
-
Save compnerd/daa7e68f7b4910cb6b27f856e6c2beba 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
// clang -target riscv64-unknown-linux-gnu -march=rv64gcv -Os %s -o reduced ; ~38s | |
// clang -target riscv64-unknown-linux-gnu -march=rv64gcv -Os -fno-vectorize %s -o reduced ; ~230ms | |
#include <algorithm> | |
#include <iostream> | |
bool z{true}; | |
size_t a{1}; | |
uint32_t b{1}; | |
uint32_t c{1}; | |
inline size_t select() { | |
if (z) return (a + b - 1) / c; | |
return (a - b + 1) / c + 1; | |
} | |
void __attribute__((__noinline__)) test() { | |
int8_t input[100]; | |
int8_t max_value = 0; | |
for (size_t c = 0; c < 3000; c++) { | |
for (size_t py = 0; py < 15; py++) | |
max_value = std::max(max_value, input[select()]); | |
__asm__ __volatile__("" ::"r"(max_value)); | |
} | |
} | |
int main(int argc, const char* argv[]) { | |
auto start = std::chrono::system_clock::now(); | |
for (int i = 0; i < 500; ++i) | |
test(); | |
auto end = std::chrono::system_clock::now(); | |
std::cout << "Elapsed time: " | |
<< std::chrono::duration<double>(end - start).count() << "s\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment