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