Skip to content

Instantly share code, notes, and snippets.

@mfleming
Created May 7, 2020 12:14
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 mfleming/c668b7586dd8f1856a812a42d3bb8f87 to your computer and use it in GitHub Desktop.
Save mfleming/c668b7586dd8f1856a812a42d3bb8f87 to your computer and use it in GitHub Desktop.
//
// Compile with:
//
// g++ clear_user.cc -std=c++11 -isystem <path to googlebenchmark>/include \
// -L<path to googlebenchmark>/build/src -lbenchmark -lpthread -o clear_user
//
#include <benchmark/benchmark.h>
#define BUF_SIZE (64*1024)
static char buf[BUF_SIZE];
void __clear_mov_imm(void *addr)
{
long __d0;
asm volatile("movq $0,(%[dst])\n"
: [dst] "=&D" (__d0)
: "[dst]"(addr));
}
void __clear_mov_reg(void *addr)
{
long __d0;
asm volatile("movq %[zero],(%[dst])\n"
: [dst] "=&D" (__d0)
: "[dst]"(addr), [zero] "r" (0UL));
}
static void BM_mov_reg(benchmark::State& state) {
for (auto _ : state)
__clear_mov_reg(buf);
}
BENCHMARK(BM_mov_reg);
static void BM_mov_imm(benchmark::State& state) {
for (auto _ : state)
__clear_mov_imm(buf);
}
BENCHMARK(BM_mov_imm);
static void BM_mov_reg_inline(benchmark::State& state) {
for (auto _ : state) {
long __d0;
asm volatile("movq %[zero],(%[dst])\n"
: [dst] "=&D" (__d0)
: "[dst]"(buf), [zero] "r" (0UL));
}
}
BENCHMARK(BM_mov_reg_inline);
static void BM_mov_imm_inline(benchmark::State& state) {
for (auto _ : state) {
long __d0;
asm volatile("movq $0,(%[dst])\n"
: [dst] "=&D" (__d0)
: "[dst]"(buf));
}
}
BENCHMARK(BM_mov_imm_inline);
BENCHMARK_MAIN();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment