dhry1.c.txt

(8 KB) Pobierz
/* ===================================================================================== */
/*	Dhrystone 1 Benchmark Source Code -- 
	dryint11.c
	Modification History:
	30 Nov. 93 	phn	Added header to file*/
/* ===================================================================================== */

unsigned long    time,cnt_start,cnt_end,cnt;
unsigned long    cnt_start1,cnt_end1,cnt1;

#include        <string.h>
#include 	"timer.h"   /* Added 3 Sept. 93 */
/*	#include 	"io.h"       Added 3 Sept. 93 */
/* ===================================================================================== */
/* Accuracy of timings and human fatigue controlled by next two lines   */
#define LOOPS        500000          /* Use this for faster machines */

/* Compiler dependent options */
#define NOENUM                  /* Define if compiler has no enum's */
/* #define      NOSTRUCTASSIGN          /* Define if compiler can't assign structures */

/* for compatibility with goofed up version */
/*#undef GOOF                   /* Define if you want the goofed up version */
/* ===================================================================================== */

#ifdef GOOF
char    Version[] = "1.0";
#else
char    Version[] = "1.1";
#endif

#ifdef  NOSTRUCTASSIGN
#define structassign(d, s)      memcpy(&(d), &(s), sizeof(d))
#else
#define structassign(d, s)      d = s
#endif


#define FALSE	0
#define TRUE	~FALSE


#ifdef  NOENUM
#define Ident1  1
#define Ident2  2
#define Ident3  3
#define Ident4  4
#define Ident5  5
typedef int     Enumeration;
#else
typedef enum    {Ident1, Ident2, Ident3, Ident4, Ident5} Enumeration;
#endif

typedef int     OneToThirty;
typedef int     OneToFifty;
typedef char    CapitalLetter;
typedef char    String30[31];
typedef int     Array1Dim[51];
typedef int     Array2Dim[51][51];

struct  Record
{
	struct Record           *PtrComp;
	Enumeration             Discr;
	Enumeration             EnumComp;
	OneToFifty              IntComp;
	String30                StringComp;
};

typedef struct Record   RecordType;
typedef RecordType *    RecordPtr;
typedef int             boolean;

/* #define NULL         0 */

#ifndef REG
#define REG
#endif

/*extern long init_bentime(int); Commented out 2 Sept. 93 */
/*extern long bentime(); Commented out 2 Sept. 93 */

/*
**      get_time()
**      this should be whatever routine is provided to count
**      elapsed processor time.  What the time is measured in
**      is not important.  Time may be measured in ticks(1/60 sec)
**      milliseconds,...etc.
*/
/*      Commented out 3 Sept. 93 
long    get_time()
{
	long    t;
	t = bentime();
	return t;
}
*/

/*
**      convert_to_milliseconds()
**      this should take a time measurement in units determined by
**      get_time() and should convert the time to milliseconds.
*/

main ()
{
         
	Proc0();
}

extern Enumeration      Func1();
extern boolean          Func2();

/*
 * Package 1
 */
int             IntGlob;
boolean         BoolGlob;
char            Char1Glob;
char            Char2Glob;
Array1Dim       Array1Glob;
Array2Dim       Array2Glob;
RecordPtr       PtrGlb;
RecordPtr       PtrGlbNext;

Proc0()
{
    RecordType              Record1, Record2; /* Added 7 Sept. 93 */
	OneToFifty              IntLoc1;
	REG OneToFifty          IntLoc2;
	OneToFifty              IntLoc3;
	REG char                CharIndex;
	Enumeration             EnumLoc;
	String30                String1Loc;
	String30                String2Loc;

	/*extern char             *malloc(); Commented out 7 Sept. 93 */

	register unsigned int   i;

/*  Commenting out malloc stuff because it is not supported.  Adding
    variables Record1 and Record2 to hold space previously occupied by 
    malloc.
	PtrGlbNext = (RecordPtr) malloc(sizeof(RecordType));
	PtrGlb = (RecordPtr) malloc(sizeof(RecordType));
*/

	PtrGlbNext = &Record1; /* Added 7 Sept. 93 */
	PtrGlb = &Record2; /* Added 7 Sept. 93 */
	PtrGlb->PtrComp = PtrGlbNext;
	PtrGlb->Discr = Ident1;
	PtrGlb->EnumComp = Ident3;
	PtrGlb->IntComp = 40;
	strcpy(PtrGlb->StringComp, "DHRYSTONE PROGRAM, SOME STRING");

#ifndef GOOF
	strcpy(String1Loc, "DHRYSTONE PROGRAM, 1'ST STRING");   /*GOOF*/
#endif
	Array2Glob[8][7] = 10;  /* Was missing in published program */


	/*****************
	-- Start Timer --
	*****************/
	/*cnt_start = init_bentime(0); Commented out 3 Sept. 93 */

	start_timer();  /* Added 3 Sept. 93 */

	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, Array2Glob, IntLoc1, IntLoc3);
		Proc1(PtrGlb);
		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);
	}

	stop_timer();  /* Added 3 Sept. 93 */
