home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / blx21.zip / BC31.ARJ / DRYSTN.CPP < prev    next >
C/C++ Source or Header  |  1992-02-20  |  9KB  |  387 lines

  1. /*
  2.      Program:  Drystn (Dhrystone)
  3.      
  4.      Version:  0.1b
  5.      Date:     February 19, 1992
  6.      
  7.      Language: 2.1 C++
  8.      
  9.    The program is based on the drystone benchmark program published
  10.    originally by MICRO CORNICOPIA magazine.  As far as possible, the
  11.    program contains the same distribution of assignments, control statements
  12.    and procedure or function calls as the original C program, except that
  13.    some of the procedures and functions were declared 'inline'.  Inlining can
  14.    be turned off by defining NOINLINE on the command line.
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <process.h>
  20. #include <stdlib.h>
  21.  
  22. const unsigned LOOPS = 50000;
  23.  
  24. char Version[] = "0.01PR";
  25.  
  26. #define structassign(d, s)   (d) = (s)
  27.  
  28.  
  29. typedef int    OneToThirty;
  30. typedef int    OneToFifty;
  31. typedef char   CapitalLetter;
  32. typedef char   String30[31];
  33. typedef int       Array1Dim[51];
  34. typedef int       Array2Dim[51][51];
  35.  
  36. #undef NULL
  37. #define    NULL        0
  38. #define    TRUE        1
  39. #define    FALSE        0
  40.  
  41. #ifndef REG
  42.      #define    REG
  43. #endif
  44.  
  45. #ifdef NOINLINE
  46.    #define INLINE 
  47. #else
  48.    #define INLINE inline
  49. #endif
  50.  
  51. enum  Enumeration  {Ident1, Ident2, Ident3, Ident4, Ident5};
  52.  
  53. typedef int              boolean;
  54.  
  55. class RecordType;
  56. typedef RecordType *     RecordPtr;
  57.  
  58. class    RecordType
  59. {
  60.    private:
  61.       RecordPtr      PtrComp;
  62.       Enumeration    Discr;
  63.       Enumeration    EnumComp;
  64.       OneToFifty     IntComp;
  65.       String30       StringComp;
  66.    public:
  67.       RecordType() {  }
  68.       RecordType(Enumeration Dis, Enumeration En, OneToFifty In) :
  69.          Discr(Dis), EnumComp(En), IntComp(In)
  70.          { }
  71.       void SetPtrComp(RecordPtr Ptr)
  72.          {
  73.          PtrComp = Ptr;
  74.          }
  75.       RecordPtr GetPtrComp()
  76.          {
  77.          return PtrComp;
  78.          }
  79.       Enumeration GetDiscr()
  80.          {
  81.          return Discr;
  82.          }
  83.       Enumeration GetEnumComp()
  84.          {
  85.          return EnumComp;
  86.          }
  87.       OneToFifty & GetIntCompRef()
  88.          {
  89.          return IntComp;
  90.          }
  91.       char * GetStringComp()
  92.          {
  93.          return StringComp;
  94.          }
  95.       INLINE void Proc1(RecordPtr Ptr);
  96.       virtual void Proc3(RecordPtr *);
  97.       virtual void Proc6(Enumeration, Enumeration&);
  98.       INLINE void Proc7(OneToFifty, OneToFifty, OneToFifty &);
  99. };
  100.  
  101. INLINE void RecordType::Proc1(RecordPtr PtrParIn)
  102. {
  103. #define    NextRecord    (*(PtrParIn->PtrComp))
  104.  
  105.     structassign(NextRecord, *this);
  106.     PtrParIn->IntComp = 5;
  107.     NextRecord.IntComp = PtrParIn->IntComp;
  108.     NextRecord.PtrComp = PtrParIn->PtrComp;
  109.     Proc3((RecordPtr *)NextRecord.PtrComp);
  110.     if (NextRecord.Discr == Ident1)
  111.     {
  112.         NextRecord.IntComp = 6;
  113.         Proc6(PtrParIn->EnumComp, NextRecord.EnumComp);
  114.         NextRecord.PtrComp = PtrComp;
  115.         Proc7(NextRecord.IntComp, 10, NextRecord.IntComp);
  116.     }
  117.     else
  118.         structassign(*PtrParIn, NextRecord);
  119. #undef    NextRecord
  120. }
  121.  
  122. // DUMMY function
  123. void RecordType::Proc3(RecordPtr *PtrParOut)
  124. {
  125.     *PtrParOut = PtrComp;
  126. }
  127.  
  128. // DUMMY function
  129. void RecordType::Proc6(Enumeration EnumParIn, Enumeration& EnumParOut)
  130. {
  131.    EnumParOut = EnumParIn;
  132. }
  133.  
  134. INLINE void RecordType::Proc7(OneToFifty IntParI1, OneToFifty IntParI2,
  135.    OneToFifty &IntParOut)
  136. {
  137.     REG OneToFifty    IntLoc;
  138.  
  139.     IntLoc = IntParI1 + 2;
  140.     IntParOut = IntParI2 + IntLoc;
  141. }
  142.  
  143. class GlobType : public RecordType
  144. {
  145.       int        IntGlob;
  146.       boolean        BoolGlob;
  147.       char        Char1Glob;
  148.       char        Char2Glob;
  149.       Array1Dim    Array1Glob;
  150.       Array2Dim    Array2Glob;
  151.       RecordPtr    PtrGlbNext;
  152.    public:
  153.       GlobType();
  154.       void Run(RecordPtr);
  155.       virtual void Proc3(RecordPtr *);
  156.       void Proc2(OneToFifty&);
  157.       INLINE void Proc4();
  158.       INLINE void Proc5();
  159.       virtual void Proc6(Enumeration, Enumeration&);
  160.       void Proc8(Array1Dim, OneToFifty, OneToFifty);
  161.       INLINE Enumeration Func1(CapitalLetter CharPar1, CapitalLetter CharPar2);
  162.       boolean Func2(String30 StrParI1, String30 StrParI2);
  163.       INLINE boolean Func3(REG Enumeration EnumParIn);
  164.       int TestResults()
  165.          {
  166.          int retval = 0;
  167.  
  168.          retval += (GetDiscr() != Ident1);
  169.          retval += (GetEnumComp() != Ident2);
  170.          retval += (GetIntCompRef() != 17);
  171.          retval += (strcmp(GetStringComp(),"DHRYSTONE PROGRAM, SOME STRING"));
  172.          retval += (IntGlob != 5);
  173.          retval += (BoolGlob != TRUE);
  174.          retval += (Char1Glob != 'A');
  175.          retval += (Char2Glob != 'B');
  176.          retval += (Array1Glob[0] != 0);
  177.          retval += (Array1Glob[50] != 0);
  178.          retval += (Array1Glob[8] != 7);
  179.          retval += (Array1Glob[9] != 7);
  180.          retval += (Array2Glob[0][0] != 0);
  181.          retval += (Array2Glob[50][50] != 0);
  182.          retval += (Array2Glob[8][7] != (int)0xC35A);
  183.          retval += (Array2Glob[8][8] != 8);
  184.          retval += (Array2Glob[28][8] != 7);
  185.  
  186.          return retval;
  187.          }
  188. };
  189.                   
  190. GlobType::GlobType() : RecordType(Ident1, Ident2, 40)
  191. {
  192.  
  193. }
  194.  
  195.  
  196. void GlobType::Proc2(OneToFifty& IntParIO)
  197. {
  198.     REG OneToFifty        IntLoc;
  199.     REG Enumeration        EnumLoc = Ident2;
  200.  
  201.     IntLoc = IntParIO + 10;
  202.     for(;;)
  203.     {
  204.         if (Char1Glob == 'A')
  205.         {
  206.             --IntLoc;
  207.             IntParIO = IntLoc - IntGlob;
  208.             EnumLoc = Ident1;
  209.         }
  210.         if (EnumLoc == Ident1)
  211.             break;
  212.     }
  213. }
  214.  
  215.  
  216. void GlobType::Proc3(RecordPtr *PtrParOut)
  217. {
  218.    if (this != NULL)  // never will equal null, but who cares
  219.        *PtrParOut = GetPtrComp();
  220.    else
  221.       IntGlob = 100;
  222.     Proc7(10, IntGlob, GetIntCompRef());
  223. }
  224.  
  225. INLINE void GlobType::Proc4()
  226. {
  227.     REG boolean    BoolLoc;
  228.  
  229.     BoolLoc = Char1Glob == 'A';
  230.     BoolLoc |= BoolGlob;
  231.     Char2Glob = 'B';
  232. }
  233.  
  234. INLINE void GlobType::Proc5()
  235. {
  236.     Char1Glob = 'A';
  237.     BoolGlob = FALSE;
  238. }
  239.  
  240. INLINE boolean GlobType::Func3(REG Enumeration EnumParIn)
  241. {
  242.     REG Enumeration    EnumLoc;
  243.  
  244.     EnumLoc = EnumParIn;
  245.     if (EnumLoc == Ident3)
  246.       return (TRUE);
  247.     return (FALSE);
  248. }
  249.  
  250. void GlobType::Proc6(Enumeration EnumParIn, Enumeration& EnumParOut)
  251. {
  252.     EnumParOut = EnumParIn;
  253.     if (!Func3(EnumParIn) )
  254.         EnumParOut = Ident4;
  255.     switch (EnumParIn)
  256.     {
  257.     case Ident1:    EnumParOut = Ident1; break;
  258.     case Ident2:    if (IntGlob > 100) EnumParOut = Ident1;
  259.             else EnumParOut = Ident4;
  260.             break;
  261.     case Ident3:    EnumParOut = Ident2; break;
  262.     case Ident4:    break;
  263.     case Ident5:    EnumParOut = Ident3;
  264.     }
  265. }
  266.  
  267. void GlobType::Proc8(Array1Dim Array1Par, OneToFifty IntParI1,
  268.    OneToFifty IntParI2)
  269. {
  270.     REG OneToFifty    IntLoc;
  271.     REG OneToFifty    IntIndex;
  272.  
  273.     IntLoc = IntParI1 + 5;
  274.     Array1Par[IntLoc] = IntParI2;
  275.     Array1Par[IntLoc+1] = Array1Par[IntLoc];
  276.     Array1Par[IntLoc+30] = IntLoc;
  277.     for (IntIndex = IntLoc; IntIndex <= (IntLoc+1); ++IntIndex)
  278.         Array2Glob[IntLoc][IntIndex] = IntLoc;
  279.     ++Array2Glob[IntLoc][IntLoc-1];
  280.     Array2Glob[IntLoc+20][IntLoc] = Array1Par[IntLoc];
  281.     IntGlob = 5;
  282. }
  283.  
  284. INLINE Enumeration GlobType::Func1(CapitalLetter CharPar1, CapitalLetter CharPar2)
  285. {                                   
  286.     REG CapitalLetter    CharLoc1;       
  287.     REG CapitalLetter    CharLoc2;
  288.  
  289.     CharLoc1 = CharPar1;
  290.     CharLoc2 = CharLoc1;
  291.     if (CharLoc2 != CharPar2)
  292.         return (Ident1);
  293.     else
  294.         return (Ident2);
  295. }
  296.  
  297. boolean GlobType::Func2(String30 StrParI1, String30 StrParI2)
  298. {
  299.     REG OneToThirty        IntLoc;
  300.     REG CapitalLetter    CharLoc;
  301.  
  302.     IntLoc = 1;
  303.     while (IntLoc <= 1)
  304.         if (Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1)
  305.         {
  306.             CharLoc = 'A';
  307.             ++IntLoc;
  308.         }
  309.     if (CharLoc >= 'W' && CharLoc <= 'Z')
  310.         IntLoc = 7;
  311.     if (CharLoc == 'X')
  312.         return(TRUE);
  313.     else
  314.     {
  315.         if (strcmp(StrParI1, StrParI2) > 0)
  316.         {
  317.             IntLoc += 7;
  318.             return (TRUE);
  319.         }
  320.         else
  321.             return (FALSE);
  322.     }
  323. }
  324.  
  325.  
  326.  
  327. // replaces PROC0
  328. void GlobType::Run(RecordPtr Ptr) 
  329. {
  330.    unsigned int i;
  331.     OneToFifty        IntLoc1;
  332.     REG OneToFifty    IntLoc2;
  333.     OneToFifty        IntLoc3;
  334.     REG char        CharLoc;
  335.     REG char        CharIndex;
  336.     Enumeration         EnumLoc;
  337.     String30        String1Loc;
  338.     String30        String2Loc;
  339.  
  340.     PtrGlbNext = Ptr;
  341.    SetPtrComp(PtrGlbNext);
  342.     strcpy(GetStringComp(), "DHRYSTONE PROGRAM, SOME STRING");
  343.     strcpy(String1Loc, "DHRYSTONE PROGRAM, 1'ST STRING");    /*GOOF*/
  344.     Array2Glob[8][7] = 10;    /* Was missing in published program */
  345.  
  346.     for (i = 0; i < LOOPS; ++i)
  347.          {
  348.         Proc5();
  349.         Proc4();
  350.         IntLoc1 = 2;
  351.         IntLoc2 = 3;
  352.         strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  353.         EnumLoc = Ident2;
  354.         BoolGlob = ! Func2(String1Loc, String2Loc);
  355.         while (IntLoc1 < IntLoc2)
  356.              {
  357.             IntLoc3 = 5 * IntLoc1 - IntLoc2;
  358.             Proc7(IntLoc1, IntLoc2, IntLoc3);
  359.             ++IntLoc1;
  360.             }
  361.         Proc8(Array1Glob, IntLoc1, IntLoc3);
  362.         Proc1((RecordPtr)this);
  363.         for (CharIndex = 'A'; CharIndex <= Char2Glob; ++CharIndex)
  364.             if (EnumLoc == Func1(CharIndex, 'C'))
  365.                 Proc6(Ident1, EnumLoc);
  366.         IntLoc3 = IntLoc2 * IntLoc1;
  367.         IntLoc2 = IntLoc3 / IntLoc1;
  368.         IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1;
  369.         Proc2(IntLoc1);
  370.     }
  371. }
  372.  
  373. GlobType DoIt;
  374.  
  375. main()
  376. {
  377.    int results = 0;
  378.    RecordPtr RecPtr;
  379.    RecPtr = new RecordType;
  380.    DoIt.Run(RecPtr);
  381.    results = DoIt.TestResults();
  382.    delete RecPtr;
  383.    if (results)
  384.       return 1;
  385.    return 0;
  386. }
  387.