home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_40.arc / C-REVIEW.ARC / DRYSTN.C < prev    next >
Text File  |  1987-09-25  |  7KB  |  327 lines

  1. /*
  2.      Program:  Drystn (Dhrystone)
  3.      
  4.      Version:  1.00
  5.      Date:     September 25, 1987
  6.      
  7.      Language: ANSI C
  8.      
  9.     The following program contains statements of a high-level programming
  10.     language (C) in a distribution considered representative:
  11.  
  12.     assignments            53%
  13.     control statements        32%
  14.     procedure, function calls    15%
  15.  
  16.     100 statements are dynamically executed.  The program is balanced with
  17.     respect to the three aspects:
  18.         - statement type
  19.         - operand type (for simple data types)
  20.         - operand access
  21.             operand global, local, parameter, or constant.
  22.  
  23.     The combination of these three aspects is balanced only approximately.
  24.  
  25.     The program does not compute anything meaningfull, but it is
  26.     syntactically and semantically correct.
  27.  
  28. */
  29.  
  30. #include <stdio.h>
  31.  
  32. #define LOOPS    50000        /* Use this for slow or 16 bit machines */
  33.  
  34. char    Version[] = "1.00MC";
  35.  
  36. #ifdef NOSTRUCTASSIGN
  37.      #define structassign(d, s) memcpy(&(d), &(s), sizeof(d))
  38. #else
  39.      #define structassign(d, s) d = s
  40. #endif
  41.  
  42. #ifdef    NOENUM
  43.      #define   Ident1    1
  44.      #define   Ident2    2
  45.      #define   Ident3    3
  46.      #define   Ident4    4
  47.      #define   Ident5    5
  48.      typedef int    Enumeration;
  49. #else
  50.      typedef enum   {Ident1, Ident2, Ident3, Ident4, Ident5} Enumeration;
  51. #endif
  52.  
  53. typedef int    OneToThirty;
  54. typedef int    OneToFifty;
  55. typedef char   CapitalLetter;
  56. typedef char   String30[31];
  57. typedef int       Array1Dim[51];
  58. typedef int       Array2Dim[51][51];
  59.  
  60. struct    Record
  61. {
  62.      struct Record  *PtrComp;
  63.      Enumeration    Discr;
  64.      Enumeration    EnumComp;
  65.      OneToFifty     IntComp;
  66.      String30       StringComp;
  67. };
  68.  
  69. typedef struct Record    RecordType;
  70. typedef RecordType *     RecordPtr;
  71. typedef int              boolean;
  72.  
  73. #define    NULL        0
  74. #define    TRUE        1
  75. #define    FALSE        0
  76.  
  77. #ifndef REG
  78.      #define    REG
  79. #endif
  80.  
  81. extern Enumeration    Func1();
  82. extern boolean        Func2();
  83.  
  84. main()
  85. {
  86.     Proc0();
  87.     exit(0);
  88. }
  89.  
  90. /*
  91.  * Package 1
  92.  */
  93. int        IntGlob;
  94. boolean        BoolGlob;
  95. char        Char1Glob;
  96. char        Char2Glob;
  97. Array1Dim    Array1Glob;
  98. Array2Dim    Array2Glob;
  99. RecordPtr    PtrGlb;
  100. RecordPtr    PtrGlbNext;
  101.  
  102. Proc0()
  103. {
  104.     unsigned int i;
  105.     OneToFifty        IntLoc1;
  106.     REG OneToFifty    IntLoc2;
  107.     OneToFifty        IntLoc3;
  108.     REG char        CharLoc;
  109.     REG char        CharIndex;
  110.     Enumeration         EnumLoc;
  111.     String30        String1Loc;
  112.     String30        String2Loc;
  113.     extern char        *malloc();
  114.  
  115.     PtrGlbNext = (RecordPtr) malloc(sizeof(RecordType));
  116.     PtrGlb = (RecordPtr) malloc(sizeof(RecordType));
  117.     PtrGlb->PtrComp = PtrGlbNext;
  118.     PtrGlb->Discr = Ident1;
  119.     PtrGlb->EnumComp = Ident3;
  120.     PtrGlb->IntComp = 40;
  121.     strcpy(PtrGlb->StringComp, "DHRYSTONE PROGRAM, SOME STRING");
  122.     strcpy(String1Loc, "DHRYSTONE PROGRAM, 1'ST STRING");    /*GOOF*/
  123.     Array2Glob[8][7] = 10;    /* Was missing in published program */
  124.  
  125.     for (i = 0; i < LOOPS; ++i)
  126.          {
  127.         Proc5();
  128.         Proc4();
  129.         IntLoc1 = 2;
  130.         IntLoc2 = 3;
  131.         strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  132.         EnumLoc = Ident2;
  133.         BoolGlob = ! Func2(String1Loc, String2Loc);
  134.         while (IntLoc1 < IntLoc2)
  135.              {
  136.             IntLoc3 = 5 * IntLoc1 - IntLoc2;
  137.             Proc7(IntLoc1, IntLoc2, &IntLoc3);
  138.             ++IntLoc1;
  139.             }
  140.         Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3);
  141.         Proc1(PtrGlb);
  142.         for (CharIndex = 'A'; CharIndex <= Char2Glob; ++CharIndex)
  143.             if (EnumLoc == Func1(CharIndex, 'C'))
  144.                 Proc6(Ident1, &EnumLoc);
  145.         IntLoc3 = IntLoc2 * IntLoc1;
  146.         IntLoc2 = IntLoc3 / IntLoc1;
  147.         IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1;
  148.         Proc2(&IntLoc1);
  149.     }
  150.     printf("Dhrystone(%s) time for %ld passes\n",Version,(long)LOOPS);
  151. }
  152.  
  153. Proc1(PtrParIn)
  154. REG RecordPtr    PtrParIn;
  155. {
  156. #define    NextRecord    (*(PtrParIn->PtrComp))
  157.  
  158.     structassign(NextRecord, *PtrGlb);
  159.     PtrParIn->IntComp = 5;
  160.     NextRecord.IntComp = PtrParIn->IntComp;
  161.     NextRecord.PtrComp = PtrParIn->PtrComp;
  162.     Proc3(NextRecord.PtrComp);
  163.     if (NextRecord.Discr == Ident1)
  164.     {
  165.         NextRecord.IntComp = 6;
  166.         Proc6(PtrParIn->EnumComp, &NextRecord.EnumComp);
  167.         NextRecord.PtrComp = PtrGlb->PtrComp;
  168.         Proc7(NextRecord.IntComp, 10, &NextRecord.IntComp);
  169.     }
  170.     else
  171.         structassign(*PtrParIn, NextRecord);
  172.  
  173. #undef    NextRecord
  174. }
  175.  
  176. Proc2(IntParIO)
  177. OneToFifty    *IntParIO;
  178. {
  179.     REG OneToFifty        IntLoc;
  180.     REG Enumeration        EnumLoc;
  181.  
  182.     IntLoc = *IntParIO + 10;
  183.     for(;;)
  184.     {
  185.         if (Char1Glob == 'A')
  186.         {
  187.             --IntLoc;
  188.             *IntParIO = IntLoc - IntGlob;
  189.             EnumLoc = Ident1;
  190.         }
  191.         if (EnumLoc == Ident1)
  192.             break;
  193.     }
  194. }
  195.  
  196. Proc3(PtrParOut)
  197. RecordPtr    *PtrParOut;
  198. {
  199.     if (PtrGlb != NULL)
  200.         *PtrParOut = PtrGlb->PtrComp;
  201.     else
  202.         IntGlob = 100;
  203.     Proc7(10, IntGlob, &PtrGlb->IntComp);
  204. }
  205.  
  206. Proc4()
  207. {
  208.     REG boolean    BoolLoc;
  209.  
  210.     BoolLoc = Char1Glob == 'A';
  211.     BoolLoc |= BoolGlob;
  212.     Char2Glob = 'B';
  213. }
  214.  
  215. Proc5()
  216. {
  217.     Char1Glob = 'A';
  218.     BoolGlob = FALSE;
  219. }
  220.  
  221. extern boolean Func3();
  222.  
  223. Proc6(EnumParIn, EnumParOut)
  224. REG Enumeration    EnumParIn;
  225. REG Enumeration    *EnumParOut;
  226. {
  227.     *EnumParOut = EnumParIn;
  228.     if (! Func3(EnumParIn) )
  229.         *EnumParOut = Ident4;
  230.     switch (EnumParIn)
  231.     {
  232.     case Ident1:    *EnumParOut = Ident1; break;
  233.     case Ident2:    if (IntGlob > 100) *EnumParOut = Ident1;
  234.             else *EnumParOut = Ident4;
  235.             break;
  236.     case Ident3:    *EnumParOut = Ident2; break;
  237.     case Ident4:    break;
  238.     case Ident5:    *EnumParOut = Ident3;
  239.     }
  240. }
  241.  
  242. Proc7(IntParI1, IntParI2, IntParOut)
  243. OneToFifty    IntParI1;
  244. OneToFifty    IntParI2;
  245. OneToFifty    *IntParOut;
  246. {
  247.     REG OneToFifty    IntLoc;
  248.  
  249.     IntLoc = IntParI1 + 2;
  250.     *IntParOut = IntParI2 + IntLoc;
  251. }
  252.  
  253. Proc8(Array1Par, Array2Par, IntParI1, IntParI2)
  254. Array1Dim    Array1Par;
  255. Array2Dim    Array2Par;
  256. OneToFifty    IntParI1;
  257. OneToFifty    IntParI2;
  258. {
  259.     REG OneToFifty    IntLoc;
  260.     REG OneToFifty    IntIndex;
  261.  
  262.     IntLoc = IntParI1 + 5;
  263.     Array1Par[IntLoc] = IntParI2;
  264.     Array1Par[IntLoc+1] = Array1Par[IntLoc];
  265.     Array1Par[IntLoc+30] = IntLoc;
  266.     for (IntIndex = IntLoc; IntIndex <= (IntLoc+1); ++IntIndex)
  267.         Array2Par[IntLoc][IntIndex] = IntLoc;
  268.     ++Array2Par[IntLoc][IntLoc-1];
  269.     Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc];
  270.     IntGlob = 5;
  271. }
  272.  
  273. Enumeration Func1(CharPar1, CharPar2)
  274. CapitalLetter    CharPar1;
  275. CapitalLetter    CharPar2;
  276. {
  277.     REG CapitalLetter    CharLoc1;
  278.     REG CapitalLetter    CharLoc2;
  279.  
  280.     CharLoc1 = CharPar1;
  281.     CharLoc2 = CharLoc1;
  282.     if (CharLoc2 != CharPar2)
  283.         return (Ident1);
  284.     else
  285.         return (Ident2);
  286. }
  287.  
  288. boolean Func2(StrParI1, StrParI2)
  289. String30    StrParI1;
  290. 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(EnumParIn)
  319. REG Enumeration    EnumParIn;
  320. {
  321.     REG Enumeration    EnumLoc;
  322.  
  323.     EnumLoc = EnumParIn;
  324.     if (EnumLoc == Ident3) return (TRUE);
  325.     return (FALSE);
  326. }
  327.