Skip to content

Instantly share code, notes, and snippets.

@heatd
Created January 27, 2023 21:52
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/96d246ec8d72b1a0ebe3911eb1da655b to your computer and use it in GitHub Desktop.
Save heatd/96d246ec8d72b1a0ebe3911eb1da655b 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 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