Files
mips/_old/src/towers.c
T
jens 26291bca3d - initial import
git-svn-id: http://moon:8086/svn/mips@1 a8ebac50-d88d-4704-bea3-6648445a41b3
2014-07-20 15:01:37 +00:00

209 lines
4.0 KiB
C

/* stanford baby benchmark suite from john hennessy --
There are copies all around; the MIPS performance brief has up-to-date
numbers for a bunch of machines. BUT, these wouldn't be my first
choice. SPEC, the industry benchmark collection group, will probably
specify a new set of benchmarks shortly and release then right after
that. I imagine they will include espresso, gcc, and other large, but
public domain programs, for real things.
here's bench.c
John Hennessy
*/
/* This is a suite of benchmarks that are relatively short, both in program
size and execution time. It requires no input, and prints the execution
time for each program, using the system- dependent routine Getclock,
below, to find out the current CPU time. It does a rudimentary check to
make sure each program gets the right output. These programs were
gathered by John Hennessy and modified by Peter Nye.
4.2 VERSION */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/times.h>
#ifndef HZ
#define HZ 60
#endif
#define nil 0
#define false 0
#define true 1
#define towersbase 2.39
/* Towers */
#define maxcells 18
/* Towers *//*
discsizrange = 1..maxcells; */
#define stackrange 3
/* cellcursor = 0..maxcells; */
struct element
{
int discsize;
int next;
};
float value;
float fixed, floated;
/* global */
int timer;
int xtimes[11];
int seed;
/* Towers */
int stack[stackrange + 1];
struct element cellspace[maxcells + 1];
int freelist, movesdone;
/* global procedures */
int
Getclock ()
{
struct tms rusage;
times (&rusage);
return ((60*rusage.tms_utime/HZ) * 50 / 3);
};
/* Program to Solve the Towers of Hanoi */
Error (emsg)
char *emsg;
{
printf (" Error in Towers: %s\n", emsg);
};
Makenull (s)
{
stack[s] = 0;
};
int
Getelement ()
{
int temp;
if (freelist > 0)
{
temp = freelist;
freelist = cellspace[freelist].next;
}
else
Error ("out of space ");
return (temp);
};
Push (i, s)
int i, s;
{
int errorfound, localel;
errorfound = false;
if (stack[s] > 0)
if (cellspace[stack[s]].discsize <= i)
{
errorfound = true;
Error ("disc size error");
};
if (!errorfound)
{
localel = Getelement ();
cellspace[localel].next = stack[s];
stack[s] = localel;
cellspace[localel].discsize = i;
}
};
Init (s, n)
int s, n;
{
int discctr;
Makenull (s);
for (discctr = n; discctr >= 1; discctr--)
Push (discctr, s);
};
int
Pop (s)
int s;
{
int temp, temp1;
if (stack[s] > 0)
{
temp1 = cellspace[stack[s]].discsize;
temp = cellspace[stack[s]].next;
cellspace[stack[s]].next = freelist;
freelist = stack[s];
stack[s] = temp;
return (temp1);
}
else
Error ("nothing to pop ");
};
Move (s1, s2)
int s1, s2;
{
Push (Pop (s1), s2);
movesdone = movesdone + 1;
};
tower (i, j, k)
int i, j, k;
{
int other;
if (k == 1)
Move (i, j);
else
{
other = 6 - i - j;
tower (i, other, k - 1);
Move (i, j);
tower (other, j, k - 1);
}
};
Towers ()
{ /* Towers */
int i;
for (i = 1; i <= maxcells; i++)
cellspace[i].next = i - 1;
freelist = maxcells;
Init (1, 14);
Makenull (2);
Makenull (3);
movesdone = 0;
tower (1, 2, 14);
if (movesdone != 16383)
printf (" Error in Towers.\n");
}; /* Towers */
main ()
{
int i;
fixed = 0.0;
floated = 0.0;
printf ("Starting \n");
/* rewrite (output); */
setbuf(stdout, nil);
printf (" Towers");
timer = Getclock ();
Towers ();
xtimes[2] = Getclock () - timer;
fixed = fixed + towersbase * xtimes[2];
floated = floated + towersbase * xtimes[2];
printf ("\n");
printf ("%8d", xtimes[2]);
printf ("\n");
/* compute composites */
printf ("\n");
// printf ("Nonfloating point composite is %10.0f\n", fixed / 10.0);
// printf ("\n");
// printf ("Floating point composite is %10.0f\n", floated / 10.0);
}