Created
May 7, 2020 12:14
-
-
Save mfleming/c668b7586dd8f1856a812a42d3bb8f87 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
// | |
// 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