home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / BK-SC1_3.DMS / in.adf / Fastlib.Lha / Examples / Dhrystone / dhrystone.c < prev   
Encoding:
C/C++ Source or Header  |  1996-01-19  |  6.4 KB  |  326 lines

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