RISC-V技术william hill官网
直播中

jf_1137202360

8年用户 1358经验值
擅长:嵌入式技术
私信 关注
[经验]

【先楫半导体HPM6750EVKMINI评估板试用体验】基准性能测试之一:整数计算能力Dhrystone

前言
根据描述该新芯片整数计算能力Dhrystone达到4651 DMIPS
图片1.png
我们就实际测试一下。
:
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下,按如下刷新
图片2.png
看到文件刷新了
图片3.png
修改代码
  • 主要添加时间测量接口
使用rt_tick_get
start_time();
end_time();
local_time();
等接口删除
  • 删除CPU相关接口
classic_benchmarksclassic_benchmarkssource_codecommon_32bitcpuidc.c中实现相应的接口,我们不使用
删除#include "cpuidh.h"相关接口
  • 修改dhry_1.c
  • fprintf全部替换为printf
  • 浮点打印改为整数打印
  • 调用
dhry_1.c中的main改为dhry_main
main.c的main函数中调用
  1. int main(void)

  2. {

  3.     void dhry_main (int argc, char *argv[]);

  4.     dhry_main(0,0);



  5.     app_init_led_pins();



  6.     static uint32_t led_thread_arg = 0;

  7.     rt_thread_t led_thread = rt_thread_create("led_th", thread_entry, &led_thread_arg, 1024, 1, 10);

  8.     rt_thread_startup(led_thread);



  9.     return 0;

  10. }


