Code alignment testing
This commit is contained in:
		@@ -15,6 +15,14 @@ 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);
 | 
			
		||||
extern "C" void align64_loop(u64 size);
 | 
			
		||||
extern "C" void align1_loop(u64 size);
 | 
			
		||||
extern "C" void align15_loop(u64 size);
 | 
			
		||||
extern "C" void align31_loop(u64 size);
 | 
			
		||||
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);
 | 
			
		||||
 | 
			
		||||
void test_fread(reptester *tester, alloc_type type);
 | 
			
		||||
void test_read(reptester *tester, alloc_type type);
 | 
			
		||||
@@ -25,6 +33,14 @@ 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);
 | 
			
		||||
void test_align64_loop(reptester *tester, alloc_type type);
 | 
			
		||||
void test_align1_loop(reptester *tester, alloc_type type);
 | 
			
		||||
void test_align15_loop(reptester *tester, alloc_type type);
 | 
			
		||||
void test_align31_loop(reptester *tester, alloc_type type);
 | 
			
		||||
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);
 | 
			
		||||
u64 get_file_length(FILE *fp);
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[]) {
 | 
			
		||||
@@ -80,18 +96,26 @@ int main(int argc, char *argv[]) {
 | 
			
		||||
      // {{"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 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 NOP ASM", "WRITE NOP ASM WITH MALLOC"},
 | 
			
		||||
      //  test_write_nop_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},
 | 
			
		||||
      {{"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},
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  tester.params.read_size = get_file_length(fp);
 | 
			
		||||
@@ -361,6 +385,208 @@ void test_write_dec_all_bytes_asm(reptester *tester, alloc_type type) {
 | 
			
		||||
  handle_free(tester, type);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void test_align64_loop(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;
 | 
			
		||||
 | 
			
		||||
  align64_loop(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_align1_loop(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;
 | 
			
		||||
 | 
			
		||||
  align1_loop(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_align15_loop(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;
 | 
			
		||||
 | 
			
		||||
  align15_loop(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_align31_loop(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;
 | 
			
		||||
 | 
			
		||||
  align31_loop(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_align63_loop(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;
 | 
			
		||||
 | 
			
		||||
  align63_loop(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_align75_loop(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;
 | 
			
		||||
 | 
			
		||||
  align75_loop(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_align90_loop(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;
 | 
			
		||||
 | 
			
		||||
  align90_loop(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_align112_loop(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;
 | 
			
		||||
 | 
			
		||||
  align112_loop(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;
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,14 @@ global nop_1x3_all_bytes_asm
 | 
			
		||||
global nop_1x9_all_bytes_asm
 | 
			
		||||
global inc_all_bytes_asm
 | 
			
		||||
global dec_all_bytes_asm
 | 
			
		||||
global align64_loop
 | 
			
		||||
global align1_loop
 | 
			
		||||
global align15_loop
 | 
			
		||||
global align31_loop
 | 
			
		||||
global align63_loop
 | 
			
		||||
global align75_loop
 | 
			
		||||
global align90_loop
 | 
			
		||||
global align112_loop
 | 
			
		||||
 | 
			
		||||
mov_all_bytes_asm:
 | 
			
		||||
	xor rax, rax
 | 
			
		||||
@@ -75,3 +83,110 @@ dec_all_bytes_asm:
 | 
			
		||||
		jnz .loop
 | 
			
		||||
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
align64_loop:
 | 
			
		||||
	xor rax, rax
 | 
			
		||||
 | 
			
		||||
	align 64
 | 
			
		||||
	.loop:
 | 
			
		||||
		inc rax
 | 
			
		||||
		cmp rdi, rax
 | 
			
		||||
		jne .loop
 | 
			
		||||
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
align1_loop:
 | 
			
		||||
	xor rax, rax
 | 
			
		||||
 | 
			
		||||
	align 64
 | 
			
		||||
	nop
 | 
			
		||||
	.loop:
 | 
			
		||||
		inc rax
 | 
			
		||||
		cmp rdi, rax
 | 
			
		||||
		jne .loop
 | 
			
		||||
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
align15_loop:
 | 
			
		||||
	xor rax, rax
 | 
			
		||||
 | 
			
		||||
	align 64
 | 
			
		||||
	%rep 15
 | 
			
		||||
	nop
 | 
			
		||||
	%endrep
 | 
			
		||||
	.loop:
 | 
			
		||||
		inc rax
 | 
			
		||||
		cmp rdi, rax
 | 
			
		||||
		jne .loop
 | 
			
		||||
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
align31_loop:
 | 
			
		||||
	xor rax, rax
 | 
			
		||||
 | 
			
		||||
	align 64
 | 
			
		||||
	%rep 31
 | 
			
		||||
	nop
 | 
			
		||||
	%endrep
 | 
			
		||||
	.loop:
 | 
			
		||||
		inc rax
 | 
			
		||||
		cmp rdi, rax
 | 
			
		||||
		jne .loop
 | 
			
		||||
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
align63_loop:
 | 
			
		||||
	xor rax, rax
 | 
			
		||||
 | 
			
		||||
	align 64
 | 
			
		||||
	%rep 63
 | 
			
		||||
	nop
 | 
			
		||||
	%endrep
 | 
			
		||||
	.loop:
 | 
			
		||||
		inc rax
 | 
			
		||||
		cmp rdi, rax
 | 
			
		||||
		jne .loop
 | 
			
		||||
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
align75_loop:
 | 
			
		||||
	xor rax, rax
 | 
			
		||||
 | 
			
		||||
	align 64
 | 
			
		||||
	%rep 75
 | 
			
		||||
	nop
 | 
			
		||||
	%endrep
 | 
			
		||||
	.loop:
 | 
			
		||||
		inc rax
 | 
			
		||||
		cmp rdi, rax
 | 
			
		||||
		jne .loop
 | 
			
		||||
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
align90_loop:
 | 
			
		||||
	xor rax, rax
 | 
			
		||||
 | 
			
		||||
	align 64
 | 
			
		||||
	%rep 90
 | 
			
		||||
	nop
 | 
			
		||||
	%endrep
 | 
			
		||||
	.loop:
 | 
			
		||||
		inc rax
 | 
			
		||||
		cmp rdi, rax
 | 
			
		||||
		jne .loop
 | 
			
		||||
 | 
			
		||||
	ret
 | 
			
		||||
 | 
			
		||||
align112_loop:
 | 
			
		||||
	xor rax, rax
 | 
			
		||||
 | 
			
		||||
	align 64
 | 
			
		||||
	%rep 112
 | 
			
		||||
	nop
 | 
			
		||||
	%endrep
 | 
			
		||||
	.loop:
 | 
			
		||||
		inc rax
 | 
			
		||||
		cmp rdi, rax
 | 
			
		||||
		jne .loop
 | 
			
		||||
 | 
			
		||||
	ret
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user