/*
-- Stop Timer --
*/

/*cnt_end=get_time(); Commented out 3 Sept. 93 */
/*cnt=cnt_end-cnt_start; Commented out 3 Sept. 93 */
/*cnt=convert_to_milliseconds(cnt); Commented out 3 Sept. 93 */

/* cnt = get_time(); */
/* time = cnt * 512;  time = time in ms   Added 7 Sept. 93 */
/* time = time / 100000; 
printf("Dhrystone(%s) time for %d passes = %d ms.\n\r",
		Version,
		(long) LOOPS, time);
printf("This machine benchmarks at %d dhrystones/second.\n\r",
		((long) LOOPS*1000L) / time);
*/

}

Proc1(PtrParIn)
REG RecordPtr   PtrParIn;
{
#define NextRecord      (*(PtrParIn->PtrComp))

	structassign(NextRecord, *PtrGlb);
	PtrParIn->IntComp = 5;
	NextRecord.IntComp = PtrParIn->IntComp;
	NextRecord.PtrComp = PtrParIn->PtrComp;
	Proc3(NextRecord.PtrComp);
	if (NextRecord.Discr == Ident1)
	{
		NextRecord.IntComp = 6;
		Proc6(PtrParIn->EnumComp, &NextRecord.EnumComp);
		NextRecord.PtrComp = PtrGlb->PtrComp;
		Proc7(NextRecord.IntComp, 10, &NextRecord.IntComp);
	}
	else
		structassign(*PtrParIn, NextRecord);

#undef  NextRecord
}

Proc2(IntParIO)
OneToFifty      *IntParIO;
{
	REG OneToFifty          IntLoc;
	REG Enumeration         EnumLoc;

	IntLoc = *IntParIO + 10;
	for(;;)
	{
		if (Char1Glob == 'A')
		{
			--IntLoc;
			*IntParIO = IntLoc - IntGlob;
			EnumLoc = Ident1;
		}
		if (EnumLoc == Ident1)
			break;
	}
}

Proc3(PtrParOut)
RecordPtr       *PtrParOut;
{
	if (PtrGlb != NULL)
		*PtrParOut = PtrGlb->PtrComp;
	else
		IntGlob = 100;
	Proc7(10, IntGlob, &PtrGlb->IntComp);
}

Proc4()
{
	REG boolean     BoolLoc;

	BoolLoc = Char1Glob == 'A';
	BoolLoc |= BoolGlob;
	Char2Glob = 'B';
}

Proc5()
{
	Char1Glob = 'A';
	BoolGlob = FALSE;
}

extern boolean Func3();

Proc6(EnumParIn, EnumParOut)
REG Enumeration EnumParIn;
REG 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;
	}
}

Proc7(IntParI1, IntParI2, IntParOut)
OneToFifty      IntParI1;
OneToFifty      IntParI2;
OneToFifty      *IntParOut;
{
	REG OneToFifty  IntLoc;

	IntLoc = IntParI1 + 2;
	*IntParOut = IntParI2 + IntLoc;
}

Proc8(Array1Par, Array2Par, IntParI1, IntParI2)
Array1Dim       Array1Par;
Array2Dim       Array2Par;
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)
		Array2Par[IntLoc][IntIndex] = IntLoc;
	++Array2Par[IntLoc][IntLoc-1];
	Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc];
	IntGlob = 5;
}

Enumeration Func1(CharPar1, CharPar2)
CapitalLetter   CharPar1;
CapitalLetter   CharPar2;
{
	REG CapitalLetter       CharLoc1;
	REG CapitalLetter       CharLoc2;

	CharLoc1 = CharPar1;
	CharLoc2 = CharLoc1;
	if (CharLoc2 != CharPar2)
		return (Ident1);
	else
		return (Ident2);
}

boolean Func2(StrParI1, StrParI2)
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);
	}
}

boolean Func3(EnumParIn)
REG Enumeration EnumParIn;
{
	REG Enumeration EnumLoc;

	EnumLoc = EnumParIn;
	if (EnumLoc == Ident3) return (TRUE);
	return (FALSE);
}

#ifdef  NOSTRUCTASSIGN
memcpy(d, s, l)
register char   *d;
register char   *s;
register int    l;
{
	while (l--) *d++ = *s++;
}
#endif

Zgłoś jeśli naruszono regulamin