Commit 43dd4f06 authored by kuhnm's avatar kuhnm

blatt 01

parent f4f9db3b
This diff is collapsed.
import m5
from m5.objects import *
system = System()
system.clk_domain = SrcClockDomain()
system.clk_domain.clock = '1GHz'
system.clk_domain.voltage_domain = VoltageDomain()
system.mem_mode = 'timing'
system.mem_ranges = [AddrRange('512MB')]
system.cpu = TimingSimpleCPU()
system.membus = SystemXBar()
system.cpu.icache_port = system.membus.slave
system.cpu.dcache_port = system.membus.slave
system.cpu.createInterruptController()
system.system_port = system.membus.slave
system.mem_ctrl = DDR3_1600_x64()
system.mem_ctrl.range = system.mem_ranges[0]
system.mem_ctrl.port = system.membus.master
process = LiveProcess()
process.cmd = ['/home/box/gem5/blatt01/exec/hello/hello_world']
system.cpu.workload = process
system.cpu.createThreads()
root = Root(full_system = False, system = system)
m5.instantiate()
exit_event = m5.simulate()
newprocess = LiveProcess()
newprocess.cmd = ['/home/box/gem5/blatt01/exec/automotive/basicmath/basicmath_small']
system.cpu.workload = newprocess
system.cpu.createThreads()
print "Beginning simulation!"
exit_event = m5.simulate()
print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause())
Compile Instructions
--------------------
1) Type "make". This will create the executables used by the scripts.
Clean Instructions
------------------
1) Type "make clean". This will delete post-compile files (i.e.
old executables, output, object files, etc...).
From http://www.snippets.org/.
This code is FREE with no restrictions.
FILE1 = basicmath_small.c rad2deg.c cubic.c isqrt.c
FILE2 = basicmath_large.c rad2deg.c cubic.c isqrt.c
all: basicmath_small basicmath_large
basicmath_small: ${FILE1} Makefile
arm-linux-gnueabihf-gcc -static -O3 ${FILE1} -o basicmath_small -lm
basicmath_large: ${FILE2} Makefile
arm-linux-gnueabihf-gcc -static -O3 ${FILE2} -o basicmath_large -lm
clean:
rm -rf basicmath_small basicmath_large output*
#include "snipmath.h"
#include <math.h>
/* The printf's may be removed to isolate just the math calculations */
int main(void)
{
double a1 = 1.0, b1 = -10.5, c1 = 32.0, d1 = -30.0;
double x[3];
double X;
int solutions;
int i;
unsigned long l = 0x3fed0169L;
struct int_sqrt q;
long n = 0;
/* solve soem cubic functions */
printf("********* CUBIC FUNCTIONS ***********\n");
/* should get 3 solutions: 2, 6 & 2.5 */
SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
a1 = 1.0; b1 = -4.5; c1 = 17.0; d1 = -30.0;
/* should get 1 solution: 2.5 */
SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
a1 = 1.0; b1 = -3.5; c1 = 22.0; d1 = -31.0;
SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
a1 = 1.0; b1 = -13.7; c1 = 1.0; d1 = -35.0;
SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
a1 = 3.0; b1 = 12.34; c1 = 5.0; d1 = 12.0;
SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
a1 = -8.0; b1 = -67.89; c1 = 6.0; d1 = -23.6;
SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
a1 = 45.0; b1 = 8.67; c1 = 7.5; d1 = 34.0;
SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
a1 = -12.0; b1 = -1.7; c1 = 5.3; d1 = 16.0;
SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
/* Now solve some random equations */
for(a1=1;a1<10;a1+=1) {
for(b1=10;b1>0;b1-=.25) {
for(c1=5;c1<15;c1+=0.61) {
for(d1=-1;d1>-5;d1-=.451) {
SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
}
}
}
}
printf("********* INTEGER SQR ROOTS ***********\n");
/* perform some integer square roots */
for (i = 0; i < 100000; i+=2)
{
usqrt(i, &q);
// remainder differs on some machines
// printf("sqrt(%3d) = %2d, remainder = %2d\n",
printf("sqrt(%3d) = %2d\n",
i, q.sqrt);
}
printf("\n");
for (l = 0x3fed0169L; l < 0x3fed4169L; l++)
{
usqrt(l, &q);
//printf("\nsqrt(%lX) = %X, remainder = %X\n", l, q.sqrt, q.frac);
printf("sqrt(%lX) = %X\n", l, q.sqrt);
}
printf("********* ANGLE CONVERSION ***********\n");
/* convert some rads to degrees */
/* for (X = 0.0; X <= 360.0; X += 1.0) */
for (X = 0.0; X <= 360.0; X += .001)
printf("%3.0f degrees = %.12f radians\n", X, deg2rad(X));
puts("");
/* for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 180)) */
for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 5760))
printf("%.12f radians = %3.0f degrees\n", X, rad2deg(X));
return 0;
}
#include "snipmath.h"
#include <math.h>
/* The printf's may be removed to isolate just the math calculations */
int main(void)
{
double a1 = 1.0, b1 = -10.5, c1 = 32.0, d1 = -30.0;
double a2 = 1.0, b2 = -4.5, c2 = 17.0, d2 = -30.0;
double a3 = 1.0, b3 = -3.5, c3 = 22.0, d3 = -31.0;
double a4 = 1.0, b4 = -13.7, c4 = 1.0, d4 = -35.0;
double x[3];
double X;
int solutions;
int i;
unsigned long l = 0x3fed0169L;
struct int_sqrt q;
long n = 0;
/* solve soem cubic functions */
printf("********* CUBIC FUNCTIONS ***********\n");
/* should get 3 solutions: 2, 6 & 2.5 */
SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
/* should get 1 solution: 2.5 */
SolveCubic(a2, b2, c2, d2, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
SolveCubic(a3, b3, c3, d3, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
SolveCubic(a4, b4, c4, d4, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
/* Now solve some random equations */
for(a1=1;a1<10;a1++) {
for(b1=10;b1>0;b1--) {
for(c1=5;c1<15;c1+=0.5) {
for(d1=-1;d1>-11;d1--) {
SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
}
}
}
}
printf("********* INTEGER SQR ROOTS ***********\n");
/* perform some integer square roots */
for (i = 0; i < 1001; ++i)
{
usqrt(i, &q);
// remainder differs on some machines
// printf("sqrt(%3d) = %2d, remainder = %2d\n",
printf("sqrt(%3d) = %2d\n",
i, q.sqrt);
}
usqrt(l, &q);
//printf("\nsqrt(%lX) = %X, remainder = %X\n", l, q.sqrt, q.frac);
printf("\nsqrt(%lX) = %X\n", l, q.sqrt);
printf("********* ANGLE CONVERSION ***********\n");
/* convert some rads to degrees */
for (X = 0.0; X <= 360.0; X += 1.0)
printf("%3.0f degrees = %.12f radians\n", X, deg2rad(X));
puts("");
for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 180))
printf("%.12f radians = %3.0f degrees\n", X, rad2deg(X));
return 0;
}
/* +++Date last modified: 05-Jul-1997 */
/*
** CUBIC.C - Solve a cubic polynomial
** public domain by Ross Cottrell
*/
#include <math.h>
#include <stdlib.h>
#include "snipmath.h"
void SolveCubic(double a,
double b,
double c,
double d,
int *solutions,
double *x)
{
long double a1 = b/a, a2 = c/a, a3 = d/a;
long double Q = (a1*a1 - 3.0*a2)/9.0;
long double R = (2.0*a1*a1*a1 - 9.0*a1*a2 + 27.0*a3)/54.0;
double R2_Q3 = R*R - Q*Q*Q;
double theta;
if (R2_Q3 <= 0)
{
*solutions = 3;
theta = acos(R/sqrt(Q*Q*Q));
x[0] = -2.0*sqrt(Q)*cos(theta/3.0) - a1/3.0;
x[1] = -2.0*sqrt(Q)*cos((theta+2.0*PI)/3.0) - a1/3.0;
x[2] = -2.0*sqrt(Q)*cos((theta+4.0*PI)/3.0) - a1/3.0;
}
else
{
*solutions = 1;
x[0] = pow(sqrt(R2_Q3)+fabs(R), 1/3.0);
x[0] += Q/x[0];
x[0] *= (R < 0.0) ? 1 : -1;
x[0] -= a1/3.0;
}
}
#ifdef TEST
int main(void)
{
double a1 = 1.0, b1 = -10.5, c1 = 32.0, d1 = -30.0;
double a2 = 1.0, b2 = -4.5, c2 = 17.0, d2 = -30.0;
double x[3];
int solutions;
SolveCubic(a1, b1, c1, d1, &solutions, x);
/* should get 3 solutions: 2, 6 & 2.5 */
SolveCubic(a2, b2, c2, d2, &solutions, x);
/* should get 1 solution: 2.5 */
return 0;
}
#endif /* TEST */
/* +++Date last modified: 05-Jul-1997 */
#include <string.h>
#include "snipmath.h"
#define BITSPERLONG 32
#define TOP2BITS(x) ((x & (3L << (BITSPERLONG-2))) >> (BITSPERLONG-2))
/* usqrt:
ENTRY x: unsigned long
EXIT returns floor(sqrt(x) * pow(2, BITSPERLONG/2))
Since the square root never uses more than half the bits
of the input, we use the other half of the bits to contain
extra bits of precision after the binary point.
EXAMPLE
suppose BITSPERLONG = 32
then usqrt(144) = 786432 = 12 * 65536
usqrt(32) = 370727 = 5.66 * 65536
NOTES
(1) change BITSPERLONG to BITSPERLONG/2 if you do not want
the answer scaled. Indeed, if you want n bits of
precision after the binary point, use BITSPERLONG/2+n.
The code assumes that BITSPERLONG is even.
(2) This is really better off being written in assembly.
The line marked below is really a "arithmetic shift left"
on the double-long value with r in the upper half
and x in the lower half. This operation is typically
expressible in only one or two assembly instructions.
(3) Unrolling this loop is probably not a bad idea.
ALGORITHM
The calculations are the base-two analogue of the square
root algorithm we all learned in grammar school. Since we're
in base 2, there is only one nontrivial trial multiplier.
Notice that absolutely no multiplications or divisions are performed.
This means it'll be fast on a wide range of processors.
*/
void usqrt(unsigned long x, struct int_sqrt *q)
{
unsigned long a = 0L; /* accumulator */
unsigned long r = 0L; /* remainder */
unsigned long e = 0L; /* trial product */
int i;
for (i = 0; i < BITSPERLONG; i++) /* NOTE 1 */
{
r = (r << 2) + TOP2BITS(x); x <<= 2; /* NOTE 2 */
a <<= 1;
e = (a << 1) + 1;
if (r >= e)
{
r -= e;
a++;
}
}
memcpy(q, &a, sizeof(long));
}
#ifdef TEST
#include <stdio.h>
#include <stdlib.h>
main(void)
{
int i;
unsigned long l = 0x3fed0169L;
struct int_sqrt q;
for (i = 0; i < 101; ++i)
{
usqrt(i, &q);
printf("sqrt(%3d) = %2d, remainder = %2d\n",
i, q.sqrt, q.frac);
}
usqrt(l, &q);
printf("\nsqrt(%lX) = %X, remainder = %X\n", l, q.sqrt, q.frac);
return 0;
}
#endif /* TEST */
/* +++Date last modified: 05-Jul-1997 */
#ifndef PI__H
#define PI__H
#ifndef PI
#define PI (4*atan(1))
#endif
#define deg2rad(d) ((d)*PI/180)
#define rad2deg(r) ((r)*180/PI)
#endif /* PI__H */
/* +++Date last modified: 05-Jul-1997 */
/*
** RAD2DEG.C - Functions to convert between radians and degrees
*/
#include <math.h>
#include "snipmath.h"
#undef rad2deg /* These are macros defined in PI.H */
#undef deg2rad
double rad2deg(double rad)
{
return (180.0 * rad / (PI));
}
double deg2rad(double deg)
{
return (PI * deg / 180.0);
}
#ifdef TEST
#include <stdio.h>
main()
{
double X;
for (X = 0.0; X <= 360.0; X += 45.0)
printf("%3.0f degrees = %.12f radians\n", X, deg2rad(X));
puts("");
for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 6))
printf("%.12f radians = %3.0f degrees\n", X, rad2deg(X));
return 0;
}
#endif /* TEST */
/* +++Date last modified: 05-Jul-1997 */
/*
** rounding macros by Dave Knapp, Thad Smith, Jon Strayer, & Bob Stout
*/
#ifndef ROUND__H
#define ROUND__H
#include <math.h>
#if defined(__cplusplus) && __cplusplus
/*
** Safe C++ inline versions
*/
/* round to integer */
inline int iround(double x)
{
return (int)floor(x + 0.5);
}
/* round number n to d decimal points */
inline double fround(double n, unsigned d)
{
return floor(n * pow(10., d) + .5) / pow(10., d);
}
#else
/*
** NOTE: These C macro versions are unsafe since arguments are referenced
** more than once.
**
** Avoid using these with expression arguments to be safe.
*/
/*
** round to integer
*/
#define iround(x) floor((x) + 0.5)
/*
** round number n to d decimal points
*/
#define fround(n,d) (floor((n)*pow(10.,(d))+.5)/pow(10.,(d)))
#endif
#endif /* ROUND__H */
#!/bin/sh
./basicmath_large > output_large.txt
#!/bin/sh
basicmath_small > output_small.txt
/* +++Date last modified: 05-Jul-1997 */
/*
** SNIPMATH.H - Header file for SNIPPETS math functions and macros
*/
#ifndef SNIPMATH__H
#define SNIPMATH__H
#include <math.h>
#include "sniptype.h"
#include "round.h"
/*
** Callable library functions begin here
*/
void SetBCDLen(int n); /* Bcdl.C */
long BCDtoLong(char *BCDNum); /* Bcdl.C */
void LongtoBCD(long num, char BCDNum[]); /* Bcdl.C */
double bcd_to_double(void *buf, size_t len, /* Bcdd.C */
int digits);
int double_to_bcd(double arg, char *buf, /* Bcdd.C */
size_t length, size_t digits );
DWORD ncomb1 (int n, int m); /* Combin.C */
DWORD ncomb2 (int n, int m); /* Combin.C */
void SolveCubic(double a, double b, double c, /* Cubic.C */
double d, int *solutions,
double *x);
DWORD dbl2ulong(double t); /* Dbl2Long.C */
long dbl2long(double t); /* Dbl2Long.C */
double dround(double x); /* Dblround.C */
/* Use #defines for Permutations and Combinations -- Factoryl.C */
#define log10P(n,r) (log10factorial(n)-log10factorial((n)-(r)))
#define log10C(n,r) (log10P((n),(r))-log10factorial(r))
double log10factorial(double N); /* Factoryl.C */