/*
|
This is a MODIFIED version of the Dhrystone 2.1 Benchmark program.
|
|
The only changes which have been made are:
|
1) the 'old-style' K&R function declarations have been replaced with
|
'ANSI-C-style' function declarations (in dhry_1.c and dhry_2,c), and
|
2) function prototypes have been added (in dhry.h)
|
3) dhry.h uses CLOCKS_PER_SEC instead of CLK_TCK (to build with -strict)
|
|
These changes allow an ANSI-C compiler to produce more efficient code, with
|
no warnings.
|
*/
|
|
/*
|
****************************************************************************
|
*
|
* "DHRYSTONE" Benchmark Program
|
* -----------------------------
|
*
|
* Version: C, Version 2.1
|
*
|
* File: dhry_1.c (part 2 of 3)
|
*
|
* Date: May 25, 1988
|
*
|
* Author: Reinhold P. Weicker
|
*
|
****************************************************************************
|
*/
|
|
#include "mk_uart.h"
|
#include "mk_trace.h"
|
#include "mk_reset.h"
|
#include "mk_clock.h"
|
#include "mk_calib.h"
|
#include "mk_wdt.h"
|
#include "mk_gpio.h"
|
#include "libc_rom.h"
|
#include "board.h"
|
#include "dhry.h"
|
|
|
/* Global Variables: */
|
|
Rec_Pointer Ptr_Glob,
|
Next_Ptr_Glob;
|
int Int_Glob;
|
Boolean Bool_Glob;
|
char Ch_1_Glob,
|
Ch_2_Glob;
|
int Arr_1_Glob [50];
|
int Arr_2_Glob [50] [50];
|
|
#ifndef REG
|
Boolean Reg = false;
|
#define REG
|
/* REG becomes defined as empty */
|
/* i.e. no register variables */
|
#else
|
Boolean Reg = true;
|
#endif
|
|
/* variables for time measurement: */
|
|
#ifdef TIMES
|
struct tms time_info;
|
extern int times (void);
|
/* see library function "times" */
|
#define Too_Small_Time (2*HZ)
|
/* Measurements should last at least about 2 seconds */
|
#endif
|
#ifdef TIME
|
extern long time(long *);
|
/* see library function "time" */
|
#define Too_Small_Time 2
|
/* Measurements should last at least 2 seconds */
|
#endif
|
#ifdef MSC_CLOCK
|
extern clock_t clock(void);
|
#define Too_Small_Time (2*HZ)
|
#endif
|
|
long Begin_Time,
|
End_Time,
|
User_Time;
|
float Microseconds,
|
Dhrystones_Per_Second;
|
|
#ifdef NOMSG
|
/*extern void EarlyExit(void);*/
|
#endif
|
|
/* end of variables for time measurement */
|
|
#if defined(__ICCARM__)
|
#pragma diag_suppress = Pe111
|
#endif
|
|
int main(void)
|
/*****/
|
|
/* main program, corresponds to procedures */
|
/* Main and Proc_0 in the Ada version */
|
{
|
One_Fifty Int_1_Loc;
|
REG One_Fifty Int_2_Loc;
|
One_Fifty Int_3_Loc;
|
REG char Ch_Index;
|
Enumeration Enum_Loc;
|
Str_30 Str_1_Loc;
|
Str_30 Str_2_Loc;
|
REG int Run_Index;
|
REG int Number_Of_Runs;
|
|
#ifdef EXPECTED_SYST
|
volatile unsigned *p = (unsigned*)0xE000E010; // Systick
|
#endif
|
|
board_clock_run();
|
board_pins_config();
|
board_debug_console_open(TRACE_PORT_UART0);
|
// Reset reason
|
reset_cause_get();
|
reset_cause_clear();
|
|
// Chip calibration
|
calib_chip();
|
|
// Disable watchdog timer
|
wdt_close(WDT_ID0);
|
mk_printf("Dhrystone\r\n");
|
|
|
gpio_open();
|
board_led_init();
|
board_configure();
|
|
|
/* Initializations */
|
|
Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
|
Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
|
|
Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
|
Ptr_Glob->Discr = Ident_1;
|
Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
|
Ptr_Glob->variant.var_1.Int_Comp = 40;
|
strcpy (Ptr_Glob->variant.var_1.Str_Comp,
|
"DHRYSTONE PROGRAM, SOME STRING");
|
strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
|
|
Arr_2_Glob [8][7] = 10;
|
/* Was missing in published program. Without this statement, */
|
/* Arr_2_Glob [8][7] would have an undefined value. */
|
/* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
|
/* overflow may occur for this array element. */
|
|
#ifdef NOMSG
|
Number_Of_Runs = ITERATIONS;
|
#else
|
mk_printf("\n");
|
mk_printf("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
|
mk_printf("\n");
|
if (Reg)
|
{
|
mk_printf("Program compiled with 'register' attribute\n");
|
mk_printf("\n");
|
}
|
else
|
{
|
mk_printf("Program compiled without 'register' attribute\n");
|
mk_printf("\n");
|
}
|
mk_printf("Please give the number of runs through the benchmark: ");
|
{
|
//int n;
|
// scanf ("%d", &n);
|
Number_Of_Runs = ITERATIONS;
|
}
|
mk_printf("\n");
|
|
mk_printf("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
|
#endif
|
|
/***************/
|
/* Start timer */
|
/***************/
|
board_led_on(BOARD_LED_2);
|
|
#ifdef TIMES
|
times (&time_info);
|
Begin_Time = (long) time_info.tms_utime;
|
#endif
|
#ifdef TIME
|
Begin_Time = time ( (long *) 0);
|
#endif
|
#ifdef MSC_CLOCK
|
#ifdef EXPECTED_SYST
|
p[1] = 0x00FFFFFF; /* Reload value : lots of time */
|
p[2] = 0x0; /* Current value clear to 0x0 */
|
p[0] = 0x1; /* Enable systick, no interrupt */
|
//Begin_Time = (*((volatile unsigned long *)(0xE000E018)));
|
Begin_Time = 0x1000000;
|
#else
|
Begin_Time = 0;
|
#endif
|
#endif
|
for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
|
{
|
|
Proc_5();
|
Proc_4();
|
/* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
|
Int_1_Loc = 2;
|
Int_2_Loc = 3;
|
strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
|
Enum_Loc = Ident_2;
|
Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
|
/* Bool_Glob == 1 */
|
while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
|
{
|
Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
|
/* Int_3_Loc == 7 */
|
Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
|
/* Int_3_Loc == 7 */
|
Int_1_Loc += 1;
|
} /* while */
|
/* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
|
Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
|
/* Int_Glob == 5 */
|
Proc_1 (Ptr_Glob);
|
for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
|
/* loop body executed twice */
|
{
|
if (Enum_Loc == Func_1 (Ch_Index, 'C'))
|
/* then, not executed */
|
{
|
Proc_6 (Ident_1, &Enum_Loc);
|
strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
|
Int_2_Loc = Run_Index;
|
Int_Glob = Run_Index;
|
}
|
}
|
/* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
|
Int_2_Loc = Int_2_Loc * Int_1_Loc;
|
Int_1_Loc = Int_2_Loc / Int_3_Loc;
|
Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
|
/* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
|
Proc_2 (&Int_1_Loc);
|
/* Int_1_Loc == 5 */
|
|
} /* loop "for Run_Index" */
|
|
#ifdef EARLY_EXIT
|
exit(0);
|
#endif
|
/**************/
|
/* Stop timer */
|
/**************/
|
|
#ifdef TIMES
|
times (&time_info);
|
End_Time = (long) time_info.tms_utime;
|
#endif
|
#ifdef TIME
|
End_Time = time ( (long *) 0);
|
#endif
|
#ifdef MSC_CLOCK
|
#ifdef EXPECTED_SYST
|
End_Time = p[2]; // Get current value;
|
#else
|
End_Time = 1;
|
#endif
|
#endif
|
|
board_led_off(BOARD_LED_2);
|
|
#ifdef NOMSG
|
|
#ifdef ENABLE_THUMB
|
mk_printf("\n");
|
mk_printf("\n");
|
exit(1);
|
#else
|
exit(0);
|
/*EarlyExit();*/
|
#endif
|
|
/* Uncomment these lines if compiling with tcc (thumb) */
|
#endif
|
|
mk_printf("Execution ends\n");
|
mk_printf("\n");
|
mk_printf("Final values of the variables used in the benchmark:\n");
|
mk_printf("\n");
|
mk_printf("Int_Glob: %d\n", Int_Glob);
|
mk_printf(" should be: %d\n", 5);
|
mk_printf("Bool_Glob: %d\n", Bool_Glob);
|
mk_printf(" should be: %d\n", 1);
|
mk_printf("Ch_1_Glob: %c\n", Ch_1_Glob);
|
mk_printf(" should be: %c\n", 'A');
|
mk_printf("Ch_2_Glob: %c\n", Ch_2_Glob);
|
mk_printf(" should be: %c\n", 'B');
|
mk_printf("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
|
mk_printf(" should be: %d\n", 7);
|
mk_printf("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
|
mk_printf(" should be: Number_Of_Runs + 10\n");
|
mk_printf("Ptr_Glob->\n");
|
mk_printf(" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
|
mk_printf(" should be: (implementation-dependent)\n");
|
mk_printf(" Discr: %d\n", Ptr_Glob->Discr);
|
mk_printf(" should be: %d\n", 0);
|
mk_printf(" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
|
mk_printf(" should be: %d\n", 2);
|
mk_printf(" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
|
mk_printf(" should be: %d\n", 17);
|
mk_printf(" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
|
mk_printf(" should be: DHRYSTONE PROGRAM, SOME STRING\n");
|
mk_printf("Next_Ptr_Glob->\n");
|
mk_printf(" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
|
mk_printf(" should be: (implementation-dependent), same as above\n");
|
mk_printf(" Discr: %d\n", Next_Ptr_Glob->Discr);
|
mk_printf(" should be: %d\n", 0);
|
mk_printf(" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
|
mk_printf(" should be: %d\n", 1);
|
mk_printf(" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
|
mk_printf(" should be: %d\n", 18);
|
mk_printf(" Str_Comp: %s\n",
|
Next_Ptr_Glob->variant.var_1.Str_Comp);
|
mk_printf(" should be: DHRYSTONE PROGRAM, SOME STRING\n");
|
mk_printf("Int_1_Loc: %d\n", Int_1_Loc);
|
mk_printf(" should be: %d\n", 5);
|
mk_printf("Int_2_Loc: %d\n", Int_2_Loc);
|
mk_printf(" should be: %d\n", 13);
|
mk_printf("Int_3_Loc: %d\n", Int_3_Loc);
|
mk_printf(" should be: %d\n", 7);
|
mk_printf("Enum_Loc: %d\n", Enum_Loc);
|
mk_printf(" should be: %d\n", 1);
|
mk_printf("Str_1_Loc: %s\n", Str_1_Loc);
|
mk_printf(" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
|
mk_printf("Str_2_Loc: %s\n", Str_2_Loc);
|
mk_printf(" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
|
mk_printf("\n");
|
|
#ifdef EXPECTED_SYST
|
User_Time = Begin_Time - End_Time; // SysTick is a decrement counter
|
#else
|
User_Time = End_Time - Begin_Time;
|
#endif
|
|
|
|
mk_printf("Number of cycles for %d iteration is %ld\n",Number_Of_Runs,User_Time);
|
|
|
if (User_Time < Too_Small_Time)
|
{
|
mk_printf("Measured time too small to obtain meaningful results\n");
|
mk_printf("Please increase number of runs\n");
|
mk_printf("\n");
|
}
|
else
|
{
|
#ifdef TIME
|
Microseconds = (float) User_Time * Mic_secs_Per_Second
|
/ (float) Number_Of_Runs;
|
Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
|
#else
|
|
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;
|
#endif
|
mk_printf("Microseconds for one run through Dhrystone: ");
|
mk_printf("%6.1f \n", Microseconds);
|
mk_printf("Dhrystones per Second: ");
|
mk_printf("%6.1f \n", Dhrystones_Per_Second);
|
mk_printf("%.2f DMIPS/MHz \n", Dhrystones_Per_Second/1757/62.5);
|
mk_printf("\n");
|
}
|
|
|
while(1);
|
return 0;
|
}
|
|
|
void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
|
/******************/
|
/* executed once */
|
{
|
REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
|
/* == Ptr_Glob_Next */
|
/* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
|
/* corresponds to "rename" in Ada, "with" in Pascal */
|
|
structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
|
Ptr_Val_Par->variant.var_1.Int_Comp = 5;
|
Next_Record->variant.var_1.Int_Comp
|
= Ptr_Val_Par->variant.var_1.Int_Comp;
|
Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
|
Proc_3 (&Next_Record->Ptr_Comp);
|
/* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
|
== Ptr_Glob->Ptr_Comp */
|
if (Next_Record->Discr == Ident_1)
|
/* then, executed */
|
{
|
Next_Record->variant.var_1.Int_Comp = 6;
|
Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
|
&Next_Record->variant.var_1.Enum_Comp);
|
Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
|
Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
|
&Next_Record->variant.var_1.Int_Comp);
|
}
|
else /* not executed */
|
structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
|
} /* Proc_1 */
|
|
|
void Proc_2 (One_Fifty *Int_Par_Ref)
|
/******************/
|
/* executed once */
|
/* *Int_Par_Ref == 1, becomes 4 */
|
{
|
One_Fifty Int_Loc;
|
Enumeration Enum_Loc;
|
|
Int_Loc = *Int_Par_Ref + 10;
|
do /* executed once */
|
if (Ch_1_Glob == 'A')
|
/* then, executed */
|
{
|
Int_Loc -= 1;
|
*Int_Par_Ref = Int_Loc - Int_Glob;
|
Enum_Loc = Ident_1;
|
} /* if */
|
while (Enum_Loc != Ident_1); /* true */
|
} /* Proc_2 */
|
|
|
void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
|
/******************/
|
/* executed once */
|
/* Ptr_Ref_Par becomes Ptr_Glob */
|
{
|
if (Ptr_Glob != Null)
|
/* then, executed */
|
*Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
|
Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
|
} /* Proc_3 */
|
|
|
void Proc_4 (void) /* without parameters */
|
/*******/
|
/* executed once */
|
{
|
Boolean Bool_Loc;
|
|
Bool_Loc = Ch_1_Glob == 'A';
|
Bool_Glob = Bool_Loc | Bool_Glob;
|
Ch_2_Glob = 'B';
|
} /* Proc_4 */
|
|
|
void Proc_5 (void) /* without parameters */
|
/*******/
|
/* executed once */
|
{
|
Ch_1_Glob = 'A';
|
Bool_Glob = false;
|
} /* Proc_5 */
|
|
|
/* Procedure for the assignment of structures, */
|
/* if the C compiler doesn't support this feature */
|
#ifdef NOSTRUCTASSIGN
|
memcpy (d, s, l)
|
register char *d;
|
register char *s;
|
register int l;
|
{
|
while (l--) *d++ = *s++;
|
}
|
#endif
|