From 12f25cfe5113e90a4719d1d5510ca2362cb69a6b Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sun, 3 Dec 2023 23:24:52 +0000 Subject: [PATCH] Additional assembly loops --- haversine_02/src/repetition_testing/main.cpp | 72 +++++++++++++++++-- .../repetition_testing/reptest_functions.asm | 34 +++++++++ 2 files changed, 99 insertions(+), 7 deletions(-) diff --git a/haversine_02/src/repetition_testing/main.cpp b/haversine_02/src/repetition_testing/main.cpp index 1c00bf1..2c876c6 100644 --- a/haversine_02/src/repetition_testing/main.cpp +++ b/haversine_02/src/repetition_testing/main.cpp @@ -11,6 +11,8 @@ extern "C" void mov_all_bytes_asm(char *buffer, u64 size); extern "C" void nop_all_bytes_asm(u64 size); +extern "C" void nop_1x3_all_bytes_asm(u64 size); +extern "C" void nop_1x9_all_bytes_asm(u64 size); extern "C" void inc_all_bytes_asm(u64 size); extern "C" void dec_all_bytes_asm(u64 size); @@ -19,6 +21,8 @@ void test_read(reptester *tester, alloc_type type); void test_write(reptester *tester, alloc_type type); void test_write_mov_all_bytes_asm(reptester *tester, alloc_type type); void test_write_nop_all_bytes_asm(reptester *tester, alloc_type type); +void test_write_nop_1x3_all_bytes_asm(reptester *tester, alloc_type type); +void test_write_nop_1x9_all_bytes_asm(reptester *tester, alloc_type type); void test_write_inc_all_bytes_asm(reptester *tester, alloc_type type); void test_write_dec_all_bytes_asm(reptester *tester, alloc_type type); u64 get_file_length(FILE *fp); @@ -73,15 +77,19 @@ int main(int argc, char *argv[]) { } func_data funcs[] = { - {{"WRITE", "WRITE WITH MALLOC"}, test_write}, - {{"WRITE MOV ASM", "WRITE MOV ASM WITH MALLOC"}, - test_write_mov_all_bytes_asm}, + // {{"WRITE", "WRITE WITH MALLOC"}, test_write}, + // {{"WRITE MOV ASM", "WRITE MOV ASM WITH MALLOC"}, + // test_write_mov_all_bytes_asm}, {{"WRITE NOP ASM", "WRITE NOP ASM WITH MALLOC"}, test_write_nop_all_bytes_asm}, - {{"WRITE INC ASM", "WRITE INC ASM WITH MALLOC"}, - test_write_inc_all_bytes_asm}, - {{"WRITE DEC ASM", "WRITE DEC ASM WITH MALLOC"}, - test_write_dec_all_bytes_asm}, + {{"WRITE NOP 1x3 ASM", "WRITE NOP 1x3 ASM WITH MALLOC"}, + test_write_nop_1x3_all_bytes_asm}, + {{"WRITE NOP 1x9 ASM", "WRITE NOP 1x9 ASM WITH MALLOC"}, + test_write_nop_1x9_all_bytes_asm}, + // {{"WRITE INC ASM", "WRITE INC ASM WITH MALLOC"}, + // test_write_inc_all_bytes_asm}, + // {{"WRITE DEC ASM", "WRITE DEC ASM WITH MALLOC"}, + // test_write_dec_all_bytes_asm}, // {{"READ", "READ WITH MALLOC"}, test_read}, // {{"FREAD", "FREAD WITH MALLOC"}, test_fread}, }; @@ -253,6 +261,56 @@ void test_write_nop_all_bytes_asm(reptester *tester, alloc_type type) { handle_free(tester, type); } +void test_write_nop_1x3_all_bytes_asm(reptester *tester, alloc_type type) { + u64 start = read_cpu_timer(); + u64 fault_count_start = page_fault_count(); + + handle_alloc(tester, type); + + u64 total_size = tester->params.read_size * tester->params.read_count; + + nop_1x3_all_bytes_asm(total_size); + + u64 fault_count_end = page_fault_count(); + u64 end = read_cpu_timer(); + + u64 read_time = end - start; + u64 page_faults = fault_count_end - fault_count_start; + + tester->results = { + total_size, + read_time, + page_faults, + }; + + handle_free(tester, type); +} + +void test_write_nop_1x9_all_bytes_asm(reptester *tester, alloc_type type) { + u64 start = read_cpu_timer(); + u64 fault_count_start = page_fault_count(); + + handle_alloc(tester, type); + + u64 total_size = tester->params.read_size * tester->params.read_count; + + nop_1x9_all_bytes_asm(total_size); + + u64 fault_count_end = page_fault_count(); + u64 end = read_cpu_timer(); + + u64 read_time = end - start; + u64 page_faults = fault_count_end - fault_count_start; + + tester->results = { + total_size, + read_time, + page_faults, + }; + + handle_free(tester, type); +} + void test_write_inc_all_bytes_asm(reptester *tester, alloc_type type) { u64 start = read_cpu_timer(); u64 fault_count_start = page_fault_count(); diff --git a/haversine_02/src/repetition_testing/reptest_functions.asm b/haversine_02/src/repetition_testing/reptest_functions.asm index f893d1a..34d5498 100644 --- a/haversine_02/src/repetition_testing/reptest_functions.asm +++ b/haversine_02/src/repetition_testing/reptest_functions.asm @@ -1,5 +1,7 @@ global mov_all_bytes_asm global nop_all_bytes_asm +global nop_1x3_all_bytes_asm +global nop_1x9_all_bytes_asm global inc_all_bytes_asm global dec_all_bytes_asm @@ -25,6 +27,38 @@ nop_all_bytes_asm: ret +nop_1x3_all_bytes_asm: + xor rax, rax + + .loop: + nop + nop + nop + inc rax + cmp rdi, rax + jne .loop + + ret + +nop_1x9_all_bytes_asm: + xor rax, rax + + .loop: + nop + nop + nop + nop + nop + nop + nop + nop + nop + inc rax + cmp rdi, rax + jne .loop + + ret + inc_all_bytes_asm: xor rax, rax