-
-
Save heatd/96d246ec8d72b1a0ebe3911eb1da655b 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 <benchmark/benchmark.h> | |
static void pushpop(benchmark::State &state) | |
{ | |
for (auto _ : state) | |
{ | |
__asm__ __volatile__("push %%rax; pop %%rbx" ::: "rbx"); | |
__asm__ __volatile__("push %%rbx; pop %%rax" ::: "rax"); | |
__asm__ __volatile__("push %%rax; pop %%rbx" ::: "rbx"); | |
__asm__ __volatile__("push %%rbx; pop %%rax" ::: "rax"); | |
__asm__ __volatile__("push %%rax; pop %%rbx" ::: "rbx"); | |
__asm__ __volatile__("push %%rbx; pop %%rax" ::: "rax"); | |
__asm__ __volatile__("push %%rax; pop %%rbx" ::: "rbx"); | |
__asm__ __volatile__("push %%rbx; pop %%rax" ::: "rax"); | |
__asm__ __volatile__("push %%rax; pop %%rbx" ::: "rbx"); | |
__asm__ __volatile__("push %%rbx; pop %%rax" ::: "rax"); | |
__asm__ __volatile__("push %%rax; pop %%rbx" ::: "rbx"); | |
} | |
} | |
BENCHMARK(pushpop); | |
static void mov(benchmark::State &state) | |
{ | |
for (auto _ : state) | |
{ | |
__asm__ __volatile__("mov %%rax, %%rbx" ::: "rbx"); | |
__asm__ __volatile__("mov %%rbx, %%rax" ::: "rax"); | |
__asm__ __volatile__("mov %%rax, %%rbx" ::: "rbx"); | |
__asm__ __volatile__("mov %%rbx, %%rax" ::: "rax"); | |
__asm__ __volatile__("mov %%rax, %%rbx" ::: "rbx"); | |
__asm__ __volatile__("mov %%rbx, %%rax" ::: "rax"); | |
__asm__ __volatile__("mov %%rax, %%rbx" ::: "rbx"); | |
__asm__ __volatile__("mov %%rbx, %%rax" ::: "rax"); | |
__asm__ __volatile__("mov %%rax, %%rbx" ::: "rbx"); | |
__asm__ __volatile__("mov %%rbx, %%rax" ::: "rax"); | |
__asm__ __volatile__("mov %%rax, %%rbx" ::: "rbx"); | |
} | |
} | |
BENCHMARK(mov); | |
BENCHMARK_MAIN(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment