Skip to content

Instantly share code, notes, and snippets.

@heatd
Created January 27, 2023 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heatd/ed84257036e218f770fa93ae99bd07d7 to your computer and use it in GitHub Desktop.
Save heatd/ed84257036e218f770fa93ae99bd07d7 to your computer and use it in GitHub Desktop.
#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