home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
cprog
/
blx21.zip
/
BC31.ARJ
/
DRYSTN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-20
|
9KB
|
387 lines
/*
Program: Drystn (Dhrystone)
Version: 0.1b
Date: February 19, 1992
Language: 2.1 C++
The program is based on the drystone benchmark program published
originally by MICRO CORNICOPIA magazine. As far as possible, the
program contains the same distribution of assignments, control statements
and procedure or function calls as the original C program, except that
some of the procedures and functions were declared 'inline'. Inlining can
be turned off by defining NOINLINE on the command line.
*/
#include <stdio.h>
#include <string.h>
#include <process.h>
#include <stdlib.h>
const unsigned LOOPS = 50000;
char Version[] = "0.01PR";
#define structassign(d, s) (d) = (s)
typedef int OneToThirty;
typedef int OneToFifty;
typedef char CapitalLetter;
typedef char String30[31];
typedef int Array1Dim[51];
typedef int Array2Dim[51][51];
#undef NULL
#define NULL 0
#define TRUE 1
#define FALSE 0
#ifndef REG
#define REG
#endif
#ifdef NOINLINE
#define INLINE
#else
#define INLINE inline
#endif
enum Enumeration {Ident1, Ident2, Ident3, Ident4, Ident5};
typedef int boolean;
class RecordType;
typedef RecordType * RecordPtr;
class RecordType
{
private:
RecordPtr PtrComp;
Enumeration Discr;
Enumeration EnumComp;
OneToFifty IntComp;
String30 StringComp;
public:
RecordType() { }
RecordType(Enumeration Dis, Enumeration En, OneToFifty In) :
Discr(Dis), EnumComp(En), IntComp(In)
{ }
void SetPtrComp(RecordPtr Ptr)
{
PtrComp = Ptr;
}
RecordPtr GetPtrComp()
{
return PtrComp;
}
Enumeration GetDiscr()
{
return Discr;
}
Enumeration GetEnumComp()
{
return EnumComp;
}
OneToFifty & GetIntCompRef()
{
return IntComp;
}
char * GetStringComp()
{
return StringComp;
}
INLINE void Proc1(RecordPtr Ptr);
virtual void Proc3(RecordPtr *);
virtual void Proc6(Enumeration, Enumeration&);
INLINE void Proc7(OneToFifty, OneToFifty, OneToFifty &);
};
INLINE void RecordType::Proc1(RecordPtr PtrParIn)
{
#define NextRecord (*(PtrParIn->PtrComp))
structassign(NextRecord, *this);
PtrParIn->IntComp = 5;
NextRecord.IntComp = PtrParIn->IntComp;
NextRecord.PtrComp = PtrParIn->PtrComp;
Proc3((RecordPtr *)NextRecord.PtrComp);
if (NextRecord.Discr == Ident1)
{
NextRecord.IntComp = 6;
Proc6(PtrParIn->EnumComp, NextRecord.EnumComp);
NextRecord.PtrComp = PtrComp;
Proc7(NextRecord.IntComp, 10, NextRecord.IntComp);
}
else
structassign(*PtrParIn, NextRecord);
#undef NextRecord
}
// DUMMY function
void RecordType::Proc3(RecordPtr *PtrParOut)
{
*PtrParOut = PtrComp;
}
// DUMMY function
void RecordType::Proc6(Enumeration EnumParIn, Enumeration& EnumParOut)
{
EnumParOut = EnumParIn;
}
INLINE void RecordType::Proc7(OneToFifty IntParI1, OneToFifty IntParI2,
OneToFifty &IntParOut)
{
REG OneToFifty IntLoc;
IntLoc = IntParI1 + 2;
IntParOut = IntParI2 + IntLoc;
}
class GlobType : public RecordType
{
int IntGlob;
boolean BoolGlob;
char Char1Glob;
char Char2Glob;
Array1Dim Array1Glob;
Array2Dim Array2Glob;
RecordPtr PtrGlbNext;
public:
GlobType();
void Run(RecordPtr);
virtual void Proc3(RecordPtr *);
void Proc2(OneToFifty&);
INLINE void Proc4();
INLINE void Proc5();
virtual void Proc6(Enumeration, Enumeration&);
void Proc8(Array1Dim, OneToFifty, OneToFifty);
INLINE Enumeration Func1(CapitalLetter CharPar1, CapitalLetter CharPar2);
boolean Func2(String30 StrParI1, String30 StrParI2);
INLINE boolean Func3(REG Enumeration EnumParIn);
int TestResults()
{
int retval = 0;
retval += (GetDiscr() != Ident1);
retval += (GetEnumComp() != Ident2);
retval += (GetIntCompRef() != 17);
retval += (strcmp(GetStringComp(),"DHRYSTONE PROGRAM, SOME STRING"));
retval += (IntGlob != 5);
retval += (BoolGlob != TRUE);
retval += (Char1Glob != 'A');
retval += (Char2Glob != 'B');
retval += (Array1Glob[0] != 0);
retval += (Array1Glob[50] != 0);
retval += (Array1Glob[8] != 7);
retval += (Array1Glob[9] != 7);
retval += (Array2Glob[0][0] != 0);
retval += (Array2Glob[50][50] != 0);
retval += (Array2Glob[8][7] != (int)0xC35A);
retval += (Array2Glob[8][8] != 8);
retval += (Array2Glob[28][8] != 7);
return retval;
}
};
GlobType::GlobType() : RecordType(Ident1, Ident2, 40)
{
}
void GlobType::Proc2(OneToFifty& IntParIO)
{
REG OneToFifty IntLoc;
REG Enumeration EnumLoc = Ident2;
IntLoc = IntParIO + 10;
for(;;)
{
if (Char1Glob == 'A')
{
--IntLoc;
IntParIO = IntLoc - IntGlob;
EnumLoc = Ident1;
}
if (EnumLoc == Ident1)
break;
}
}
void GlobType::Proc3(RecordPtr *PtrParOut)
{
if (this != NULL) // never will equal null, but who cares
*PtrParOut = GetPtrComp();
else
IntGlob = 100;
Proc7(10, IntGlob, GetIntCompRef());
}
INLINE void GlobType::Proc4()
{
REG boolean BoolLoc;
BoolLoc = Char1Glob == 'A';
BoolLoc |= BoolGlob;
Char2Glob = 'B';
}
INLINE void GlobType::Proc5()
{
Char1Glob = 'A';
BoolGlob = FALSE;
}
INLINE boolean GlobType::Func3(REG Enumeration EnumParIn)
{
REG Enumeration EnumLoc;
EnumLoc = EnumParIn;
if (EnumLoc == Ident3)
return (TRUE);
return (FALSE);
}
void GlobType::Proc6(Enumeration EnumParIn, Enumeration& EnumParOut)
{
EnumParOut = EnumParIn;
if (!Func3(EnumParIn) )
EnumParOut = Ident4;
switch (EnumParIn)
{
case Ident1: EnumParOut = Ident1; break;
case Ident2: if (IntGlob > 100) EnumParOut = Ident1;
else EnumParOut = Ident4;
break;
case Ident3: EnumParOut = Ident2; break;
case Ident4: break;
case Ident5: EnumParOut = Ident3;
}
}
void GlobType::Proc8(Array1Dim Array1Par, OneToFifty IntParI1,
OneToFifty IntParI2)
{
REG OneToFifty IntLoc;
REG OneToFifty IntIndex;
IntLoc = IntParI1 + 5;
Array1Par[IntLoc] = IntParI2;
Array1Par[IntLoc+1] = Array1Par[IntLoc];
Array1Par[IntLoc+30] = IntLoc;
for (IntIndex = IntLoc; IntIndex <= (IntLoc+1); ++IntIndex)
Array2Glob[IntLoc][IntIndex] = IntLoc;
++Array2Glob[IntLoc][IntLoc-1];
Array2Glob[IntLoc+20][IntLoc] = Array1Par[IntLoc];
IntGlob = 5;
}
INLINE Enumeration GlobType::Func1(CapitalLetter CharPar1, CapitalLetter CharPar2)
{
REG CapitalLetter CharLoc1;
REG CapitalLetter CharLoc2;
CharLoc1 = CharPar1;
CharLoc2 = CharLoc1;
if (CharLoc2 != CharPar2)
return (Ident1);
else
return (Ident2);
}
boolean GlobType::Func2(String30 StrParI1, String30 StrParI2)
{
REG OneToThirty IntLoc;
REG CapitalLetter CharLoc;
IntLoc = 1;
while (IntLoc <= 1)
if (Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1)
{
CharLoc = 'A';
++IntLoc;
}
if (CharLoc >= 'W' && CharLoc <= 'Z')
IntLoc = 7;
if (CharLoc == 'X')
return(TRUE);
else
{
if (strcmp(StrParI1, StrParI2) > 0)
{
IntLoc += 7;
return (TRUE);
}
else
return (FALSE);
}
}
// replaces PROC0
void GlobType::Run(RecordPtr Ptr)
{
unsigned int i;
OneToFifty IntLoc1;
REG OneToFifty IntLoc2;
OneToFifty IntLoc3;
REG char CharLoc;
REG char CharIndex;
Enumeration EnumLoc;
String30 String1Loc;
String30 String2Loc;
PtrGlbNext = Ptr;
SetPtrComp(PtrGlbNext);
strcpy(GetStringComp(), "DHRYSTONE PROGRAM, SOME STRING");
strcpy(String1Loc, "DHRYSTONE PROGRAM, 1'ST STRING"); /*GOOF*/
Array2Glob[8][7] = 10; /* Was missing in published program */
for (i = 0; i < LOOPS; ++i)
{
Proc5();
Proc4();
IntLoc1 = 2;
IntLoc2 = 3;
strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
EnumLoc = Ident2;
BoolGlob = ! Func2(String1Loc, String2Loc);
while (IntLoc1 < IntLoc2)
{
IntLoc3 = 5 * IntLoc1 - IntLoc2;
Proc7(IntLoc1, IntLoc2, IntLoc3);
++IntLoc1;
}
Proc8(Array1Glob, IntLoc1, IntLoc3);
Proc1((RecordPtr)this);
for (CharIndex = 'A'; CharIndex <= Char2Glob; ++CharIndex)
if (EnumLoc == Func1(CharIndex, 'C'))
Proc6(Ident1, EnumLoc);
IntLoc3 = IntLoc2 * IntLoc1;
IntLoc2 = IntLoc3 / IntLoc1;
IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1;
Proc2(IntLoc1);
}
}
GlobType DoIt;
main()
{
int results = 0;
RecordPtr RecPtr;
RecPtr = new RecordType;
DoIt.Run(RecPtr);
results = DoIt.TestResults();
delete RecPtr;
if (results)
return 1;
return 0;
}