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