diff --git a/Makefile b/Makefile index 35c0975..ada7fda 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ CFLAGS=-lm -g -Wall -O1 -build/main: src/main.c src/repetition_tester.c build/multi_nop_loop.o build/write_loops.o build/load_uop.o src/rprof.h +build/main: src/main.c src/repetition_tester.c build/multi_nop_loop.o build/write_loops.o build/load_uop.o build/store_uop.o src/rprof.h mkdir -p build - gcc -o build/main src/main.c build/multi_nop_loop.o build/write_loops.o build/load_uop.o $(CFLAGS) + gcc -o build/main src/main.c build/multi_nop_loop.o build/write_loops.o build/load_uop.o build/store_uop.o $(CFLAGS) build/load_uop.o: src/load_uop.asm nasm -g -f elf64 -o build/load_uop.o src/load_uop.asm @@ -13,6 +13,9 @@ build/write_loops.o: src/write_loops.asm build/multi_nop_loop.o: src/multi_nop_loop.asm nasm -g -f elf64 -o build/multi_nop_loop.o src/multi_nop_loop.asm +build/store_uop.o: src/store_uop.asm + nasm -g -f elf64 -o build/store_uop.o src/store_uop.asm + run: ./build/main ./build/main $(TEST_NAME) diff --git a/src/main.c b/src/main.c index 1697acc..5a39cd3 100644 --- a/src/main.c +++ b/src/main.c @@ -15,6 +15,7 @@ #include "main_write_backward.c" #include "main_write_loop.c" #include "main_load_uop.c" +#include "main_store_uop.c" int main(int argc, char **argv) { if (argc < 2) { @@ -30,6 +31,8 @@ int main(int argc, char **argv) { return main_test_write_all_bytes(); } else if (!strncmp(test_name, "load_uop", sizeof("load_uop"))) { return main_test_load_uop(); + } else if (!strncmp(test_name, "store_uop", sizeof("store_uop"))) { + return main_test_store_uop(); } else if (!strncmp(test_name, "write_loop", sizeof("write_loop"))) { return main_test_write_loop(); } else if (!strncmp(test_name, "write_backward", sizeof("write_backward"))) { diff --git a/src/main_store_uop.c b/src/main_store_uop.c new file mode 100644 index 0000000..1312ff6 --- /dev/null +++ b/src/main_store_uop.c @@ -0,0 +1,41 @@ +#include "repetition_tester.c" +#include "store_uop.h" + +int main_test_store_uop() { + typedef void (*test_cb)(uint8_t *buffer, uint64_t byte_count); + struct testcase { + char *name; + test_cb cb; + }; + + struct testcase cases[] = { + { .name = "mov_store_x1()", .cb = mov_store_x1 }, + { .name = "mov_store_x2()", .cb = mov_store_x2 }, + { .name = "mov_store_x3()", .cb = mov_store_x3 }, + { .name = "mov_store_x4()", .cb = mov_store_x4 }, + }; + + struct repetitor repetitor = {}; + repetitor_init(&repetitor); + printf("CPU Frequency: %ldHz (~%.2fGHz)\n", repetitor.cpu_freq, (float)repetitor.cpu_freq/(1000*1000*1000)); + + uint64_t byte_count = 4096 * 1024; + uint8_t buffer[byte_count]; + + for (int i = 0; i < ARRAY_LEN(cases); i++) { + struct testcase *testcase = &cases[i]; + repetitor_clear(&repetitor); + while (repetitor_repeat(&repetitor, 2)) { + repetitor_start(&repetitor); + repetitor_measure_start(&repetitor); + testcase->cb(buffer, byte_count); + repetitor_measure_stop(&repetitor, byte_count); + repetitor_stop(&repetitor); + } + repetitor_print_results_label(&repetitor, testcase->name); + } + + return 0; +} + + diff --git a/src/store_uop.asm b/src/store_uop.asm new file mode 100644 index 0000000..97c0165 --- /dev/null +++ b/src/store_uop.asm @@ -0,0 +1,57 @@ +global mov_store_x1 +global mov_store_x2 +global mov_store_x3 +global mov_store_x4 + +section .text + +; rsi - byte_count +; rdi - buffer +mov_store_x1: + mov rcx, rsi + align 64 +.loop: + mov [rdi], rax + sub rcx, 1 + jnle .loop + ret + +; rsi - byte_count +; rdi - buffer +mov_store_x2: + mov rcx, rsi + align 64 +.loop: + mov [rdi], rax + mov [rdi], rax + sub rcx, 2 + jnle .loop + ret + +; rsi - byte_count +; rdi - buffer +mov_store_x3: + mov rcx, rsi + align 64 +.loop: + mov [rdi], rax + mov [rdi], rax + mov [rdi], rax + sub rcx, 3 + jnle .loop + ret + +; rsi - byte_count +; rdi - buffer +mov_store_x4: + mov rcx, rsi + align 64 +.loop: + mov [rdi], rax + mov [rdi], rax + mov [rdi], rax + mov [rdi], rax + sub rcx, 4 + jnle .loop + ret + diff --git a/src/store_uop.h b/src/store_uop.h new file mode 100644 index 0000000..922955d --- /dev/null +++ b/src/store_uop.h @@ -0,0 +1,6 @@ +#include + +void mov_store_x1(uint8_t *buffer, uint64_t byte_count); +void mov_store_x2(uint8_t *buffer, uint64_t byte_count); +void mov_store_x3(uint8_t *buffer, uint64_t byte_count); +void mov_store_x4(uint8_t *buffer, uint64_t byte_count);