From 4945a298aca184b3aa9880ed5745382f67683764 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sat, 10 Feb 2024 17:54:42 +0000 Subject: [PATCH] Add more assembly functions to repetition_testing --- haversine_02/src/repetition_testing/main.cpp | 73 +++++++++++++++++-- .../repetition_testing/reptest_functions.asm | 24 ++++++ 2 files changed, 89 insertions(+), 8 deletions(-) diff --git a/haversine_02/src/repetition_testing/main.cpp b/haversine_02/src/repetition_testing/main.cpp index 0918c39..5b0fd72 100644 --- a/haversine_02/src/repetition_testing/main.cpp +++ b/haversine_02/src/repetition_testing/main.cpp @@ -23,6 +23,8 @@ extern "C" void align63_loop(u64 size); extern "C" void align75_loop(u64 size); extern "C" void align90_loop(u64 size); extern "C" void align112_loop(u64 size); +extern "C" void rat_add(u64 size); +extern "C" void rat_mov_add(u64 size); void test_fread(reptester *tester, alloc_type type); void test_read(reptester *tester, alloc_type type); @@ -41,6 +43,8 @@ void test_align63_loop(reptester *tester, alloc_type type); void test_align75_loop(reptester *tester, alloc_type type); void test_align90_loop(reptester *tester, alloc_type type); void test_align112_loop(reptester *tester, alloc_type type); +void test_rat_add(reptester *tester, alloc_type type); +void test_rat_mov_add(reptester *tester, alloc_type type); u64 get_file_length(FILE *fp); int main(int argc, char *argv[]) { @@ -108,14 +112,17 @@ int main(int argc, char *argv[]) { // test_write_dec_all_bytes_asm}, // {{"READ", "READ WITH MALLOC"}, test_read}, // {{"FREAD", "FREAD WITH MALLOC"}, test_fread}, - {{"ALIGN 64", "ALIGN 64 WITH MALLOC"}, test_align64_loop}, - {{"ALIGN 1", "ALIGN 1 WITH MALLOC"}, test_align1_loop}, - {{"ALIGN 15", "ALIGN 15 WITH MALLOC"}, test_align15_loop}, - {{"ALIGN 31", "ALIGN 31 WITH MALLOC"}, test_align31_loop}, - {{"ALIGN 63", "ALIGN 63 WITH MALLOC"}, test_align63_loop}, - {{"ALIGN 75", "ALIGN 75 WITH MALLOC"}, test_align75_loop}, - {{"ALIGN 90", "ALIGN 90 WITH MALLOC"}, test_align90_loop}, - {{"ALIGN 112", "ALIGN 112 WITH MALLOC"}, test_align112_loop}, + // {{"ALIGN 64", "ALIGN 64 WITH MALLOC"}, test_align64_loop}, + // {{"ALIGN 1", "ALIGN 1 WITH MALLOC"}, test_align1_loop}, + // {{"ALIGN 15", "ALIGN 15 WITH MALLOC"}, test_align15_loop}, + // {{"ALIGN 31", "ALIGN 31 WITH MALLOC"}, test_align31_loop}, + // {{"ALIGN 63", "ALIGN 63 WITH MALLOC"}, test_align63_loop}, + // {{"ALIGN 75", "ALIGN 75 WITH MALLOC"}, test_align75_loop}, + // {{"ALIGN 90", "ALIGN 90 WITH MALLOC"}, test_align90_loop}, + // {{"ALIGN 112", "ALIGN 112 WITH MALLOC"}, test_align112_loop}, + // {{"ALIGN 112", "ALIGN 112 WITH MALLOC"}, test_align112_loop}, + {{"RAT ADD", "RAT ADD WITH MALLOC"}, test_rat_add}, + {{"RAT MOV ADD", "RAT MOV ADD WITH MALLOC"}, test_rat_mov_add}, }; tester.params.read_size = get_file_length(fp); @@ -587,6 +594,56 @@ void test_align112_loop(reptester *tester, alloc_type type) { handle_free(tester, type); } +void test_rat_add(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; + + rat_add(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_rat_mov_add(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; + + rat_mov_add(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); +} + u64 get_file_length(FILE *fp) { if (!fp) { return 0; diff --git a/haversine_02/src/repetition_testing/reptest_functions.asm b/haversine_02/src/repetition_testing/reptest_functions.asm index b2772e6..a08160f 100644 --- a/haversine_02/src/repetition_testing/reptest_functions.asm +++ b/haversine_02/src/repetition_testing/reptest_functions.asm @@ -12,6 +12,8 @@ global align63_loop global align75_loop global align90_loop global align112_loop +global rat_add +global rat_mov_add mov_all_bytes_asm: xor rax, rax @@ -190,3 +192,25 @@ align112_loop: jne .loop ret + +rat_add: + mov rax, rdi + + .loop: + add rcx, 1 + add rcx, 1 + dec rax + jnz .loop + ret + +rat_mov_add: + mov rax, rdi + + .loop: + mov rcx, rax + add rcx, 1 + mov rcx, rax + add rcx, 1 + dec rax + jnz .loop + ret