Commit e94bda4b authored by Christoph Gerum's avatar Christoph Gerum

Exercise Sheet 03

parent c0e4c8a8
#include <stdio.h>
int main(int argc, char **argv){
printf("Hello World!\n");
}
[root]
type=Root
children=system
eventq_index=0
full_system=false
sim_quantum=0
time_sync_enable=false
time_sync_period=100000000000
time_sync_spin_threshold=100000000
[system]
type=System
children=clk_domain cpu dvfs_handler mem_ctrl membus
boot_osflags=a
cache_line_size=64
clk_domain=system.clk_domain
eventq_index=0
init_param=0
kernel=
kernel_addr_check=true
load_addr_mask=1099511627775
load_offset=0
mem_mode=timing
mem_ranges=0:536870911
memories=system.mem_ctrl
mmap_using_noreserve=false
num_work_ids=16
readfile=
symbolfile=
work_begin_ckpt_count=0
work_begin_cpu_id_exit=-1
work_begin_exit_count=0
work_cpus_ckpt_count=0
work_end_ckpt_count=0
work_end_exit_count=0
work_item_id=-1
system_port=system.membus.slave[2]
[system.clk_domain]
type=SrcClockDomain
children=voltage_domain
clock=500
domain_id=-1
eventq_index=0
init_perf_level=0
voltage_domain=system.clk_domain.voltage_domain
[system.clk_domain.voltage_domain]
type=VoltageDomain
eventq_index=0
voltage=1.000000
[system.cpu]
type=TimingSimpleCPU
children=dstage2_mmu dtb interrupts isa istage2_mmu itb tracer workload
branchPred=Null
checker=Null
clk_domain=system.clk_domain
cpu_id=-1
do_checkpoint_insts=true
do_quiesce=true
do_statistics_insts=true
dstage2_mmu=system.cpu.dstage2_mmu
dtb=system.cpu.dtb
eventq_index=0
function_trace=false
function_trace_start=0
interrupts=system.cpu.interrupts
isa=system.cpu.isa
istage2_mmu=system.cpu.istage2_mmu
itb=system.cpu.itb
max_insts_all_threads=0
max_insts_any_thread=0
max_loads_all_threads=0
max_loads_any_thread=0
numThreads=1
profile=0
progress_interval=0
simpoint_start_insts=
socket_id=0
switched_out=false
system=system
tracer=system.cpu.tracer
workload=system.cpu.workload
dcache_port=system.membus.slave[1]
icache_port=system.membus.slave[0]
[system.cpu.dstage2_mmu]
type=ArmStage2MMU
children=stage2_tlb
eventq_index=0
stage2_tlb=system.cpu.dstage2_mmu.stage2_tlb
sys=system
tlb=system.cpu.dtb
[system.cpu.dstage2_mmu.stage2_tlb]
type=ArmTLB
children=walker
eventq_index=0
is_stage2=true
size=32
walker=system.cpu.dstage2_mmu.stage2_tlb.walker
[system.cpu.dstage2_mmu.stage2_tlb.walker]
type=ArmTableWalker
clk_domain=system.clk_domain
eventq_index=0
is_stage2=true
num_squash_per_cycle=2
sys=system
[system.cpu.dtb]
type=ArmTLB
children=walker
eventq_index=0
is_stage2=false
size=64
walker=system.cpu.dtb.walker
[system.cpu.dtb.walker]
type=ArmTableWalker
clk_domain=system.clk_domain
eventq_index=0
is_stage2=false
num_squash_per_cycle=2
sys=system
[system.cpu.interrupts]
type=ArmInterrupts
eventq_index=0
[system.cpu.isa]
type=ArmISA
eventq_index=0
fpsid=1090793632
id_aa64afr0_el1=0
id_aa64afr1_el1=0
id_aa64dfr0_el1=1052678
id_aa64dfr1_el1=0
id_aa64isar0_el1=0
id_aa64isar1_el1=0
id_aa64mmfr0_el1=15728642
id_aa64mmfr1_el1=0
id_aa64pfr0_el1=17
id_aa64pfr1_el1=0
id_isar0=34607377
id_isar1=34677009
id_isar2=555950401
id_isar3=17899825
id_isar4=268501314
id_isar5=0
id_mmfr0=270536963
id_mmfr1=0
id_mmfr2=19070976
id_mmfr3=34611729
id_pfr0=49
id_pfr1=4113
midr=1091551472
pmu=Null
system=system
[system.cpu.istage2_mmu]
type=ArmStage2MMU
children=stage2_tlb
eventq_index=0
stage2_tlb=system.cpu.istage2_mmu.stage2_tlb
sys=system
tlb=system.cpu.itb
[system.cpu.istage2_mmu.stage2_tlb]
type=ArmTLB
children=walker
eventq_index=0
is_stage2=true
size=32
walker=system.cpu.istage2_mmu.stage2_tlb.walker
[system.cpu.istage2_mmu.stage2_tlb.walker]
type=ArmTableWalker
clk_domain=system.clk_domain
eventq_index=0
is_stage2=true
num_squash_per_cycle=2
sys=system
[system.cpu.itb]
type=ArmTLB
children=walker
eventq_index=0
is_stage2=false
size=64
walker=system.cpu.itb.walker
[system.cpu.itb.walker]
type=ArmTableWalker
clk_domain=system.clk_domain
eventq_index=0
is_stage2=false
num_squash_per_cycle=2
sys=system
[system.cpu.tracer]
type=ExeTracer
eventq_index=0
[system.cpu.workload]
type=LiveProcess
cmd=./hello.elf
cwd=
drivers=
egid=100
env=
errout=cerr
euid=100
eventq_index=0
executable=
gid=100
input=cin
kvmInSE=false
max_stack_size=67108864
output=cout
pid=100
ppid=99
simpoint=0
system=system
uid=100
useArchPT=false
[system.dvfs_handler]
type=DVFSHandler
domains=
enable=false
eventq_index=0
sys_clk_domain=system.clk_domain
transition_latency=100000000
[system.mem_ctrl]
type=DRAMCtrl
IDD0=0.064000
IDD02=0.004000
IDD2N=0.050000
IDD2N2=0.000000
IDD2P0=0.000000
IDD2P02=0.000000
IDD2P1=0.000000
IDD2P12=0.000000
IDD3N=0.067000
IDD3N2=0.003000
IDD3P0=0.000000
IDD3P02=0.000000
IDD3P1=0.000000
IDD3P12=0.000000
IDD4R=0.160000
IDD4R2=0.000000
IDD4W=0.180000
IDD4W2=0.000000
IDD5=0.192000
IDD52=0.000000
IDD6=0.000000
IDD62=0.000000
VDD=1.200000
VDD2=2.500000
activation_limit=4
addr_mapping=RoRaBaCoCh
bank_groups_per_rank=4
banks_per_rank=16
burst_length=8
channels=1
clk_domain=system.clk_domain
conf_table_reported=true
device_bus_width=8
device_rowbuffer_size=1024
device_size=536870912
devices_per_rank=8
dll=true
eventq_index=0
in_addr_map=true
max_accesses_per_row=16
mem_sched_policy=frfcfs
min_writes_per_switch=16
null=false
page_policy=open_adaptive
range=0:536870911
ranks_per_channel=2
read_buffer_size=32
static_backend_latency=10000
static_frontend_latency=10000
tBURST=3333
tCCD_L=5000
tCK=833
tCL=14160
tCS=1666
tRAS=32000
tRCD=14160
tREFI=7800000
tRFC=350000
tRP=14160
tRRD=3300
tRRD_L=4900
tRTP=7500
tRTW=1666
tWR=15000
tWTR=5000
tXAW=21000
tXP=0
tXPDLL=0
tXS=0
tXSDLL=0
write_buffer_size=64
write_high_thresh_perc=85
write_low_thresh_perc=50
port=system.membus.master[0]
[system.membus]
type=CoherentXBar
clk_domain=system.clk_domain
eventq_index=0
forward_latency=4
frontend_latency=3
response_latency=2
snoop_filter=Null
snoop_response_latency=4
system=system
use_default_range=false
width=16
master=system.mem_ctrl.port
slave=system.cpu.icache_port system.cpu.dcache_port system.system_port
This diff is collapsed.
This diff is collapsed.
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>
#include <stdio.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)
deg2rad(X);
/* 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))
rad2deg(X);
/* 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.
*/