From 4bead73f52ad5a43a5400179928aa0aa97b79b35 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Fri, 1 May 2015 00:56:39 -0700 Subject: [PATCH] Make dhrystone report correct-ish numbers --- benchmarks/Makefile | 2 +- benchmarks/common/crt.S | 3 + benchmarks/common/test.ld | 14 +- benchmarks/dhrystone/dhrystone.c | 32 ++++- benchmarks/dhrystone/dhrystone.h | 18 +-- benchmarks/dhrystone/dhrystone_main.c | 179 +++++++++++++------------- 6 files changed, 135 insertions(+), 113 deletions(-) diff --git a/benchmarks/Makefile b/benchmarks/Makefile index 3cb899a..9738f61 100644 --- a/benchmarks/Makefile +++ b/benchmarks/Makefile @@ -52,7 +52,7 @@ HOST_COMP = gcc $(HOST_OPTS) RISCV_PREFIX=riscv64-unknown-elf- RISCV_GCC = $(RISCV_PREFIX)gcc -RISCV_GCC_OPTS = -static -Wa,-march=RVIMAFDXhwacha -std=gnu99 -O2 -ffast-math +RISCV_GCC_OPTS = -static -Wa,-march=RVIMAFDXhwacha -std=gnu99 -O2 -ffast-math -fno-common -fno-builtin-printf RISCV_LINK = $(RISCV_GCC) -T $(bmarkdir)/common/test.ld $(incs) RISCV_LINK_MT = $(RISCV_GCC) -T $(bmarkdir)/common/test-mt.ld RISCV_LINK_OPTS = -nostdlib -nostartfiles -ffast-math -lc -lgcc diff --git a/benchmarks/common/crt.S b/benchmarks/common/crt.S index 0c99c4a..97b90d5 100644 --- a/benchmarks/common/crt.S +++ b/benchmarks/common/crt.S @@ -131,6 +131,9 @@ _start: fmv.s.x f31,x0 1: + # initialize global pointer + la gp, _gp + la tp, _end + 63 and tp, tp, -64 diff --git a/benchmarks/common/test.ld b/benchmarks/common/test.ld index 816c948..082891c 100644 --- a/benchmarks/common/test.ld +++ b/benchmarks/common/test.ld @@ -28,8 +28,20 @@ SECTIONS *(.text) } - /* data segmemt */ + /* data segment */ .data : { *(.data) } + + .sdata : { + _gp = . + 0x800; + *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata*) + *(.sdata .sdata.* .gnu.linkonce.s.*) + } + + /* bss segment */ + .sbss : { + *(.sbss .sbss.* .gnu.linkonce.sb.*) + *(.scommon) + } .bss : { *(.bss) } /* thread-local data segment */ diff --git a/benchmarks/dhrystone/dhrystone.c b/benchmarks/dhrystone/dhrystone.c index 1c0ad92..418602a 100644 --- a/benchmarks/dhrystone/dhrystone.c +++ b/benchmarks/dhrystone/dhrystone.c @@ -1,5 +1,7 @@ // See LICENSE for license details. +#pragma GCC optimize ("no-inline") + #include "dhrystone.h" #ifndef REG @@ -15,10 +17,13 @@ extern int Int_Glob; extern char Ch_1_Glob; -void Proc_6(Enumeration Enum_Val_Par, Enumeration* Enum_Ref_Par) +Proc_6 (Enum_Val_Par, Enum_Ref_Par) /*********************************/ /* executed once */ /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */ + +Enumeration Enum_Val_Par; +Enumeration *Enum_Ref_Par; { *Enum_Ref_Par = Enum_Val_Par; if (! Func_3 (Enum_Val_Par)) @@ -46,7 +51,7 @@ void Proc_6(Enumeration Enum_Val_Par, Enumeration* Enum_Ref_Par) } /* Proc_6 */ -void Proc_7(int Int_1_Par_Val, int Int_2_Par_Val, int* Int_Par_Ref) +Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref) /**********************************************/ /* executed three times */ /* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */ @@ -55,6 +60,9 @@ void Proc_7(int Int_1_Par_Val, int Int_2_Par_Val, int* Int_Par_Ref) /* Int_Par_Ref becomes 17 */ /* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */ /* Int_Par_Ref becomes 18 */ +One_Fifty Int_1_Par_Val; +One_Fifty Int_2_Par_Val; +One_Fifty *Int_Par_Ref; { One_Fifty Int_Loc; @@ -63,11 +71,15 @@ void Proc_7(int Int_1_Par_Val, int Int_2_Par_Val, int* Int_Par_Ref) } /* Proc_7 */ -void Proc_8(Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val) +Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val) /*********************************************************************/ /* executed once */ /* Int_Par_Val_1 == 3 */ /* Int_Par_Val_2 == 7 */ +Arr_1_Dim Arr_1_Par_Ref; +Arr_2_Dim Arr_2_Par_Ref; +int Int_1_Par_Val; +int Int_2_Par_Val; { REG One_Fifty Int_Index; REG One_Fifty Int_Loc; @@ -84,12 +96,15 @@ void Proc_8(Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, } /* Proc_8 */ -Enumeration Func_1 (char Ch_1_Par_Val, char Ch_2_Par_Val) +Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val) /*************************************************/ /* executed three times */ /* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */ /* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */ /* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */ + +Capital_Letter Ch_1_Par_Val; +Capital_Letter Ch_2_Par_Val; { Capital_Letter Ch_1_Loc; Capital_Letter Ch_2_Loc; @@ -107,11 +122,14 @@ Enumeration Func_1 (char Ch_1_Par_Val, char Ch_2_Par_Val) } /* Func_1 */ -Boolean Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref) +Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref) /*************************************************/ /* executed once */ /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */ /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */ + +Str_30 Str_1_Par_Ref; +Str_30 Str_2_Par_Ref; { REG One_Thirty Int_Loc; Capital_Letter Ch_Loc; @@ -146,10 +164,11 @@ Boolean Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref) } /* Func_2 */ -Boolean Func_3(Enumeration Enum_Par_Val) +Boolean Func_3 (Enum_Par_Val) /***************************/ /* executed once */ /* Enum_Par_Val == Ident_3 */ +Enumeration Enum_Par_Val; { Enumeration Enum_Loc; @@ -160,3 +179,4 @@ Boolean Func_3(Enumeration Enum_Par_Val) else /* not executed */ return (false); } /* Func_3 */ + diff --git a/benchmarks/dhrystone/dhrystone.h b/benchmarks/dhrystone/dhrystone.h index f3f7bfd..767a657 100644 --- a/benchmarks/dhrystone/dhrystone.h +++ b/benchmarks/dhrystone/dhrystone.h @@ -382,10 +382,10 @@ extern clock_t clock(); #elif defined(__riscv) #define HZ 976563 -#define Too_Small_Time 50 +#define Too_Small_Time 1 #define CLOCK_TYPE "rdcycle()" -#define Start_Timer() Begin_Time = rdcycle()/1024 -#define Stop_Timer() End_Time = rdcycle()/1024 +#define Start_Timer() Begin_Time = rdcycle() +#define Stop_Timer() End_Time = rdcycle() #else /* Use times(2) time function unless */ @@ -474,16 +474,4 @@ typedef struct record } variant; } Rec_Type, *Rec_Pointer; -void Proc_1(Rec_Pointer Ptr_Val_Par); -void Proc_2(int* Int_Par_Ref); -void Proc_3(Rec_Pointer* Ptr_Ref_Par); -void Proc_4(); -void Proc_5(); -void Proc_6(Enumeration Enum_Val_Par, Enumeration* Enum_Ref_Par); -void Proc_7(int Int_1_Par_Val, int Int_2_Par_Val, int* Int_Par_Ref); -void Proc_8(Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val); -Enumeration Func_1 (char Ch_1_Par_Val, char Ch_2_Par_Val); -Boolean Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref); -Boolean Func_3(Enumeration Enum_Par_Val); - #endif diff --git a/benchmarks/dhrystone/dhrystone_main.c b/benchmarks/dhrystone/dhrystone_main.c index b4bfda1..34451f9 100644 --- a/benchmarks/dhrystone/dhrystone_main.c +++ b/benchmarks/dhrystone/dhrystone_main.c @@ -8,6 +8,8 @@ // You should not change anything except the HOST_DEBUG and // PREALLOCATE macros for your timing run. +#pragma GCC optimize ("no-inline") + #include "dhrystone.h" //-------------------------------------------------------------------------- @@ -38,9 +40,9 @@ #endif #if HOST_DEBUG -# define do_fprintf fprintf +# define debug_printf printf #else -int __attribute__((noinline)) do_fprintf(FILE* f, const char* str, ...) +void debug_printf(const char* str, ...) { return 0; } @@ -61,6 +63,10 @@ char Ch_1_Glob, int Arr_1_Glob [50]; int Arr_2_Glob [50] [50]; +extern char *malloc (); +Enumeration Func_1 (); + /* forward declaration necessary since Enumeration may not simply be int */ + #ifndef REG Boolean Reg = false; #define REG @@ -77,7 +83,7 @@ Boolean Done; long Begin_Time, End_Time, User_Time; -float Microseconds, +long Microseconds, Dhrystones_Per_Second; /* end of variables for time measurement */ @@ -102,18 +108,15 @@ int main (int argc, char** argv) #if HOST_DEBUG if (argc > 2) { - do_fprintf (stdout, "Usage: %s [number of loops]\n", argv[0]); + printf("Usage: %s [number of loops]\n", argv[0]); exit (1); } if (argc == 2) { Number_Of_Runs = atoi (argv[1]); - } else -#endif - { - Number_Of_Runs = NUMBER_OF_RUNS; } - if (Number_Of_Runs <= 0) + else if (Number_Of_Runs <= 0) +#endif { Number_Of_Runs = NUMBER_OF_RUNS; } @@ -137,26 +140,22 @@ int main (int argc, char** argv) /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */ /* overflow may occur for this array element. */ -#if HOST_DEBUG - do_fprintf (stdout, "\n"); - do_fprintf (stdout, "Dhrystone Benchmark, Version %s\n", Version); + debug_printf("\n"); + debug_printf("Dhrystone Benchmark, Version %s\n", Version); if (Reg) { - do_fprintf (stdout, "Program compiled with 'register' attribute\n"); + debug_printf("Program compiled with 'register' attribute\n"); } else { - do_fprintf (stdout, "Program compiled without 'register' attribute\n"); + debug_printf("Program compiled without 'register' attribute\n"); } - do_fprintf (stdout, "Using %s, HZ=%d\n", CLOCK_TYPE, HZ); - do_fprintf (stdout, "\n"); -#endif + debug_printf("Using %s, HZ=%d\n", CLOCK_TYPE, HZ); + debug_printf("\n"); Done = false; while (!Done) { -#if HOST_DEBUG - do_fprintf (stdout, "Trying %d runs through Dhrystone:\n", Number_Of_Runs); -#endif + debug_printf("Trying %d runs through Dhrystone:\n", Number_Of_Runs); /***************/ /* Start timer */ @@ -222,83 +221,78 @@ int main (int argc, char** argv) if (User_Time < Too_Small_Time) { - do_fprintf (stdout, "Measured time too small to obtain meaningful results\n"); + printf("Measured time too small to obtain meaningful results\n"); Number_Of_Runs = Number_Of_Runs * 10; - do_fprintf (stdout, "\n"); + printf("\n"); } else Done = true; } - do_fprintf (stderr, "Final values of the variables used in the benchmark:\n"); - do_fprintf (stderr, "\n"); - do_fprintf (stderr, "Int_Glob: %d\n", Int_Glob); - do_fprintf (stderr, " should be: %d\n", 5); - do_fprintf (stderr, "Bool_Glob: %d\n", Bool_Glob); - do_fprintf (stderr, " should be: %d\n", 1); - do_fprintf (stderr, "Ch_1_Glob: %c\n", Ch_1_Glob); - do_fprintf (stderr, " should be: %c\n", 'A'); - do_fprintf (stderr, "Ch_2_Glob: %c\n", Ch_2_Glob); - do_fprintf (stderr, " should be: %c\n", 'B'); - do_fprintf (stderr, "Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]); - do_fprintf (stderr, " should be: %d\n", 7); - do_fprintf (stderr, "Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]); - do_fprintf (stderr, " should be: Number_Of_Runs + 10\n"); - do_fprintf (stderr, "Ptr_Glob->\n"); - do_fprintf (stderr, " Ptr_Comp: %d\n", (long) Ptr_Glob->Ptr_Comp); - do_fprintf (stderr, " should be: (implementation-dependent)\n"); - do_fprintf (stderr, " Discr: %d\n", Ptr_Glob->Discr); - do_fprintf (stderr, " should be: %d\n", 0); - do_fprintf (stderr, " Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp); - do_fprintf (stderr, " should be: %d\n", 2); - do_fprintf (stderr, " Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp); - do_fprintf (stderr, " should be: %d\n", 17); - do_fprintf (stderr, " Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp); - do_fprintf (stderr, " should be: DHRYSTONE PROGRAM, SOME STRING\n"); - do_fprintf (stderr, "Next_Ptr_Glob->\n"); - do_fprintf (stderr, " Ptr_Comp: %d\n", (long) Next_Ptr_Glob->Ptr_Comp); - do_fprintf (stderr, " should be: (implementation-dependent), same as above\n"); - do_fprintf (stderr, " Discr: %d\n", Next_Ptr_Glob->Discr); - do_fprintf (stderr, " should be: %d\n", 0); - do_fprintf (stderr, " Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp); - do_fprintf (stderr, " should be: %d\n", 1); - do_fprintf (stderr, " Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp); - do_fprintf (stderr, " should be: %d\n", 18); - do_fprintf (stderr, " Str_Comp: %s\n", + debug_printf("Final values of the variables used in the benchmark:\n"); + debug_printf("\n"); + debug_printf("Int_Glob: %d\n", Int_Glob); + debug_printf(" should be: %d\n", 5); + debug_printf("Bool_Glob: %d\n", Bool_Glob); + debug_printf(" should be: %d\n", 1); + debug_printf("Ch_1_Glob: %c\n", Ch_1_Glob); + debug_printf(" should be: %c\n", 'A'); + debug_printf("Ch_2_Glob: %c\n", Ch_2_Glob); + debug_printf(" should be: %c\n", 'B'); + debug_printf("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]); + debug_printf(" should be: %d\n", 7); + debug_printf("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]); + debug_printf(" should be: Number_Of_Runs + 10\n"); + debug_printf("Ptr_Glob->\n"); + debug_printf(" Ptr_Comp: %d\n", (long) Ptr_Glob->Ptr_Comp); + debug_printf(" should be: (implementation-dependent)\n"); + debug_printf(" Discr: %d\n", Ptr_Glob->Discr); + debug_printf(" should be: %d\n", 0); + debug_printf(" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp); + debug_printf(" should be: %d\n", 2); + debug_printf(" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp); + debug_printf(" should be: %d\n", 17); + debug_printf(" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp); + debug_printf(" should be: DHRYSTONE PROGRAM, SOME STRING\n"); + debug_printf("Next_Ptr_Glob->\n"); + debug_printf(" Ptr_Comp: %d\n", (long) Next_Ptr_Glob->Ptr_Comp); + debug_printf(" should be: (implementation-dependent), same as above\n"); + debug_printf(" Discr: %d\n", Next_Ptr_Glob->Discr); + debug_printf(" should be: %d\n", 0); + debug_printf(" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp); + debug_printf(" should be: %d\n", 1); + debug_printf(" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp); + debug_printf(" should be: %d\n", 18); + debug_printf(" Str_Comp: %s\n", Next_Ptr_Glob->variant.var_1.Str_Comp); - do_fprintf (stderr, " should be: DHRYSTONE PROGRAM, SOME STRING\n"); - do_fprintf (stderr, "Int_1_Loc: %d\n", Int_1_Loc); - do_fprintf (stderr, " should be: %d\n", 5); - do_fprintf (stderr, "Int_2_Loc: %d\n", Int_2_Loc); - do_fprintf (stderr, " should be: %d\n", 13); - do_fprintf (stderr, "Int_3_Loc: %d\n", Int_3_Loc); - do_fprintf (stderr, " should be: %d\n", 7); - do_fprintf (stderr, "Enum_Loc: %d\n", Enum_Loc); - do_fprintf (stderr, " should be: %d\n", 1); - do_fprintf (stderr, "Str_1_Loc: %s\n", Str_1_Loc); - do_fprintf (stderr, " should be: DHRYSTONE PROGRAM, 1'ST STRING\n"); - do_fprintf (stderr, "Str_2_Loc: %s\n", Str_2_Loc); - do_fprintf (stderr, " should be: DHRYSTONE PROGRAM, 2'ND STRING\n"); - do_fprintf (stderr, "\n"); - - -#if HOST_DEBUG - Microseconds = (float) User_Time * Mic_secs_Per_Second - / ((float) HZ * ((float) Number_Of_Runs)); - Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs) - / (float) User_Time; - - do_fprintf (stdout, "Microseconds for one run through Dhrystone: "); - do_fprintf (stdout, "%10.1f \n", Microseconds); - do_fprintf (stdout, "Dhrystones per Second: "); - do_fprintf (stdout, "%10.0f \n", Dhrystones_Per_Second); - do_fprintf (stdout, "\n"); -#endif + debug_printf(" should be: DHRYSTONE PROGRAM, SOME STRING\n"); + debug_printf("Int_1_Loc: %d\n", Int_1_Loc); + debug_printf(" should be: %d\n", 5); + debug_printf("Int_2_Loc: %d\n", Int_2_Loc); + debug_printf(" should be: %d\n", 13); + debug_printf("Int_3_Loc: %d\n", Int_3_Loc); + debug_printf(" should be: %d\n", 7); + debug_printf("Enum_Loc: %d\n", Enum_Loc); + debug_printf(" should be: %d\n", 1); + debug_printf("Str_1_Loc: %s\n", Str_1_Loc); + debug_printf(" should be: DHRYSTONE PROGRAM, 1'ST STRING\n"); + debug_printf("Str_2_Loc: %s\n", Str_2_Loc); + debug_printf(" should be: DHRYSTONE PROGRAM, 2'ND STRING\n"); + debug_printf("\n"); + + + Microseconds = ((User_Time / Number_Of_Runs) * Mic_secs_Per_Second) / HZ; + Dhrystones_Per_Second = (HZ * Number_Of_Runs) / User_Time; + + printf("Microseconds for one run through Dhrystone: %ld\n", Microseconds); + printf("Dhrystones per Second: %ld\n", Dhrystones_Per_Second); return 0; } -void Proc_1(Rec_Pointer Ptr_Val_Par) +Proc_1 (Ptr_Val_Par) /******************/ + +REG Rec_Pointer Ptr_Val_Par; /* executed once */ { REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; @@ -329,10 +323,12 @@ void Proc_1(Rec_Pointer Ptr_Val_Par) } /* Proc_1 */ -void Proc_2(int* Int_Par_Ref) +Proc_2 (Int_Par_Ref) /******************/ /* executed once */ /* *Int_Par_Ref == 1, becomes 4 */ + +One_Fifty *Int_Par_Ref; { One_Fifty Int_Loc; Enumeration Enum_Loc; @@ -350,10 +346,13 @@ void Proc_2(int* Int_Par_Ref) } /* Proc_2 */ -void Proc_3(Rec_Pointer* Ptr_Ref_Par) +Proc_3 (Ptr_Ref_Par) /******************/ /* executed once */ /* Ptr_Ref_Par becomes Ptr_Glob */ + +Rec_Pointer *Ptr_Ref_Par; + { if (Ptr_Glob != Null) /* then, executed */ @@ -362,7 +361,7 @@ void Proc_3(Rec_Pointer* Ptr_Ref_Par) } /* Proc_3 */ -void Proc_4() +Proc_4 () /* without parameters */ /*******/ /* executed once */ { @@ -374,7 +373,7 @@ void Proc_4() } /* Proc_4 */ -void Proc_5() +Proc_5 () /* without parameters */ /*******/ /* executed once */ { -- 2.30.2