home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / misc / a-d / dhrystone / source / dhrystone21.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-11  |  7.1 KB  |  377 lines

  1.  
  2. /* Accuracy of timings and human fatigue controlled by next two lines */
  3. /*#define LOOPS    50000        /* Use this for slow or 16 bit machines */
  4. #define LOOPS    20000        /* Use this for faster machines */
  5.  
  6. /*#define LOOPS 5000000           /* Use THIS with a 68040 ! */
  7.  
  8.  
  9. /* Compiler dependent options */
  10. #undef    NOENUM            /* Define if compiler has no enum's */
  11. #undef    NOSTRUCTASSIGN        /* Define if compiler can't assign structures */
  12.  
  13. /* define only one of the next two defines */
  14.  
  15. #define TIME            /* Use time(2) time function */
  16.  
  17.  
  18. /* define the granularity of your times(2) function (when used) */
  19. #define HZ    1000        /* times(2) returns 1/60 second (most) */
  20. /* #define HZ    100        /* times(2) returns 1/100 second (WECo) */
  21.  
  22. char    Ver[] = "$VER: Dhrystone 2.1 68000+ (5.7.95)";
  23.  
  24. #ifdef    NOSTRUCTASSIGN
  25. #define    structassign(d, s)    memcpy(&(d), &(s), sizeof(d))
  26. #else
  27. #define    structassign(d, s)    d = s
  28. #endif
  29.  
  30. #ifdef    NOENUM
  31. #define    Ident1    1
  32. #define    Ident2    2
  33. #define    Ident3    3
  34. #define    Ident4    4
  35. #define    Ident5    5
  36. typedef int    Enumeration;
  37. #else
  38. typedef enum    {Ident1, Ident2, Ident3, Ident4, Ident5} Enumeration;
  39. #endif
  40.  
  41. typedef int    OneToThirty;
  42. typedef int    OneToFifty;
  43. typedef char    CapitalLetter;
  44. typedef char    String30[31];
  45. typedef int    Array1Dim[51];
  46. typedef int    Array2Dim[51][51];
  47.  
  48. struct    Record
  49. {
  50.     struct Record        *PtrComp;
  51.     Enumeration        Discr;
  52.     Enumeration        EnumComp;
  53.     OneToFifty        intComp;
  54.     String30        StringComp;
  55. };
  56.  
  57. typedef struct Record     RecordType;
  58. typedef RecordType *    RecordPtr;
  59. typedef int        boolean;
  60.  
  61. #define    NULL        0
  62. #define    TRUE        1
  63. #define    FALSE        0
  64.  
  65. #ifndef REG
  66. #define    REG
  67. #endif
  68.  
  69. extern Enumeration    Func1();
  70. extern boolean        Func2();
  71.  
  72.  
  73. #include <stdio.h>
  74. #include <stdlib.h>
  75. #include <string.h>
  76. /* #include <sys/types.h> */
  77. #include <time.h>
  78.  
  79.  
  80. /*
  81.  * Package 1
  82.  */
  83. int        intGlob;
  84. boolean        BoolGlob;
  85. char        Char1Glob;
  86. char        Char2Glob;
  87. Array1Dim    Array1Glob;
  88. Array2Dim    Array2Glob;
  89. RecordPtr    PtrGlb;
  90. RecordPtr    PtrGlbNext;
  91.  
  92.  
  93. Proc0(void)
  94. {
  95.      unsigned long time1,time2,time3;
  96.     OneToFifty        intLoc1;
  97.     REG OneToFifty        intLoc2;
  98.     OneToFifty        intLoc3;
  99.     REG char        CharLoc;
  100.     REG char        CharIndex;
  101.     Enumeration         EnumLoc;
  102.     String30        String1Loc;
  103.     String30        String2Loc;
  104.     REG int            i;
  105.  
  106.     PtrGlbNext = (RecordPtr) malloc(sizeof(RecordType));
  107.     PtrGlb = (RecordPtr) malloc(sizeof(RecordType));
  108.     PtrGlb->PtrComp = PtrGlbNext;
  109.     PtrGlb->Discr = Ident1;
  110.     PtrGlb->EnumComp = Ident3;
  111.     PtrGlb->intComp = 40;
  112.     strcpy(PtrGlb->StringComp, "DHRYSTONE PROGRAM, SOME STRING");
  113.     strcpy(String1Loc, "DHRYSTONE PROGRAM, 1'ST STRING");    /*GOOF*/
  114.  
  115.     Array2Glob[8][7] = 10;    /* Was missing in published program */
  116.  
  117. /*****************
  118. -- Start Timer --
  119. *****************/
  120.  
  121. //Forbid();
  122. time1=GetSysTime();
  123.  
  124.     for (i = 0; i < LOOPS; ++i)
  125.     {
  126.  
  127.         Proc5();
  128.         Proc4();
  129.         
  130.         intLoc1 = 2;
  131.         intLoc2 = 3;
  132.         strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  133.         EnumLoc = Ident2;
  134.         BoolGlob = ! Func2(String1Loc, String2Loc);
  135.         while (intLoc1 < intLoc2)
  136.         {
  137.             intLoc3 = 5 * intLoc1 - intLoc2;
  138.             Proc7(intLoc1, intLoc2, &intLoc3);
  139.             intLoc1 += 1;
  140.         }
  141.         Proc8(Array1Glob, Array2Glob, intLoc1, intLoc3);
  142.         Proc1(PtrGlb);
  143.         for (CharIndex = 'A'; CharIndex <= Char2Glob; ++CharIndex)
  144.         {
  145.             if (EnumLoc == Func1(CharIndex, 'C'))
  146.             {
  147.                 Proc6(Ident1, &EnumLoc);
  148.                 strcpy(String1Loc, "DHRYSTONE PROGRAM, 3'ST STRING");
  149.                 intLoc2 = i;
  150.                 intGlob = i;
  151.             }
  152.         }
  153.         intLoc2 = intLoc2 * intLoc1;
  154.         intLoc1 = intLoc2 / intLoc3;
  155.         intLoc2 = 7 * (intLoc2 - intLoc3) - intLoc1;
  156.         Proc2(&intLoc1);
  157.     }
  158.  
  159. /*****************
  160. -- Stop Timer --
  161. *****************/
  162.  
  163. time2 = GetSysTime();
  164. time3 = time2-time1;
  165. //Permit();
  166.  
  167. printf("Dhrystone (2.1) time for %ld passes = %d.%03d seconds.\n",
  168.     (long) LOOPS,time3/1000,time3%1000);
  169. printf("This machine benchmarks at %ld dhrystones/second.\n",
  170.     (LOOPS*1000) / time3 );
  171. printf("\nBenchmark ported by Torsten Hiddessen (math@sun.rz.tu-clausthal.de)\n");
  172. }
  173.  
  174. GetSysTime(void)
  175. {
  176.  unsigned int t1[2]={0,0};
  177.  timer(t1);
  178.  
  179.  // printf("t1=%ld t2=%ld\n",t1[0],t1[1]);
  180.  
  181.  return ((unsigned long) (1000*t1[0])+(t1[1]/1000) );
  182.  
  183. }
  184.  
  185.  
  186. main()
  187. {
  188.     Proc0();
  189.     exit(0);
  190. }
  191.  
  192. Proc1(PtrParIn)
  193. REG RecordPtr    PtrParIn;
  194. {
  195. #define    NextRecord    (*(PtrParIn->PtrComp))
  196.  
  197.     structassign(NextRecord, *PtrGlb);
  198.     PtrParIn->intComp = 5;
  199.     NextRecord.intComp = PtrParIn->intComp;
  200.     NextRecord.PtrComp = PtrParIn->PtrComp;
  201.     Proc3(NextRecord.PtrComp);
  202.     if (NextRecord.Discr == Ident1)
  203.     {
  204.         NextRecord.intComp = 6;
  205.         Proc6(PtrParIn->EnumComp, &NextRecord.EnumComp);
  206.         NextRecord.PtrComp = PtrGlb->PtrComp;
  207.         Proc7(NextRecord.intComp, 10, &NextRecord.intComp);
  208.     }
  209.     else
  210.         structassign(*PtrParIn, NextRecord);
  211.  
  212. #undef    NextRecord
  213. }
  214.  
  215. Proc2(intParIO)
  216. OneToFifty    *intParIO;
  217. {
  218.     REG OneToFifty        intLoc;
  219.     REG Enumeration        EnumLoc;
  220.  
  221.     intLoc = *intParIO + 10;
  222.     for(;;)
  223.     {
  224.         if (Char1Glob == 'A')
  225.         {
  226.             --intLoc;
  227.             *intParIO = intLoc - intGlob;
  228.             EnumLoc = Ident1;
  229.         }
  230.         if (EnumLoc == Ident1)
  231.             break;
  232.     }
  233. }
  234.  
  235. Proc3(PtrParOut)
  236. RecordPtr    *PtrParOut;
  237. {
  238.     if (PtrGlb != NULL)
  239.         *PtrParOut = PtrGlb->PtrComp;
  240.     else
  241.         intGlob = 100;
  242.     Proc7(10, intGlob, &PtrGlb->intComp);
  243. }
  244.  
  245. Proc4()
  246. {
  247.     REG boolean    BoolLoc;
  248.  
  249.     BoolLoc = Char1Glob == 'A';
  250.     BoolLoc |= BoolGlob;
  251.     Char2Glob = 'B';
  252. }
  253.  
  254. Proc5()
  255. {
  256.     Char1Glob = 'A';
  257.     BoolGlob = FALSE;
  258. }
  259.  
  260. extern boolean Func3();
  261.  
  262. Proc6(EnumParIn, EnumParOut)
  263. REG Enumeration    EnumParIn;
  264. REG Enumeration    *EnumParOut;
  265. {
  266.     *EnumParOut = EnumParIn;
  267.     if (! Func3(EnumParIn) )
  268.         *EnumParOut = Ident4;
  269.     switch (EnumParIn)
  270.     {
  271.     case Ident1:    *EnumParOut = Ident1; break;
  272.     case Ident2:    if (intGlob > 100) *EnumParOut = Ident1;
  273.             else *EnumParOut = Ident4;
  274.             break;
  275.     case Ident3:    *EnumParOut = Ident2; break;
  276.     case Ident4:    break;
  277.     case Ident5:    *EnumParOut = Ident3;
  278.     }
  279. }
  280.  
  281. Proc7(intParI1, intParI2, intParOut)
  282. OneToFifty    intParI1;
  283. OneToFifty    intParI2;
  284. OneToFifty    *intParOut;
  285. {
  286.     REG OneToFifty    intLoc;
  287.  
  288.     intLoc = intParI1 + 2;
  289.     *intParOut = intParI2 + intLoc;
  290. }
  291.  
  292. Proc8(Array1Par, Array2Par, intParI1, intParI2)
  293. Array1Dim    Array1Par;
  294. Array2Dim    Array2Par;
  295. OneToFifty    intParI1;
  296. OneToFifty    intParI2;
  297. {
  298.     REG OneToFifty    intLoc;
  299.     REG OneToFifty    intIndex;
  300.  
  301.     intLoc = intParI1 + 5;
  302.     Array1Par[intLoc] = intParI2;
  303.     Array1Par[intLoc+1] = Array1Par[intLoc];
  304.     Array1Par[intLoc+30] = intLoc;
  305.     for (intIndex = intLoc; intIndex <= (intLoc+1); ++intIndex)
  306.         Array2Par[intLoc][intIndex] = intLoc;
  307.     ++Array2Par[intLoc][intLoc-1];
  308.     Array2Par[intLoc+20][intLoc] = Array1Par[intLoc];
  309.     intGlob = 5;
  310. }
  311.  
  312. Enumeration Func1(CharPar1, CharPar2)
  313. CapitalLetter    CharPar1;
  314. CapitalLetter    CharPar2;
  315. {
  316.     REG CapitalLetter    CharLoc1;
  317.     REG CapitalLetter    CharLoc2;
  318.  
  319.     CharLoc1 = CharPar1;
  320.     CharLoc2 = CharLoc1;
  321.     if (CharLoc2 != CharPar2)
  322.         return (Ident1);
  323.     else
  324.         return (Ident2);
  325. }
  326.  
  327. boolean Func2(StrParI1, StrParI2)
  328. String30    StrParI1;
  329. String30    StrParI2;
  330. {
  331.     REG OneToThirty        intLoc;
  332.     REG CapitalLetter    CharLoc;
  333.  
  334.     intLoc = 1;
  335.     while (intLoc <= 1)
  336.         if (Func1(StrParI1[intLoc], StrParI2[intLoc+1]) == Ident1)
  337.         {
  338.             CharLoc = 'A';
  339.             ++intLoc;
  340.         }
  341.     if (CharLoc >= 'W' && CharLoc <= 'Z')
  342.         intLoc = 7;
  343.     if (CharLoc == 'X')
  344.         return(TRUE);
  345.     else
  346.     {
  347.         if (strcmp(StrParI1, StrParI2) > 0)
  348.         {
  349.             intLoc += 7;
  350.             return (TRUE);
  351.         }
  352.         else
  353.             return (FALSE);
  354.     }
  355. }
  356.  
  357. boolean Func3(EnumParIn)
  358. REG Enumeration    EnumParIn;
  359. {
  360.     REG Enumeration    EnumLoc;
  361.  
  362.     EnumLoc = EnumParIn;
  363.     if (EnumLoc == Ident3) return (TRUE);
  364.     return (FALSE);
  365. }
  366.  
  367. #ifdef    NOSTRUCTASSIGN
  368. memcpy(d, s, l)
  369. register char    *d;
  370. register char    *s;
  371. register int    l;
  372. {
  373.     while (l--) *d++ = *s++;
  374. }
  375. #endif
  376.  
  377.