测试
考虑优化等级
考虑减少系统抵达中断频率
图片4.png
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
  1. /*       gcc dhry_1.c dhry_2.c cpuidc64.o cpuida64.o -m64 -lrt -lc -lm -o dhry2
  2. *************************************************************************
  3. *
  4. *                   "DHRYSTONE" Benchmark Program
  5. *                   -----------------------------
  6. *
  7. *  Version:    C, Version 2.1
  8. *
  9. *  File:       dhry_1.c (part 2 of 3)
  10. *
  11. *  Date:       May 25, 1988
  12. *
  13. *  Author:     Reinhold P. Weicker
  14. *
  15. *************************************************************************
  16. *
  17. *     #define options not used
  18. */

  19. #include
  20. #include
  21. #include
  22. #include "rtthread.h"
  23. #include "dhry.h"
  24. //#include "cpuidh.h"

  25. #ifdef CNNT
  26.     #define options   "Non-optimised"
  27.     #define opt "0"
  28. #else
  29. //    #define options   "Optimised"
  30.     #define options   "Opt 3 64 Bit"
  31.     #define opt ""
  32. #endif


  33. /* Global Variables: */

  34. Rec_Pointer     Ptr_Glob,
  35.                  Next_Ptr_Glob;
  36. int             Int_Glob;
  37. Boolean         Bool_Glob;
  38. char            Ch_1_Glob,
  39.                  Ch_2_Glob;
  40. int             Arr_1_Glob [50];
  41. int             Arr_2_Glob [50] [50];

  42. char Reg_Define[40] = "Register option      Selected.";


  43. Enumeration Func_1 (Capital_Letter Ch_1_Par_Val,
  44.                                            Capital_Letter Ch_2_Par_Val);
  45.    /*
  46.    forward declaration necessary since Enumeration may not simply be int
  47.    */

  48. #ifndef ROPT
  49. #define REG
  50.          /* REG becomes defined as empty */
  51.          /* i.e. no register variables   */
  52. #else
  53. #define REG register
  54. #endif

  55. void Proc_1 (REG Rec_Pointer Ptr_Val_Par);
  56. void Proc_2 (One_Fifty *Int_Par_Ref);
  57. void Proc_3 (Rec_Pointer *Ptr_Ref_Par);
  58. void Proc_4 ();
  59. void Proc_5 ();
  60. void Proc_6 (Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par);
  61. void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val,
  62.                                               One_Fifty *Int_Par_Ref);
  63. void Proc_8 (Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref,
  64.                                int Int_1_Par_Val, int Int_2_Par_Val);
  65.                               
  66. Boolean Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref);


  67. /* variables for time measurement: */

  68. #define Too_Small_Time 2
  69.                  /* Measurements should last at least 2 seconds */

  70. double         User_Time;

  71. double          Microseconds,
  72.                  Dhrystones_Per_Second,
  73.                  Vax_Mips;

  74. /* end of variables for time measurement */


  75. void dhry_main (int argc, char *argv[])
  76. /*****/

  77.    /* main program, corresponds to procedures        */
  78.    /* Main and Proc_0 in the Ada version             */
  79. {

  80.          One_Fifty   Int_1_Loc;
  81.    REG   One_Fifty   Int_2_Loc;
  82.          One_Fifty   Int_3_Loc;
  83.    REG   char        Ch_Index;
  84.          Enumeration Enum_Loc;
  85.          Str_30      Str_1_Loc;
  86.          Str_30      Str_2_Loc;
  87.    REG   int         Run_Index;
  88.    REG   int         Number_Of_Runs;
  89.          int         endit, count = 10;
  90.          FILE        *Ap;
  91.          int         errors = 0;
  92.          int         i;
  93.          int         nopause = 1;


  94.    /* Initializations */
  95.     if (argc > 1)
  96.      {
  97.         switch (argv[1][0])
  98.          {
  99.              case 'N':
  100.                 nopause = 0;
  101.                 break;
  102.              case 'n':
  103.                nopause = 0;
  104.                break;
  105.          }
  106.       }

  107.   // if ((Ap = fopen("Dhry.txt","a+")) == NULL)
  108.   //   {
  109.    //     printf(" Can not open Dhry.txtnn");
  110.    //     printf(" Press Enternn");
  111.   //      int g = getchar();
  112.    //     exit(1);
  113.    //  }

  114. /***********************************************************************
  115. *         Change for compiler and optimisation used                   *
  116. ***********************************************************************/

  117.    Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  118.    Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));

  119.    Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
  120.    Ptr_Glob->Discr                       = Ident_1;
  121.    Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
  122.    Ptr_Glob->variant.var_1.Int_Comp      = 40;
  123.    strcpy (Ptr_Glob->variant.var_1.Str_Comp,
  124.            "DHRYSTONE PROGRAM, SOME STRING");      
  125.    strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");

  126.    Arr_2_Glob [8][7] = 10;
  127.          /* Was missing in published program. Without this statement,   */
  128.          /* Arr_2_Glob [8][7] would have an undefined value.            */
  129.          /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
  130.          /* overflow may occur for this array element.                  */

  131.     //getDetails();
  132.     //for (i=1; i<10; i++)
  133.     //{
  134.     //    printf("%sn", configdata[i]);
  135.     //}
  136.     //printf("n");

  137.     //printf ( " #####################################################nn");
  138.     //for (i=1; i<10; i++)
  139.     //{
  140.     //    printf( "%s n", configdata[i]);
  141.     //}
  142.     //printf ( "n");

  143.     printf("##########################################n");

  144.    printf ("n");
  145.    printf ("Dhrystone Benchmark, Version 2.1 (Language: C or C++)n");
  146.    printf ("n");
  147.    
  148.    printf ("Optimisation    %sn", options);
  149.    #ifdef ROPT
  150.        printf ("Register option selectednn");
  151.    #else
  152.        printf ("Register option not selectednn");
  153.        strcpy(Reg_Define, "Register option  Not selected.");
  154.    #endif              //   "Register option      Selected."

  155. /*  
  156.    if (Reg)
  157.    {
  158.      printf ("Program compiled with 'register' attributen");
  159.      printf ("n");
  160.    }
  161.    else
  162.    {
  163.      printf ("Program compiled without 'register' attributen");
  164.      printf ("n");
  165.    }

  166.    printf ("Please give the number of runs through the benchmark: ");
  167.    {
  168.      int n;
  169.      scanf ("%d", &n);
  170.      Number_Of_Runs = n;
  171.    }   
  172.    printf ("n");
  173.    printf ("Execution starts, %d runs through Dhrystonen",
  174.                                                  Number_Of_Runs);
  175. */

  176.    Number_Of_Runs = 5000;

  177.    do
  178.    {

  179.        Number_Of_Runs = Number_Of_Runs * 2;
  180.        count = count - 1;
  181.        Arr_2_Glob [8][7] = 10;
  182.         
  183.        /***************/
  184.        /* Start timer */
  185.        /***************/
  186.   
  187.        ///start_time();
  188.        rt_tick_t start_time = rt_tick_get();
  189.    
  190.        for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
  191.        {

  192.          Proc_5();
  193.          Proc_4();
  194.            /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
  195.          Int_1_Loc = 2;
  196.          Int_2_Loc = 3;
  197.          strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  198.          Enum_Loc = Ident_2;
  199.          Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
  200.            /* Bool_Glob == 1 */
  201.          while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
  202.          {
  203.            Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
  204.              /* Int_3_Loc == 7 */
  205.            Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  206.              /* Int_3_Loc == 7 */
  207.            Int_1_Loc += 1;
  208.          }   /* while */
  209.             /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  210.          Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  211.            /* Int_Glob == 5 */
  212.          Proc_1 (Ptr_Glob);
  213.          for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
  214.                               /* loop body executed twice */
  215.          {
  216.            if (Enum_Loc == Func_1 (Ch_Index, 'C'))
  217.                /* then, not executed */
  218.              {
  219.                Proc_6 (Ident_1, &Enum_Loc);
  220.                strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  221.                Int_2_Loc = Run_Index;
  222.                Int_Glob = Run_Index;
  223.              }
  224.          }
  225.            /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  226.          Int_2_Loc = Int_2_Loc * Int_1_Loc;
  227.          Int_1_Loc = Int_2_Loc / Int_3_Loc;
  228.          Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  229.            /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  230.          Proc_2 (&Int_1_Loc);
  231.            /* Int_1_Loc == 5 */

  232.        }   /* loop "for Run_Index" */

  233.        /**************/
  234.        /* Stop timer */
  235.        /**************/

  236.        ///end_time();
  237.        ///User_Time = secs;
  238.        User_Time = ((rt_tick_get() - start_time)*1.0)/RT_TICK_PER_SECOND;
  239.             
  240.        printf ("%d runs %d milliseconds n",Number_Of_Runs, (int)(User_Time*1000));
  241.        if (User_Time > 2)
  242.        {
  243.              count = 0;
  244.        }
  245.        else
  246.        {
  247.              if (User_Time < 0.05)
  248.              {
  249.                   Number_Of_Runs = Number_Of_Runs * 5;
  250.              }
  251.        }
  252.    }   /* calibrate/run do while */
  253.    while (count >0);

  254.    printf ("n");
  255.    printf ("Final values (* implementation-dependent):n");
  256.    printf ("n");
  257.    printf ("Int_Glob:      ");
  258.    if (Int_Glob == 5)  printf ("O.K.  ");
  259.    else                printf ("WRONG ");
  260.    printf ("%d  ", Int_Glob);
  261.       
  262.    printf ("Bool_Glob:     ");
  263.    if (Bool_Glob == 1) printf ("O.K.  ");
  264.    else                printf ("WRONG ");
  265.    printf ("%dn", Bool_Glob);
  266.       
  267.    printf ("Ch_1_Glob:     ");
  268.    if (Ch_1_Glob == 'A')  printf ("O.K.  ");               
  269.    else                   printf ("WRONG ");
  270.    printf ("%c  ", Ch_1_Glob);
  271.          
  272.    printf ("Ch_2_Glob:     ");
  273.    if (Ch_2_Glob == 'B')  printf ("O.K.  ");
  274.    else                   printf ("WRONG ");
  275.    printf ("%cn",  Ch_2_Glob);
  276.    
  277.    printf ("Arr_1_Glob[8]: ");
  278.    if (Arr_1_Glob[8] == 7)  printf ("O.K.  ");
  279.    else                     printf ("WRONG ");
  280.    printf ("%d  ", Arr_1_Glob[8]);
  281.             
  282.    printf ("Arr_2_Glob8/7: ");
  283.    if (Arr_2_Glob[8][7] == Number_Of_Runs + 10)
  284.                           printf ("O.K.  ");
  285.    else                   printf ("WRONG ");
  286.    printf ("%10dn", Arr_2_Glob[8][7]);
  287.    
  288.    printf ("Ptr_Glob->            ");
  289.    printf ("  Ptr_Comp:       *    %dn", (int) Ptr_Glob->Ptr_Comp);
  290.    
  291.    printf ("  Discr:       ");
  292.    if (Ptr_Glob->Discr == 0)  printf ("O.K.  ");
  293.    else                       printf ("WRONG ");
  294.    printf ("%d  ", Ptr_Glob->Discr);
  295.             
  296.    printf ("Enum_Comp:     ");
  297.    if (Ptr_Glob->variant.var_1.Enum_Comp == 2)
  298.                         printf ("O.K.  ");
  299.    else                printf ("WRONG ");
  300.    printf ("%dn", Ptr_Glob->variant.var_1.Enum_Comp);
  301.       
  302.    printf ("  Int_Comp:    ");
  303.    if (Ptr_Glob->variant.var_1.Int_Comp == 17)  printf ("O.K.  ");
  304.    else                                         printf ("WRONG ");
  305.    printf ("%d ", Ptr_Glob->variant.var_1.Int_Comp);
  306.       
  307.    printf ("Str_Comp:      ");
  308.    if (strcmp(Ptr_Glob->variant.var_1.Str_Comp,
  309.                         "DHRYSTONE PROGRAM, SOME STRING") == 0)
  310.                         printf ("O.K.  ");
  311.    else                printf ("WRONG ");   
  312.    printf ("%sn", Ptr_Glob->variant.var_1.Str_Comp);
  313.    
  314.    printf ("Next_Ptr_Glob->       ");
  315.    printf ("  Ptr_Comp:       *    %d", (int) Next_Ptr_Glob->Ptr_Comp);
  316.    printf (" same as aboven");
  317.    
  318.    printf ("  Discr:       ");
  319.    if (Next_Ptr_Glob->Discr == 0)
  320.                         printf ("O.K.  ");
  321.    else                printf ("WRONG ");
  322.    printf ("%d  ", Next_Ptr_Glob->Discr);
  323.    
  324.    printf ("Enum_Comp:     ");
  325.    if (Next_Ptr_Glob->variant.var_1.Enum_Comp == 1)
  326.                         printf ("O.K.  ");
  327.    else                printf ("WRONG ");
  328.    printf ("%dn", Next_Ptr_Glob->variant.var_1.Enum_Comp);
  329.    
  330.    printf ("  Int_Comp:    ");
  331.    if (Next_Ptr_Glob->variant.var_1.Int_Comp == 18)
  332.                         printf ("O.K.  ");
  333.    else                printf ("WRONG ");
  334.    printf ("%d ", Next_Ptr_Glob->variant.var_1.Int_Comp);
  335.    
  336.    printf ("Str_Comp:      ");
  337.    if (strcmp(Next_Ptr_Glob->variant.var_1.Str_Comp,
  338.                         "DHRYSTONE PROGRAM, SOME STRING") == 0)
  339.                         printf ("O.K.  ");
  340.    else                printf ("WRONG ");   
  341.    printf ("%sn", Next_Ptr_Glob->variant.var_1.Str_Comp);
  342.    
  343.    printf ("Int_1_Loc:     ");
  344.    if (Int_1_Loc == 5)
  345.                         printf ("O.K.  ");
  346.    else                printf ("WRONG ");
  347.    printf ("%d  ", Int_1_Loc);
  348.       
  349.    printf ("Int_2_Loc:     ");
  350.    if (Int_2_Loc == 13)
  351.                         printf ("O.K.  ");
  352.    else                printf ("WRONG ");
  353.    printf ("%dn", Int_2_Loc);
  354.    
  355.    printf ("Int_3_Loc:     ");
  356.    if (Int_3_Loc == 7)
  357.                         printf ("O.K.  ");
  358.    else                printf ("WRONG ");
  359.    printf ("%d  ", Int_3_Loc);
  360.    
  361.    printf ("Enum_Loc:      ");
  362.    if (Enum_Loc == 1)
  363.                         printf ("O.K.  ");
  364.    else                printf ("WRONG ");
  365.    printf ("%d  n", Enum_Loc);
  366.    
  367.    
  368.    printf ("Str_1_Loc:                             ");
  369.    if (strcmp(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING") == 0)
  370.                         printf ("O.K.  ");

  371.    else                printf ("WRONG ");   
  372.    printf ("%sn", Str_1_Loc);

  373.    printf ("Str_2_Loc:                             ");
  374.    if (strcmp(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING") == 0)
  375.                         printf ("O.K.  ");
  376.    else                printf ("WRONG ");   
  377.    printf ("%sn", Str_2_Loc);
  378.          

  379.    printf ("n");
  380.    

  381.    if (User_Time < Too_Small_Time)
  382.    {
  383.      printf ("Measured time too small to obtain meaningful resultsn");
  384.      printf ("Please increase number of runsn");
  385.      printf ("n");
  386.    }
  387.    else
  388.    {
  389.      Microseconds = User_Time * Mic_secs_Per_Second
  390.                          / (double) Number_Of_Runs;
  391.      Dhrystones_Per_Second = (double) Number_Of_Runs / User_Time;
  392.      Vax_Mips = Dhrystones_Per_Second / 1757.0;

  393.      printf ("Microseconds(/1000) for one run through Dhrystone: ");
  394.      printf ("%d n", (int)(Microseconds*1000));
  395.      printf ("Dhrystones per Second:                      ");
  396.      printf ("%d n",  (int)Dhrystones_Per_Second);
  397.      printf ("VAX  MIPS rating =                          ");
  398.      printf ("%d n", (int)Vax_Mips);
  399.      printf ("n");


  400. /************************************************************************
  401. *                Add results to output file Dhry.txt                   *
  402. ************************************************************************/
  403.    ///local_time();
  404.    ///printf ( " #####################################################nn");
  405.    ///printf ( " Dhrystone Benchmark 2.1 %s via C/C++ %sn", options, timeday);
  406.    ///printf ( " VAX MIPS rating:      %12.2lfnn",Vax_Mips);

  407. //   printf( " Classic Benchmark Ratings for CPUSpeed.txt where 100 MHz Pentium = 100n");
  408. /*
  409.    if (strtol(opt, NULL, 10) == 1)
  410.    {
  411.        printf( " Integer Dhry2 Opt %dnn", (int)(Vax_Mips / 130 * 100));
  412.    }
  413.    else
  414.    {
  415.        printf( " Integer Dhry2 NoOpt %dnn", (int)(Vax_Mips / 32 * 100));
  416.    }
  417. */   

  418.    if (Int_Glob != 5)
  419.    {
  420.        printf ( " Wrong result Int_Glob Was %d Should be 5n", Int_Glob);
  421.        errors = errors + 1;
  422.    }
  423.    if (Bool_Glob != 1)
  424.    {
  425.        printf ( " Wrong result Bool_Glob Was %d Should be 1n", Bool_Glob);
  426.        errors = errors + 1;
  427.    }
  428.    if (Ch_1_Glob != 'A')
  429.    {
  430.        printf ( " Wrong result Ch_1_Glob Was %c Should be An", Ch_1_Glob);
  431.        errors = errors + 1;
  432.    }
  433.    if (Ch_2_Glob != 'B')
  434.    {
  435.        printf ( " Wrong result Ch_2_Glob Was %c Should be Bn", Ch_2_Glob);
  436.        errors = errors + 1;
  437.    }         
  438.    if (Arr_1_Glob[8] != 7)
  439.    {
  440.        printf ( " Wrong result Arr_1_Glob[8] Was %d Should be 7n", Arr_1_Glob[8]);
  441.        errors = errors + 1;
  442.    }
  443.    if (Arr_2_Glob[8][7] != Number_Of_Runs + 10)
  444.    {
  445.        printf ( " Wrong result Arr_2_Glob[8][7] Was %d Should be %dn", Arr_2_Glob[8][7], Number_Of_Runs + 10);
  446.        errors = errors + 1;
  447.    }
  448.    if (Ptr_Glob->Discr != 0)
  449.    {
  450.        printf ( " Wrong result Ptr_Glob->Discr Was %d Should be 0n", Ptr_Glob->Discr);
  451.        errors = errors + 1;
  452.    }
  453.    if (Ptr_Glob->variant.var_1.Enum_Comp != 2)
  454.    {
  455.        printf ( " Wrong result Ptr_Glob->variant.var_1.Enum_Comp Was %d Should be 2n", Ptr_Glob->variant.var_1.Enum_Comp);
  456.        errors = errors + 1;
  457.    }
  458.    if (Ptr_Glob->variant.var_1.Int_Comp != 17)
  459.    {
  460.        printf ( " Wrong result Ptr_Glob->variant.var_1.Int_Comp Was %d Should be 17n", Ptr_Glob->variant.var_1.Int_Comp);
  461.        errors = errors + 1;
  462.    }
  463.    if (strcmp(Ptr_Glob->variant.var_1.Str_Comp,  "DHRYSTONE PROGRAM, SOME STRING") != 0)
  464.    {
  465.        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);
  466.        errors = errors + 1;
  467.    }
  468.    if (Next_Ptr_Glob->Discr != 0)
  469.    {
  470.        printf ( " Wrong result Next_Ptr_Glob->Discr Was %d Should be 0n", Next_Ptr_Glob->Discr);
  471.        errors = errors + 1;
  472.    }
  473.    if (Next_Ptr_Glob->variant.var_1.Enum_Comp != 1)
  474.    {
  475.        printf ( " Wrong result Next_Ptr_Glob->variant.var_1.Enum_Comp Was %d Should be 1n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
  476.        errors = errors + 1;
  477.    }
  478.    if (Next_Ptr_Glob->variant.var_1.Int_Comp != 18)
  479.    {
  480.        printf ( " Wrong result Next_Ptr_Glob->variant.var_1.Int_Comp Was %d Should be 18n", Next_Ptr_Glob->variant.var_1.Int_Comp);
  481.        errors = errors + 1;
  482.    }
  483.    if (strcmp(Next_Ptr_Glob->variant.var_1.Str_Comp,  "DHRYSTONE PROGRAM, SOME STRING") != 0)
  484.    {
  485.        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);
  486.        errors = errors + 1;
  487.    }
  488.    if (Int_1_Loc != 5)
  489.    {
  490.        printf ( " Wrong result Int_1_Loc Was %d Should be 5n", Int_1_Loc);
  491.        errors = errors + 1;
  492.    }
  493.    if (Int_2_Loc != 13)
  494.    {
  495.        printf ( " Wrong result Int_2_Loc Was %d Should be 13n", Int_2_Loc);
  496.        errors = errors + 1;
  497.    }
  498.    if (Int_3_Loc != 7)
  499.    {
  500.        printf ( " Wrong result Int_3_Loc Was %d Should be 7n", Int_3_Loc);
  501.        errors = errors + 1;
  502.    }
  503.    if (Enum_Loc != 1)
  504.    {
  505.        printf ( " Wrong result Enum_Loc Was %d Should be 1n", Enum_Loc);
  506.        errors = errors + 1;
  507.    }
  508.    if (strcmp(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING") != 0)
  509.    {
  510.        printf ( " Wrong result Str_1_Loc Was %s Should be DHRYSTONE PROGRAM, 1'ST STRINGn", Str_1_Loc);
  511.        errors = errors + 1;
  512.    }
  513.    if (strcmp(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING") != 0)
  514.    {
  515.        printf ( " Wrong result Str_2_Loc Was %s Should be DHRYSTONE PROGRAM, 2'ND STRINGn", Str_2_Loc);
  516.        errors = errors + 1;
  517.    }
  518.    if (errors == 0)
  519.    {
  520.        printf ( " Numeric results were correctnn");
  521.    }
  522.    else
  523.    {
  524.        printf ( "n");
  525.    }
  526.                  
  527.    ///fclose(Ap);
  528.    }
  529.     if (nopause)
  530.     {
  531.        printf(" Press Enternn");
  532.        int g = getchar();
  533.     }
  534. }

  535. void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
  536. /******************/

  537.      /* executed once */
  538. {
  539.    REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;  
  540.                                          /* == Ptr_Glob_Next */
  541.    /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
  542.    /* corresponds to "rename" in Ada, "with" in Pascal           */
  543.    
  544.    structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
  545.    Ptr_Val_Par->variant.var_1.Int_Comp = 5;
  546.    Next_Record->variant.var_1.Int_Comp
  547.          = Ptr_Val_Par->variant.var_1.Int_Comp;
  548.    Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
  549.    Proc_3 (&Next_Record->Ptr_Comp);
  550.      /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
  551.                          == Ptr_Glob->Ptr_Comp */
  552.    if (Next_Record->Discr == Ident_1)
  553.      /* then, executed */
  554.    {
  555.      Next_Record->variant.var_1.Int_Comp = 6;
  556.      Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
  557.             &Next_Record->variant.var_1.Enum_Comp);
  558.      Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
  559.      Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
  560.             &Next_Record->variant.var_1.Int_Comp);
  561.    }
  562.    else /* not executed */
  563.      structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
  564. } /* Proc_1 */


  565. void Proc_2 (One_Fifty *Int_Par_Ref)
  566. /******************/
  567.      /* executed once */
  568.      /* *Int_Par_Ref == 1, becomes 4 */

  569. {
  570.    One_Fifty  Int_Loc;
  571.    Enumeration   Enum_Loc;

  572.    Int_Loc = *Int_Par_Ref + 10;
  573.    do /* executed once */
  574.      if (Ch_1_Glob == 'A')
  575.        /* then, executed */
  576.      {
  577.        Int_Loc -= 1;
  578.        *Int_Par_Ref = Int_Loc - Int_Glob;
  579.        Enum_Loc = Ident_1;
  580.      } /* if */
  581.    while (Enum_Loc != Ident_1); /* true */
  582. } /* Proc_2 */


  583. void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
  584. /******************/
  585.      /* executed once */
  586.      /* Ptr_Ref_Par becomes Ptr_Glob */

  587. {
  588.    if (Ptr_Glob != Null)
  589.      /* then, executed */
  590.      *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
  591.    Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
  592. } /* Proc_3 */


  593. void Proc_4 () /* without parameters */
  594. /*******/
  595.      /* executed once */
  596. {
  597.    Boolean Bool_Loc;

  598.    Bool_Loc = Ch_1_Glob == 'A';
  599.    Bool_Glob = Bool_Loc | Bool_Glob;
  600.    Ch_2_Glob = 'B';
  601. } /* Proc_4 */


  602. void Proc_5 () /* without parameters */
  603. /*******/
  604.      /* executed once */
  605. {
  606.    Ch_1_Glob = 'A';
  607.    Bool_Glob = false;
  608. } /* Proc_5 */


  609.          /* Procedure for the assignment of structures,          */
  610.          /* if the C compiler doesn't support this feature       */
  611. #ifdef  NOSTRUCTASSIGN
  612. memcpy (d, s, l)
  613. register char   *d;
  614. register char   *s;
  615. register int    l;
  616. {
  617.          while (l--) *d++ = *s++;
  618. }
  619. #endif



dhry_2.c
  1. /*
  2.   *************************************************************************
  3.   *
  4.   *                   "DHRYSTONE" Benchmark Program
  5.   *                   -----------------------------
  6.   *
  7.   *  Version:    C, Version 2.1
  8.   *
  9.   *  File:       dhry_2.c (part 3 of 3)
  10.   *
  11.   *  Date:       May 25, 1988
  12.   *
  13.   *  Author:     Reinhold P. Weicker
  14.   *
  15.   *************************************************************************
  16.   */

  17. #include "dhry.h"

  18. #ifndef REG
  19. #define REG
  20.          /* REG becomes defined as empty */
  21.          /* i.e. no register variables   */
  22. #else
  23. #define REG register
  24. #endif

  25. extern  int     Int_Glob;
  26. extern  char    Ch_1_Glob;

  27. Boolean Func_3 (Enumeration Enum_Par_Val);

  28. void Proc_6 (Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par)
  29. /*********************************/
  30.      /* executed once */
  31.      /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */

  32. {
  33.    *Enum_Ref_Par = Enum_Val_Par;
  34.    if (! Func_3 (Enum_Val_Par))
  35.      /* then, not executed */
  36.      *Enum_Ref_Par = Ident_4;
  37.    switch (Enum_Val_Par)
  38.    {
  39.      case Ident_1:
  40.        *Enum_Ref_Par = Ident_1;
  41.        break;
  42.      case Ident_2:
  43.        if (Int_Glob > 100)
  44.          /* then */
  45.        *Enum_Ref_Par = Ident_1;
  46.        else *Enum_Ref_Par = Ident_4;
  47.        break;
  48.      case Ident_3: /* executed */
  49.        *Enum_Ref_Par = Ident_2;
  50.        break;
  51.      case Ident_4: break;
  52.      case Ident_5:
  53.        *Enum_Ref_Par = Ident_3;
  54.        break;
  55.    } /* switch */
  56. } /* Proc_6 */


  57. void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val,
  58.                                               One_Fifty *Int_Par_Ref)
  59. /**********************************************/
  60.      /* executed three times                                      */
  61.      /* first call:      Int_1_Par_Val == 2, Int_2_Par_Val == 3,  */
  62.      /*                  Int_Par_Ref becomes 7                    */
  63.      /* second call:     Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
  64.      /*                  Int_Par_Ref becomes 17                   */
  65.      /* third call:      Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
  66.      /*                  Int_Par_Ref becomes 18                   */

  67. {
  68.    One_Fifty Int_Loc;

  69.    Int_Loc = Int_1_Par_Val + 2;
  70.    *Int_Par_Ref = Int_2_Par_Val + Int_Loc;
  71. } /* Proc_7 */


  72. void Proc_8 (Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref,
  73.                                   int Int_1_Par_Val, int Int_2_Par_Val)
  74. /*********************************************************************/
  75.      /* executed once      */
  76.      /* Int_Par_Val_1 == 3 */
  77.      /* Int_Par_Val_2 == 7 */

  78. {
  79.    REG One_Fifty Int_Index;
  80.    REG One_Fifty Int_Loc;

  81.    Int_Loc = Int_1_Par_Val + 5;
  82.    Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
  83.    Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
  84.    Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
  85.    for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
  86.      Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
  87.    Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
  88.    Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
  89.    Int_Glob = 5;
  90. } /* Proc_8 */


  91. Enumeration Func_1 (Capital_Letter Ch_1_Par_Val,
  92.                                            Capital_Letter Ch_2_Par_Val)
  93. /*************************************************/
  94.      /* executed three times                                         */
  95.      /* first call:      Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R'    */
  96.      /* second call:     Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C'    */
  97.      /* third call:      Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C'    */

  98. {
  99.    Capital_Letter        Ch_1_Loc;
  100.    Capital_Letter        Ch_2_Loc;

  101.    Ch_1_Loc = Ch_1_Par_Val;
  102.    Ch_2_Loc = Ch_1_Loc;
  103.    if (Ch_2_Loc != Ch_2_Par_Val)
  104.      /* then, executed */
  105.      return (Ident_1);
  106.    else  /* not executed */
  107.    {
  108.      Ch_1_Glob = Ch_1_Loc;
  109.      return (Ident_2);
  110.     }
  111. } /* Func_1 */


  112. Boolean Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref)
  113. /*************************************************/
  114.      /* executed once */
  115.      /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
  116.      /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */

  117. {
  118.    REG One_Thirty        Int_Loc;
  119.        Capital_Letter    Ch_Loc;

  120.    Int_Loc = 2;
  121.    while (Int_Loc <= 2) /* loop body executed once */
  122.      if (Func_1 (Str_1_Par_Ref[Int_Loc],
  123.                  Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
  124.        /* then, executed */
  125.      {
  126.        Ch_Loc = 'A';
  127.        Int_Loc += 1;
  128.      } /* if, while */
  129.    if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
  130.      /* then, not executed */
  131.      Int_Loc = 7;
  132.    if (Ch_Loc == 'R')
  133.      /* then, not executed */
  134.      return (true);
  135.    else /* executed */
  136.    {
  137.      if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
  138.        /* then, not executed */
  139.      {
  140.        Int_Loc += 7;
  141.        Int_Glob = Int_Loc;
  142.        return (true);
  143.      }
  144.      else /* executed */
  145.        return (false);
  146.    } /* if Ch_Loc */
  147. } /* Func_2 */


  148. Boolean Func_3 (Enumeration Enum_Par_Val)
  149. /***************************/
  150.      /* executed once        */
  151.      /* Enum_Par_Val == Ident_3 */
  152.      
  153. {
  154.    Enumeration Enum_Loc;

  155.    Enum_Loc = Enum_Par_Val;
  156.    if (Enum_Loc == Ident_3)
  157.      /* then, executed */
  158.      return (true);
  159.    else /* not executed */
  160.      return (false);
  161. } /* Func_3 */
dhry.h
  1. /*
  2. **************************************************************************
  3. *                       DHRYSTONE 2.1 BENCHMARK PC VERSION
  4. **************************************************************************
  5. *
  6. *                   "DHRYSTONE" Benchmark Program
  7. *                   -----------------------------
  8. *                                                                           
  9. *  Version:    C, Version 2.1
  10. *                                                                           
  11. *  File:       dhry.h (part 1 of 3)
  12. *
  13. *  Date:       May 25, 1988
  14. *
  15. *  Author:     Reinhold P. Weicker
  16. *                      Siemens AG, AUT E 51
  17. *                      Postfach 3220
  18. *                      8520 Erlangen
  19. *                      Germany (West)
  20. *                              Phone:  [+49]-9131-7-20330
  21. *                                      (8-17 Central European Time)
  22. *                              Usenet: ..!mcsun!unido!estevax!weicker
  23. *
  24. *            Original Version (in Ada) published in
  25. *            "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
  26. *            pp. 1013 - 1030, together with the statistics
  27. *            on which the distribution of statements etc. is based.
  28. *
  29. *            In this C version, the following C library functions are used:
  30. *            - strcpy, strcmp (inside the measurement loop)
  31. *            - printf, scanf (outside the measurement loop)
  32. *            In addition, Berkeley UNIX system calls "times ()" or "time ()"
  33. *            are used for execution time measurement. For measurements
  34. *            on other systems, these calls have to be changed.
  35. *
  36. *  Collection of Results:
  37. *              Reinhold Weicker (address see above) and
  38. *              
  39. *              Rick Richardson
  40. *              PC Research. Inc.
  41. *              94 Apple Orchard Drive
  42. *              Tinton Falls, NJ 07724
  43. *                      Phone:  (201) 389-8963 (9-17 EST)               
  44. *                      Usenet: ...!uunet!pcrat!rick
  45. *
  46. *      Please send results to Rick Richardson and/or Reinhold Weicker.
  47. *      Complete information should be given on hardware and software used.
  48. *      Hardware information includes: Machine type, CPU, type and size
  49. *      of caches; for microprocessors: clock frequency, memory speed
  50. *      (number of wait states).
  51. *      Software information includes: Compiler (and runtime library)
  52. *      manufacturer and version, compilation switches, OS version.
  53. *      The Operating System version may give an indication about the
  54. *      compiler; Dhrystone itself performs no OS calls in the measurement
  55. *      loop.
  56. *
  57. *      The complete output generated by the program should be mailed
  58. *      such that at least some checks for correctness can be made.
  59. *
  60. **************************************************************************
  61. *
  62. *  This version has changes made by Roy Longbottom to conform to a common
  63. *  format for a series of standard benchmarks for PCs:
  64. *
  65. *  Running time greater than 5 seconds due to inaccuracy of the PC clock.
  66. *
  67. *  Automatic adjustment of run time, no manually inserted parameters.
  68. *
  69. *  Initial display of calibration times to confirm linearity.
  70. *
  71. *  Display of results within one screen (or at a slow speed as the test
  72. *  progresses) so that it can be seen to have run successfully.
  73. *
  74. *  Facilities to type in details of system used etc.
  75. *
  76. *  All results and details appended to a results file.
  77. *
  78. *
  79. *  Roy Longbottom
  80. *  101323.2241@compuserve.com
  81. *
  82. **************************************************************************
  83. *
  84. *  For details of history, changes, other defines, benchmark construction
  85. *  statistics see official versions from ftp.nosc.mil/pub/aburto where
  86. *  the latest table of results (dhry.tbl) are available. See also
  87. *  netlib@ornl.gov
  88. *
  89. **************************************************************************
  90. *
  91. * Defines:     The following "Defines" are possible:
  92. *              -DREG=register          (default: Not defined)
  93. *                      As an approximation to what an average C programmer
  94. *                      might do, the "register" storage class is applied
  95. *                      (if enabled by -DREG=register)
  96. *                      - for local variables, if they are used (dynamically)
  97. *                        five or more times
  98. *                      - for parameters if they are used (dynamically)
  99. *                        six or more times
  100. *                      Note that an optimal "register" strategy is
  101. *                      compiler-dependent, and that "register" declarations
  102. *                      do not necessarily lead to faster execution.
  103. *              -DNOSTRUCTASSIGN        (default: Not defined)
  104. *                      Define if the C compiler does not support
  105. *                      assignment of structures.
  106. *              -DNOENUMS               (default: Not defined)
  107. *                      Define if the C compiler does not support
  108. *                      enumeration types.
  109. ***************************************************************************
  110. *
  111. *  Compilation model and measurement (IMPORTANT):
  112. *
  113. *  This C version of Dhrystone consists of three files:
  114. *  - dhry.h (this file, containing global definitions and comments)
  115. *  - dhry_1.c (containing the code corresponding to Ada package Pack_1)
  116. *  - dhry_2.c (containing the code corresponding to Ada package Pack_2)
  117. *
  118. *  The following "ground rules" apply for measurements:
  119. *  - Separate compilation
  120. *  - No procedure merging
  121. *  - Otherwise, compiler optimizations are allowed but should be indicated
  122. *  - Default results are those without register declarations
  123. *  See the companion paper "Rationale for Dhrystone Version 2" for a more
  124. *  detailed discussion of these ground rules.
  125. *
  126. *  For 16-Bit processors (e.g. 80186, 80286), times for all compilation
  127. *  models ("small", "medium", "large" etc.) should be given if possible,
  128. *  together with a definition of these models for the compiler system used.
  129. *
  130. **************************************************************************
  131. *                Examples of Pentium Results
  132. *
  133. * Dhrystone Benchmark  Version 2.1 (Language: C)
  134. *
  135. * Month run            4/1996
  136. * PC model             Escom
  137. * CPU                  Pentium
  138. * Clock MHz            100
  139. * Cache                256K
  140. * Options              Neptune chipset
  141. * OS/DOS               Windows 95
  142. * Compiler             Watcom C/ C++ 10.5 Win386
  143. * OptLevel             -otexan -zp8 -fp5 -5r
  144. * Run by               Roy Longbottom
  145. * From                 UK
  146. * Mail                 101323.2241@compuserve.com
  147. *
  148. * Final values         (* implementation-dependent):
  149. *
  150. * Int_Glob:      O.K.  5
  151. * Bool_Glob:     O.K.  1
  152. * Ch_1_Glob:     O.K.  A
  153. * Ch_2_Glob:     O.K.  B
  154. * Arr_1_Glob[8]: O.K.  7
  155. * Arr_2_Glob8/7: O.K.     1600010
  156. * Ptr_Glob->  
  157. *   Ptr_Comp:       *  98008
  158. *   Discr:       O.K.  0
  159. *   Enum_Comp:   O.K.  2
  160. *   Int_Comp:    O.K.  17
  161. *   Str_Comp:    O.K.  DHRYSTONE PROGRAM, SOME STRING
  162. * Next_Ptr_Glob->
  163. *   Ptr_Comp:       *  98008 same as above
  164. *   Discr:       O.K.  0
  165. *   Enum_Comp:   O.K.  1
  166. *   Int_Comp:    O.K.  18
  167. *   Str_Comp:    O.K.  DHRYSTONE PROGRAM, SOME STRING
  168. * Int_1_Loc:     O.K.  5
  169. * Int_2_Loc:     O.K.  13
  170. * Int_3_Loc:     O.K.  7
  171. * Enum_Loc:      O.K.  1
  172. * Str_1_Loc:     O.K.  DHRYSTONE PROGRAM, 1'ST STRING
  173. * Str_2_Loc:     O.K.  DHRYSTONE PROGRAM, 2'ND STRING
  174. *
  175. * Register option      Selected.
  176. *
  177. * Microseconds 1 loop:          4.53
  178. * Dhrystones / second:      220690
  179. * VAX MIPS rating:            125.61
  180. *
  181. *
  182. * Dhrystone Benchmark  Version 2.1 (Language: C)
  183. *
  184. * Month run            4/1996
  185. * PC model             Escom
  186. * CPU                  Pentium
  187. * Clock MHz            100
  188. * Cache                256K
  189. * Options              Neptune chipset
  190. * OS/DOS               Windows 95
  191. * Compiler             Watcom C/ C++ 10.5 Win386
  192. * OptLevel                 No optimisation
  193. * Run by               Roy Longbottom
  194. * From                 UK
  195. * Mail                 101323.2241@compuserve.com
  196. *
  197. * Final values         (* implementation-dependent):
  198. *
  199. * Int_Glob:      O.K.  5
  200. * Bool_Glob:     O.K.  1
  201. * Ch_1_Glob:     O.K.  A
  202. * Ch_2_Glob:     O.K.  B
  203. * Arr_1_Glob[8]: O.K.  7
  204. * Arr_2_Glob8/7: O.K.      320010
  205. * Ptr_Glob->  
  206. *   Ptr_Comp:       *  98004
  207. *   Discr:       O.K.  0
  208. *   Enum_Comp:   O.K.  2
  209. *   Int_Comp:    O.K.  17
  210. *   Str_Comp:    O.K.  DHRYSTONE PROGRAM, SOME STRING
  211. * Next_Ptr_Glob->
  212. *   Ptr_Comp:       *  98004 same as above
  213. *   Discr:       O.K.  0
  214. *   Enum_Comp:   O.K.  1
  215. *   Int_Comp:    O.K.  18
  216. *   Str_Comp:    O.K.  DHRYSTONE PROGRAM, SOME STRING
  217. * Int_1_Loc:     O.K.  5
  218. * Int_2_Loc:     O.K.  13
  219. * Int_3_Loc:     O.K.  7
  220. * Enum_Loc:      O.K.  1
  221. * Str_1_Loc:     O.K.  DHRYSTONE PROGRAM, 1'ST STRING
  222. * Str_2_Loc:     O.K.  DHRYSTONE PROGRAM, 2'ND STRING
  223. *
  224. * Register option      Not selected.
  225. *
  226. * Microseconds 1 loop:         20.06
  227. * Dhrystones / second:       49844
  228. * VAX MIPS rating:             28.37
  229. *
  230. **************************************************************************
  231. */

  232. /* Compiler and system dependent definitions: */

  233. #ifndef TIME
  234. #define TIMES
  235. #endif
  236.                 /* Use times(2) time function unless    */
  237.                 /* explicitly defined otherwise         */

  238. #ifdef TIMES
  239. /* #include
  240.    #include */
  241.                 /* for "times" */
  242. #endif

  243. #define Mic_secs_Per_Second     1000000.0
  244.                 /* Berkeley UNIX C returns process times in seconds/HZ */

  245. #ifdef  NOSTRUCTASSIGN
  246. #define structassign(d, s)      memcpy(&(d), &(s), sizeof(d))
  247. #else
  248. #define structassign(d, s)      d = s
  249. #endif

  250. #ifdef  NOENUM
  251. #define Ident_1 0
  252. #define Ident_2 1
  253. #define Ident_3 2
  254. #define Ident_4 3
  255. #define Ident_5 4
  256.   typedef int   Enumeration;
  257. #else
  258.   typedef       enum    {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
  259.                 Enumeration;
  260. #endif
  261.         /* for boolean and enumeration types in Ada, Pascal */

  262. /* General definitions: */

  263. #include
  264. #include

  265.                 /* for strcpy, strcmp */

  266. #define Null 0
  267.                 /* Value of a Null pointer */
  268. #define true  1
  269. #define false 0

  270. typedef int     One_Thirty;
  271. typedef int     One_Fifty;
  272. typedef char    Capital_Letter;
  273. typedef int     Boolean;
  274. typedef char    Str_30 [31];
  275. typedef int     Arr_1_Dim [50];
  276. typedef int     Arr_2_Dim [50] [50];

  277. typedef struct record
  278.     {
  279.     struct record *Ptr_Comp;
  280.     Enumeration    Discr;
  281.     union {
  282.           struct {
  283.                   Enumeration Enum_Comp;
  284.                   int         Int_Comp;
  285.                   char        Str_Comp [31];
  286.                   } var_1;
  287.           struct {
  288.                   Enumeration E_Comp_2;
  289.                   char        Str_2_Comp [31];
  290.                   } var_2;
  291.           struct {
  292.                   char        Ch_1_Comp;
  293.                   char        Ch_2_Comp;
  294.                   } var_3;
  295.           } variant;
  296.       } Rec_Type, *Rec_Pointer;







回帖(1)

h1654155285.8644

2022-7-6 15:57:25
很不错的处理器,写的也很详细,如果简洁点就更好了。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分