描述
本文来源电子发烧友社区,作者:李先生, 帖子地址:https://bbs.elecfans.com/jishu_2284138_1_1.html
前言
根据描述该新芯片整数计算能力Dhrystone达到4651 DMIPS
我们就实际测试一下。
注:
Dhrystone是于1984年由Reinhold P. Weicker设计的一套综合的基准程序,该程序用来测试CPU(整数)计算性能。其输出结果为每秒钟运行Dhrystone的次数,即每秒钟迭代主循环的次数。
获取代码
http://www.roylongbottom.org.uk/classic_benchmarks.tar.gz
解压classic_benchmarks.tar.gz将classic_benchmarksclassic_benchmarkssource_codedhrystone2文件夹复制到自己的工程。
添加代码
将dhrystone2文件夹复制到工程目录projled下,按如下刷新
看到文件刷新了
修改代码
start_time();
end_time();
local_time();
等接口删除
classic_benchmarksclassic_benchmarkssource_codecommon_32bit的cpuidc.c中实现相应的接口,我们不使用
删除#include "cpuidh.h"相关接口
-
fprintf全部替换为printf
-
浮点打印改为整数打印
-
调用
dhry_1.c中的main改为dhry_main
在main.c的main函数中调用
-
int main(void)
-
-
{
-
-
void dhry_main (int argc, char *argv[]);
-
-
dhry_main(0,0);
-
-
-
-
app_init_led_pins();
-
-
-
-
static uint32_t led_thread_arg = 0;
-
-
rt_thread_t led_thread = rt_thread_create("led_th", thread_entry, &led_thread_arg, 1024, 1, 10);
-
-
rt_thread_startup(led_thread);
-
-
-
-
return 0;
-
-
}
复制代码
测试
考虑优化等级
考虑减少系统抵达中断频率
|
RT_TICK_PER_SECOND=1000
|
RT_TICK_PER_SECOND=100
|
|
优化等级0
|
优化等级3
|
优化等级0
|
优化等级3
|
RAM中运行
|
828DMIPS
|
2508DMIPS
|
|
2536DMIPS
|
ROM中运行
|
828
|
2507DMIPS
|
|
2529DMIPS
|
最后实测大概2536DMIPS和表明的4651 DMIPS差一倍左右,不知道是标注的是双核一起,还是有优化措施可以再提高。
测试代码dhry_1.c
-
/* gcc dhry_1.c dhry_2.c cpuidc64.o cpuida64.o -m64 -lrt -lc -lm -o dhry2
-
*************************************************************************
-
*
-
* "DHRYSTONE" Benchmark Program
-
* -----------------------------
-
*
-
* Version: C, Version 2.1
-
*
-
* File: dhry_1.c (part 2 of 3)
-
*
-
* Date: May 25, 1988
-
*
-
* Author: Reinhold P. Weicker
-
*
-
*************************************************************************
-
*
-
* #define options not used
-
*/
-
-
#include
-
#include
-
#include
-
#include "rtthread.h"
-
#include "dhry.h"
-
//#include "cpuidh.h"
-
-
#ifdef CNNT
-
#define options "Non-optimised"
-
#define opt "0"
-
#else
-
// #define options "Optimised"
-
#define options "Opt 3 64 Bit"
-
#define opt ""
-
#endif
-
-
-
/* 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];
-
-
char Reg_Define[40] = "Register option Selected.";
-
-
-
Enumeration Func_1 (Capital_Letter Ch_1_Par_Val,
-
Capital_Letter Ch_2_Par_Val);
-
/*
-
forward declaration necessary since Enumeration may not simply be int
-
*/
-
-
#ifndef ROPT
-
#define REG
-
/* REG becomes defined as empty */
-
/* i.e. no register variables */
-
#else
-
#define REG register
-
#endif
-
-
void Proc_1 (REG Rec_Pointer Ptr_Val_Par);
-
void Proc_2 (One_Fifty *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 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val,
-
One_Fifty *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);
-
-
Boolean Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref);
-
-
-
/* variables for time measurement: */
-
-
#define Too_Small_Time 2
-
/* Measurements should last at least 2 seconds */
-
-
double User_Time;
-
-
double Microseconds,
-
Dhrystones_Per_Second,
-
Vax_Mips;
-
-
/* end of variables for time measurement */
-
-
-
void dhry_main (int argc, char *argv[])
-
/*****/
-
-
/* 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;
-
int endit, count = 10;
-
FILE *Ap;
-
int errors = 0;
-
int i;
-
int nopause = 1;
-
-
-
/* Initializations */
-
if (argc > 1)
-
{
-
switch (argv[1][0])
-
{
-
case 'N':
-
nopause = 0;
-
break;
-
case 'n':
-
nopause = 0;
-
break;
-
}
-
}
-
-
// if ((Ap = fopen("Dhry.txt","a+")) == NULL)
-
// {
-
// printf(" Can not open Dhry.txtnn");
-
// printf(" Press Enternn");
-
// int g = getchar();
-
// exit(1);
-
// }
-
-
/***********************************************************************
-
* Change for compiler and optimisation used *
-
***********************************************************************/
-
-
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. */
-
-
//getDetails();
-
//for (i=1; i<10; i++)
-
//{
-
// printf("%sn", configdata[i]);
-
//}
-
//printf("n");
-
-
//printf ( " #####################################################nn");
-
//for (i=1; i<10; i++)
-
//{
-
// printf( "%s n", configdata[i]);
-
//}
-
//printf ( "n");
-
-
printf("##########################################n");
-
-
printf ("n");
-
printf ("Dhrystone Benchmark, Version 2.1 (Language: C or C++)n");
-
printf ("n");
-
-
printf ("Optimisation %sn", options);
-
#ifdef ROPT
-
printf ("Register option selectednn");
-
#else
-
printf ("Register option not selectednn");
-
strcpy(Reg_Define, "Register option Not selected.");
-
#endif // "Register option Selected."
-
-
/*
-
if (Reg)
-
{
-
printf ("Program compiled with 'register' attributen");
-
printf ("n");
-
}
-
else
-
{
-
printf ("Program compiled without 'register' attributen");
-
printf ("n");
-
}
-
-
printf ("Please give the number of runs through the benchmark: ");
-
{
-
int n;
-
scanf ("%d", &n);
-
Number_Of_Runs = n;
-
}
-
printf ("n");
-
printf ("Execution starts, %d runs through Dhrystonen",
-
Number_Of_Runs);
-
*/
-
-
Number_Of_Runs = 5000;
-
-
do
-
{
-
-
Number_Of_Runs = Number_Of_Runs * 2;
-
count = count - 1;
-
Arr_2_Glob [8][7] = 10;
-
-
/***************/
-
/* Start timer */
-
/***************/
-
-
///start_time();
-
rt_tick_t start_time = rt_tick_get();
-
-
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" */
-
-
/**************/
-
/* Stop timer */
-
/**************/
-
-
///end_time();
-
///User_Time = secs;
-
User_Time = ((rt_tick_get() - start_time)*1.0)/RT_TICK_PER_SECOND;
-
-
printf ("%d runs %d milliseconds n",Number_Of_Runs, (int)(User_Time*1000));
-
if (User_Time > 2)
-
{
-
count = 0;
-
}
-
else
-
{
-
if (User_Time < 0.05)
-
{
-
Number_Of_Runs = Number_Of_Runs * 5;
-
}
-
}
-
} /* calibrate/run do while */
-
while (count >0);
-
-
printf ("n");
-
printf ("Final values (* implementation-dependent):n");
-
printf ("n");
-
printf ("Int_Glob: ");
-
if (Int_Glob == 5) printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%d ", Int_Glob);
-
-
printf ("Bool_Glob: ");
-
if (Bool_Glob == 1) printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%dn", Bool_Glob);
-
-
printf ("Ch_1_Glob: ");
-
if (Ch_1_Glob == 'A') printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%c ", Ch_1_Glob);
-
-
printf ("Ch_2_Glob: ");
-
if (Ch_2_Glob == 'B') printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%cn", Ch_2_Glob);
-
-
printf ("Arr_1_Glob[8]: ");
-
if (Arr_1_Glob[8] == 7) printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%d ", Arr_1_Glob[8]);
-
-
printf ("Arr_2_Glob8/7: ");
-
if (Arr_2_Glob[8][7] == Number_Of_Runs + 10)
-
printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%10dn", Arr_2_Glob[8][7]);
-
-
printf ("Ptr_Glob-> ");
-
printf (" Ptr_Comp: * %dn", (int) Ptr_Glob->Ptr_Comp);
-
-
printf (" Discr: ");
-
if (Ptr_Glob->Discr == 0) printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%d ", Ptr_Glob->Discr);
-
-
printf ("Enum_Comp: ");
-
if (Ptr_Glob->variant.var_1.Enum_Comp == 2)
-
printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%dn", Ptr_Glob->variant.var_1.Enum_Comp);
-
-
printf (" Int_Comp: ");
-
if (Ptr_Glob->variant.var_1.Int_Comp == 17) printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%d ", Ptr_Glob->variant.var_1.Int_Comp);
-
-
printf ("Str_Comp: ");
-
if (strcmp(Ptr_Glob->variant.var_1.Str_Comp,
-
"DHRYSTONE PROGRAM, SOME STRING") == 0)
-
printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%sn", Ptr_Glob->variant.var_1.Str_Comp);
-
-
printf ("Next_Ptr_Glob-> ");
-
printf (" Ptr_Comp: * %d", (int) Next_Ptr_Glob->Ptr_Comp);
-
printf (" same as aboven");
-
-
printf (" Discr: ");
-
if (Next_Ptr_Glob->Discr == 0)
-
printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%d ", Next_Ptr_Glob->Discr);
-
-
printf ("Enum_Comp: ");
-
if (Next_Ptr_Glob->variant.var_1.Enum_Comp == 1)
-
printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%dn", Next_Ptr_Glob->variant.var_1.Enum_Comp);
-
-
printf (" Int_Comp: ");
-
if (Next_Ptr_Glob->variant.var_1.Int_Comp == 18)
-
printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%d ", Next_Ptr_Glob->variant.var_1.Int_Comp);
-
-
printf ("Str_Comp: ");
-
if (strcmp(Next_Ptr_Glob->variant.var_1.Str_Comp,
-
"DHRYSTONE PROGRAM, SOME STRING") == 0)
-
printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%sn", Next_Ptr_Glob->variant.var_1.Str_Comp);
-
-
printf ("Int_1_Loc: ");
-
if (Int_1_Loc == 5)
-
printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%d ", Int_1_Loc);
-
-
printf ("Int_2_Loc: ");
-
if (Int_2_Loc == 13)
-
printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%dn", Int_2_Loc);
-
-
printf ("Int_3_Loc: ");
-
if (Int_3_Loc == 7)
-
printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%d ", Int_3_Loc);
-
-
printf ("Enum_Loc: ");
-
if (Enum_Loc == 1)
-
printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%d n", Enum_Loc);
-
-
-
printf ("Str_1_Loc: ");
-
if (strcmp(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING") == 0)
-
printf ("O.K. ");
-
-
else printf ("WRONG ");
-
printf ("%sn", Str_1_Loc);
-
-
printf ("Str_2_Loc: ");
-
if (strcmp(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING") == 0)
-
printf ("O.K. ");
-
else printf ("WRONG ");
-
printf ("%sn", Str_2_Loc);
-
-
-
printf ("n");
-
-
-
if (User_Time < Too_Small_Time)
-
{
-
printf ("Measured time too small to obtain meaningful resultsn");
-
printf ("Please increase number of runsn");
-
printf ("n");
-
}
-
else
-
{
-
Microseconds = User_Time * Mic_secs_Per_Second
-
/ (double) Number_Of_Runs;
-
Dhrystones_Per_Second = (double) Number_Of_Runs / User_Time;
-
Vax_Mips = Dhrystones_Per_Second / 1757.0;
-
-
printf ("Microseconds(/1000) for one run through Dhrystone: ");
-
printf ("%d n", (int)(Microseconds*1000));
-
printf ("Dhrystones per Second: ");
-
printf ("%d n", (int)Dhrystones_Per_Second);
-
printf ("VAX MIPS rating = ");
-
printf ("%d n", (int)Vax_Mips);
-
printf ("n");
-
-
-
/************************************************************************
-
* Add results to output file Dhry.txt *
-
************************************************************************/
-
///local_time();
-
///printf ( " #####################################################nn");
-
///printf ( " Dhrystone Benchmark 2.1 %s via C/C++ %sn", options, timeday);
-
///printf ( " VAX MIPS rating: %12.2lfnn",Vax_Mips);
-
-
// printf( " Classic Benchmark Ratings for CPUSpeed.txt where 100 MHz Pentium = 100n");
-
/*
-
if (strtol(opt, NULL, 10) == 1)
-
{
-
printf( " Integer Dhry2 Opt %dnn", (int)(Vax_Mips / 130 * 100));
-
}
-
else
-
{
-
printf( " Integer Dhry2 NoOpt %dnn", (int)(Vax_Mips / 32 * 100));
-
}
-
*/
-
-
if (Int_Glob != 5)
-
{
-
printf ( " Wrong result Int_Glob Was %d Should be 5n", Int_Glob);
-
errors = errors + 1;
-
}
-
if (Bool_Glob != 1)
-
{
-
printf ( " Wrong result Bool_Glob Was %d Should be 1n", Bool_Glob);
-
errors = errors + 1;
-
}
-
if (Ch_1_Glob != 'A')
-
{
-
printf ( " Wrong result Ch_1_Glob Was %c Should be An", Ch_1_Glob);
-
errors = errors + 1;
-
}
-
if (Ch_2_Glob != 'B')
-
{
-
printf ( " Wrong result Ch_2_Glob Was %c Should be Bn", Ch_2_Glob);
-
errors = errors + 1;
-
}
-
if (Arr_1_Glob[8] != 7)
-
{
-
printf ( " Wrong result Arr_1_Glob[8] Was %d Should be 7n", Arr_1_Glob[8]);
-
errors = errors + 1;
-
}
-
if (Arr_2_Glob[8][7] != Number_Of_Runs + 10)
-
{
-
printf ( " Wrong result Arr_2_Glob[8][7] Was %d Should be %dn", Arr_2_Glob[8][7], Number_Of_Runs + 10);
-
errors = errors + 1;
-
}
-
if (Ptr_Glob->Discr != 0)
-
{
-
printf ( " Wrong result Ptr_Glob->Discr Was %d Should be 0n", Ptr_Glob->Discr);
-
errors = errors + 1;
-
}
-
if (Ptr_Glob->variant.var_1.Enum_Comp != 2)
-
{
-
printf ( " Wrong result Ptr_Glob->variant.var_1.Enum_Comp Was %d Should be 2n", Ptr_Glob->variant.var_1.Enum_Comp);
-
errors = errors + 1;
-
}
-
if (Ptr_Glob->variant.var_1.Int_Comp != 17)
-
{
-
printf ( " Wrong result Ptr_Glob->variant.var_1.Int_Comp Was %d Should be 17n", Ptr_Glob->variant.var_1.Int_Comp);
-
errors = errors + 1;
-
}
-
if (strcmp(Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING") != 0)
-
{
-
printf ( " Wrong result Ptr_Glob->variant.var_1.Str_Comp Was %s Should be DHRYSTONE PROGRAM, SOME STRINGn", Ptr_Glob->variant.var_1.Str_Comp);
-
errors = errors + 1;
-
}
-
if (Next_Ptr_Glob->Discr != 0)
-
{
-
printf ( " Wrong result Next_Ptr_Glob->Discr Was %d Should be 0n", Next_Ptr_Glob->Discr);
-
errors = errors + 1;
-
}
-
if (Next_Ptr_Glob->variant.var_1.Enum_Comp != 1)
-
{
-
printf ( " Wrong result Next_Ptr_Glob->variant.var_1.Enum_Comp Was %d Should be 1n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
-
errors = errors + 1;
-
}
-
if (Next_Ptr_Glob->variant.var_1.Int_Comp != 18)
-
{
-
printf ( " Wrong result Next_Ptr_Glob->variant.var_1.Int_Comp Was %d Should be 18n", Next_Ptr_Glob->variant.var_1.Int_Comp);
-
errors = errors + 1;
-
}
-
if (strcmp(Next_Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING") != 0)
-
{
-
printf ( " Wrong result Next_Ptr_Glob->variant.var_1.Str_Comp Was %s Should be DHRYSTONE PROGRAM, SOME STRINGn", Next_Ptr_Glob->variant.var_1.Str_Comp);
-
errors = errors + 1;
-
}
-
if (Int_1_Loc != 5)
-
{
-
printf ( " Wrong result Int_1_Loc Was %d Should be 5n", Int_1_Loc);
-
errors = errors + 1;
-
}
-
if (Int_2_Loc != 13)
-
{
-
printf ( " Wrong result Int_2_Loc Was %d Should be 13n", Int_2_Loc);
-
errors = errors + 1;
-
}
-
if (Int_3_Loc != 7)
-
{
-
printf ( " Wrong result Int_3_Loc Was %d Should be 7n", Int_3_Loc);
-
errors = errors + 1;
-
}
-
if (Enum_Loc != 1)
-
{
-
printf ( " Wrong result Enum_Loc Was %d Should be 1n", Enum_Loc);
-
errors = errors + 1;
-
}
-
if (strcmp(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING") != 0)
-
{
-
printf ( " Wrong result Str_1_Loc Was %s Should be DHRYSTONE PROGRAM, 1'ST STRINGn", Str_1_Loc);
-
errors = errors + 1;
-
}
-
if (strcmp(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING") != 0)
-
{
-
printf ( " Wrong result Str_2_Loc Was %s Should be DHRYSTONE PROGRAM, 2'ND STRINGn", Str_2_Loc);
-
errors = errors + 1;
-
}
-
if (errors == 0)
-
{
-
printf ( " Numeric results were correctnn");
-
}
-
else
-
{
-
printf ( "n");
-
}
-
-
///fclose(Ap);
-
}
-
if (nopause)
-
{
-
printf(" Press Enternn");
-
int g = getchar();
-
}
-
}
-
-
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 () /* 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 () /* 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
-
-
-
-
复制代码
dhry_2.c
-
/*
-
*************************************************************************
-
*
-
* "DHRYSTONE" Benchmark Program
-
* -----------------------------
-
*
-
* Version: C, Version 2.1
-
*
-
* File: dhry_2.c (part 3 of 3)
-
*
-
* Date: May 25, 1988
-
*
-
* Author: Reinhold P. Weicker
-
*
-
*************************************************************************
-
*/
-
-
#include "dhry.h"
-
-
#ifndef REG
-
#define REG
-
/* REG becomes defined as empty */
-
/* i.e. no register variables */
-
#else
-
#define REG register
-
#endif
-
-
extern int Int_Glob;
-
extern char Ch_1_Glob;
-
-
Boolean Func_3 (Enumeration Enum_Par_Val);
-
-
void Proc_6 (Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par)
-
/*********************************/
-
/* executed once */
-
/* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
-
-
{
-
*Enum_Ref_Par = Enum_Val_Par;
-
if (! Func_3 (Enum_Val_Par))
-
/* then, not executed */
-
*Enum_Ref_Par = Ident_4;
-
switch (Enum_Val_Par)
-
{
-
case Ident_1:
-
*Enum_Ref_Par = Ident_1;
-
break;
-
case Ident_2:
-
if (Int_Glob > 100)
-
/* then */
-
*Enum_Ref_Par = Ident_1;
-
else *Enum_Ref_Par = Ident_4;
-
break;
-
case Ident_3: /* executed */
-
*Enum_Ref_Par = Ident_2;
-
break;
-
case Ident_4: break;
-
case Ident_5:
-
*Enum_Ref_Par = Ident_3;
-
break;
-
} /* switch */
-
} /* Proc_6 */
-
-
-
void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val,
-
One_Fifty *Int_Par_Ref)
-
/**********************************************/
-
/* executed three times */
-
/* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */
-
/* Int_Par_Ref becomes 7 */
-
/* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
-
/* 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_Loc;
-
-
Int_Loc = Int_1_Par_Val + 2;
-
*Int_Par_Ref = Int_2_Par_Val + Int_Loc;
-
} /* 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)
-
/*********************************************************************/
-
/* executed once */
-
/* Int_Par_Val_1 == 3 */
-
/* Int_Par_Val_2 == 7 */
-
-
{
-
REG One_Fifty Int_Index;
-
REG One_Fifty Int_Loc;
-
-
Int_Loc = Int_1_Par_Val + 5;
-
Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
-
Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
-
Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
-
for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
-
Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
-
Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
-
Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
-
Int_Glob = 5;
-
} /* Proc_8 */
-
-
-
Enumeration Func_1 (Capital_Letter Ch_1_Par_Val,
-
Capital_Letter 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_Loc;
-
Capital_Letter Ch_2_Loc;
-
-
Ch_1_Loc = Ch_1_Par_Val;
-
Ch_2_Loc = Ch_1_Loc;
-
if (Ch_2_Loc != Ch_2_Par_Val)
-
/* then, executed */
-
return (Ident_1);
-
else /* not executed */
-
{
-
Ch_1_Glob = Ch_1_Loc;
-
return (Ident_2);
-
}
-
} /* Func_1 */
-
-
-
Boolean Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref)
-
/*************************************************/
-
/* executed once */
-
/* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
-
/* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
-
-
{
-
REG One_Thirty Int_Loc;
-
Capital_Letter Ch_Loc;
-
-
Int_Loc = 2;
-
while (Int_Loc <= 2) /* loop body executed once */
-
if (Func_1 (Str_1_Par_Ref[Int_Loc],
-
Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
-
/* then, executed */
-
{
-
Ch_Loc = 'A';
-
Int_Loc += 1;
-
} /* if, while */
-
if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
-
/* then, not executed */
-
Int_Loc = 7;
-
if (Ch_Loc == 'R')
-
/* then, not executed */
-
return (true);
-
else /* executed */
-
{
-
if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
-
/* then, not executed */
-
{
-
Int_Loc += 7;
-
Int_Glob = Int_Loc;
-
return (true);
-
}
-
else /* executed */
-
return (false);
-
} /* if Ch_Loc */
-
} /* Func_2 */
-
-
-
Boolean Func_3 (Enumeration Enum_Par_Val)
-
/***************************/
-
/* executed once */
-
/* Enum_Par_Val == Ident_3 */
-
-
{
-
Enumeration Enum_Loc;
-
-
Enum_Loc = Enum_Par_Val;
-
if (Enum_Loc == Ident_3)
-
/* then, executed */
-
return (true);
-
else /* not executed */
-
return (false);
-
} /* Func_3 */
-
复制代码
dhry.h
-
/*
-
**************************************************************************
-
* DHRYSTONE 2.1 BENCHMARK PC VERSION
-
**************************************************************************
-
*
-
* "DHRYSTONE" Benchmark Program
-
* -----------------------------
-
*
-
* Version: C, Version 2.1
-
*
-
* File: dhry.h (part 1 of 3)
-
*
-
* Date: May 25, 1988
-
*
-
* Author: Reinhold P. Weicker
-
* Siemens AG, AUT E 51
-
* Postfach 3220
-
* 8520 Erlangen
-
* Germany (West)
-
* Phone: [+49]-9131-7-20330
-
* (8-17 Central European Time)
-
* Usenet: ..!mcsun!unido!estevax!weicker
-
*
-
* Original Version (in Ada) published in
-
* "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
-
* pp. 1013 - 1030, together with the statistics
-
* on which the distribution of statements etc. is based.
-
*
-
* In this C version, the following C library functions are used:
-
* - strcpy, strcmp (inside the measurement loop)
-
* - printf, scanf (outside the measurement loop)
-
* In addition, Berkeley UNIX system calls "times ()" or "time ()"
-
* are used for execution time measurement. For measurements
-
* on other systems, these calls have to be changed.
-
*
-
* Collection of Results:
-
* Reinhold Weicker (address see above) and
-
*
-
* Rick Richardson
-
* PC Research. Inc.
-
* 94 Apple Orchard Drive
-
* Tinton Falls, NJ 07724
-
* Phone: (201) 389-8963 (9-17 EST)
-
* Usenet: ...!uunet!pcrat!rick
-
*
-
* Please send results to Rick Richardson and/or Reinhold Weicker.
-
* Complete information should be given on hardware and software used.
-
* Hardware information includes: Machine type, CPU, type and size
-
* of caches; for microprocessors: clock frequency, memory speed
-
* (number of wait states).
-
* Software information includes: Compiler (and runtime library)
-
* manufacturer and version, compilation switches, OS version.
-
* The Operating System version may give an indication about the
-
* compiler; Dhrystone itself performs no OS calls in the measurement
-
* loop.
-
*
-
* The complete output generated by the program should be mailed
-
* such that at least some checks for correctness can be made.
-
*
-
**************************************************************************
-
*
-
* This version has changes made by Roy Longbottom to conform to a common
-
* format for a series of standard benchmarks for PCs:
-
*
-
* Running time greater than 5 seconds due to inaccuracy of the PC clock.
-
*
-
* Automatic adjustment of run time, no manually inserted parameters.
-
*
-
* Initial display of calibration times to confirm linearity.
-
*
-
* Display of results within one screen (or at a slow speed as the test
-
* progresses) so that it can be seen to have run successfully.
-
*
-
* Facilities to type in details of system used etc.
-
*
-
* All results and details appended to a results file.
-
*
-
*
-
* Roy Longbottom
-
* 101323.2241@compuserve.com
-
*
-
**************************************************************************
-
*
-
* For details of history, changes, other defines, benchmark construction
-
* statistics see official versions from ftp.nosc.mil/pub/aburto where
-
* the latest table of results (dhry.tbl) are available. See also
-
* netlib@ornl.gov
-
*
-
**************************************************************************
-
*
-
* Defines: The following "Defines" are possible:
-
* -DREG=register (default: Not defined)
-
* As an approximation to what an average C programmer
-
* might do, the "register" storage class is applied
-
* (if enabled by -DREG=register)
-
* - for local variables, if they are used (dynamically)
-
* five or more times
-
* - for parameters if they are used (dynamically)
-
* six or more times
-
* Note that an optimal "register" strategy is
-
* compiler-dependent, and that "register" declarations
-
* do not necessarily lead to faster execution.
-
* -DNOSTRUCTASSIGN (default: Not defined)
-
* Define if the C compiler does not support
-
* assignment of structures.
-
* -DNOENUMS (default: Not defined)
-
* Define if the C compiler does not support
-
* enumeration types.
-
***************************************************************************
-
*
-
* Compilation model and measurement (IMPORTANT):
-
*
-
* This C version of Dhrystone consists of three files:
-
* - dhry.h (this file, containing global definitions and comments)
-
* - dhry_1.c (containing the code corresponding to Ada package Pack_1)
-
* - dhry_2.c (containing the code corresponding to Ada package Pack_2)
-
*
-
* The following "ground rules" apply for measurements:
-
* - Separate compilation
-
* - No procedure merging
-
* - Otherwise, compiler optimizations are allowed but should be indicated
-
* - Default results are those without register declarations
-
* See the companion paper "Rationale for Dhrystone Version 2" for a more
-
* detailed discussion of these ground rules.
-
*
-
* For 16-Bit processors (e.g. 80186, 80286), times for all compilation
-
* models ("small", "medium", "large" etc.) should be given if possible,
-
* together with a definition of these models for the compiler system used.
-
*
-
**************************************************************************
-
* Examples of Pentium Results
-
*
-
* Dhrystone Benchmark Version 2.1 (Language: C)
-
*
-
* Month run 4/1996
-
* PC model Escom
-
* CPU Pentium
-
* Clock MHz 100
-
* Cache 256K
-
* Options Neptune chipset
-
* OS/DOS Windows 95
-
* Compiler Watcom C/ C++ 10.5 Win386
-
* OptLevel -otexan -zp8 -fp5 -5r
-
* Run by Roy Longbottom
-
* From UK
-
* Mail 101323.2241@compuserve.com
-
*
-
* Final values (* implementation-dependent):
-
*
-
* Int_Glob: O.K. 5
-
* Bool_Glob: O.K. 1
-
* Ch_1_Glob: O.K. A
-
* Ch_2_Glob: O.K. B
-
* Arr_1_Glob[8]: O.K. 7
-
* Arr_2_Glob8/7: O.K. 1600010
-
* Ptr_Glob->
-
* Ptr_Comp: * 98008
-
* Discr: O.K. 0
-
* Enum_Comp: O.K. 2
-
* Int_Comp: O.K. 17
-
* Str_Comp: O.K. DHRYSTONE PROGRAM, SOME STRING
-
* Next_Ptr_Glob->
-
* Ptr_Comp: * 98008 same as above
-
* Discr: O.K. 0
-
* Enum_Comp: O.K. 1
-
* Int_Comp: O.K. 18
-
* Str_Comp: O.K. DHRYSTONE PROGRAM, SOME STRING
-
* Int_1_Loc: O.K. 5
-
* Int_2_Loc: O.K. 13
-
* Int_3_Loc: O.K. 7
-
* Enum_Loc: O.K. 1
-
* Str_1_Loc: O.K. DHRYSTONE PROGRAM, 1'ST STRING
-
* Str_2_Loc: O.K. DHRYSTONE PROGRAM, 2'ND STRING
-
*
-
* Register option Selected.
-
*
-
* Microseconds 1 loop: 4.53
-
* Dhrystones / second: 220690
-
* VAX MIPS rating: 125.61
-
*
-
*
-
* Dhrystone Benchmark Version 2.1 (Language: C)
-
*
-
* Month run 4/1996
-
* PC model Escom
-
* CPU Pentium
-
* Clock MHz 100
-
* Cache 256K
-
* Options Neptune chipset
-
* OS/DOS Windows 95
-
* Compiler Watcom C/ C++ 10.5 Win386
-
* OptLevel No optimisation
-
* Run by Roy Longbottom
-
* From UK
-
* Mail 101323.2241@compuserve.com
-
*
-
* Final values (* implementation-dependent):
-
*
-
* Int_Glob: O.K. 5
-
* Bool_Glob: O.K. 1
-
* Ch_1_Glob: O.K. A
-
* Ch_2_Glob: O.K. B
-
* Arr_1_Glob[8]: O.K. 7
-
* Arr_2_Glob8/7: O.K. 320010
-
* Ptr_Glob->
-
* Ptr_Comp: * 98004
-
* Discr: O.K. 0
-
* Enum_Comp: O.K. 2
-
* Int_Comp: O.K. 17
-
* Str_Comp: O.K. DHRYSTONE PROGRAM, SOME STRING
-
* Next_Ptr_Glob->
-
* Ptr_Comp: * 98004 same as above
-
* Discr: O.K. 0
-
* Enum_Comp: O.K. 1
-
* Int_Comp: O.K. 18
-
* Str_Comp: O.K. DHRYSTONE PROGRAM, SOME STRING
-
* Int_1_Loc: O.K. 5
-
* Int_2_Loc: O.K. 13
-
* Int_3_Loc: O.K. 7
-
* Enum_Loc: O.K. 1
-
* Str_1_Loc: O.K. DHRYSTONE PROGRAM, 1'ST STRING
-
* Str_2_Loc: O.K. DHRYSTONE PROGRAM, 2'ND STRING
-
*
-
* Register option Not selected.
-
*
-
* Microseconds 1 loop: 20.06
-
* Dhrystones / second: 49844
-
* VAX MIPS rating: 28.37
-
*
-
**************************************************************************
-
*/
-
-
/* Compiler and system dependent definitions: */
-
-
#ifndef TIME
-
#define TIMES
-
#endif
-
/* Use times(2) time function unless */
-
/* explicitly defined otherwise */
-
-
#ifdef TIMES
-
/* #include
-
#include */
-
/* for "times" */
-
#endif
-
-
#define Mic_secs_Per_Second 1000000.0
-
/* Berkeley UNIX C returns process times in seconds/HZ */
-
-
#ifdef NOSTRUCTASSIGN
-
#define structassign(d, s) memcpy(&(d), &(s), sizeof(d))
-
#else
-
#define structassign(d, s) d = s
-
#endif
-
-
#ifdef NOENUM
-
#define Ident_1 0
-
#define Ident_2 1
-
#define Ident_3 2
-
#define Ident_4 3
-
#define Ident_5 4
-
typedef int Enumeration;
-
#else
-
typedef enum {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
-
Enumeration;
-
#endif
-
/* for boolean and enumeration types in Ada, Pascal */
-
-
/* General definitions: */
-
-
#include
-
#include
-
-
/* for strcpy, strcmp */
-
-
#define Null 0
-
/* Value of a Null pointer */
-
#define true 1
-
#define false 0
-
-
typedef int One_Thirty;
-
typedef int One_Fifty;
-
typedef char Capital_Letter;
-
typedef int Boolean;
-
typedef char Str_30 [31];
-
typedef int Arr_1_Dim [50];
-
typedef int Arr_2_Dim [50] [50];
-
-
typedef struct record
-
{
-
struct record *Ptr_Comp;
-
Enumeration Discr;
-
union {
-
struct {
-
Enumeration Enum_Comp;
-
int Int_Comp;
-
char Str_Comp [31];
-
} var_1;
-
struct {
-
Enumeration E_Comp_2;
-
char Str_2_Comp [31];
-
} var_2;
-
struct {
-
char Ch_1_Comp;
-
char Ch_2_Comp;
-
} var_3;
-
} variant;
-
} Rec_Type, *Rec_Pointer;
-
-
-
-
复制代码
打开APP阅读更多精彩内容