diff --git a/seminaries/qtrvsim/fibo-hazards/.gitignore b/seminaries/qtrvsim/fibo-hazards/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..8b8d27c61d41913654ad945bf2867cb504914253 --- /dev/null +++ b/seminaries/qtrvsim/fibo-hazards/.gitignore @@ -0,0 +1,7 @@ +*.o +depend +fibo-hazards +fibo_limit.in +fibo_series.out + + diff --git a/seminaries/qtrvsim/fibo-hazards/Makefile b/seminaries/qtrvsim/fibo-hazards/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..33a5caae0efb18989a7235cfc374f7a3f68a92c8 --- /dev/null +++ b/seminaries/qtrvsim/fibo-hazards/Makefile @@ -0,0 +1,90 @@ +ARCH=riscv64-unknown-elf + +SOURCES = fibo-hazards.S +TARGET_EXE = fibo-hazards + +CC=$(ARCH)-gcc +CXX=$(ARCH)-g++ +AS=$(ARCH)-as +LD=$(ARCH)-ld +OBJCOPY=$(ARCH)-objcopy + +ARCHFLAGS += -mabi=ilp32 +ARCHFLAGS += -march=rv32i +ARCHFLAGS += -fno-lto + +CFLAGS += -ggdb -Os -Wall +CXXFLAGS+= -ggdb -Os -Wall +AFLAGS += -ggdb +LDFLAGS += -ggdb +LDFLAGS += -nostartfiles +LDFLAGS += -nostdlib +LDFLAGS += -static +#LDFLAGS += -specs=/opt/musl/riscv64-linux-gnu/lib/musl-gcc.specs + +CFLAGS += $(ARCHFLAGS) +CXXFLAGS+= $(ARCHFLAGS) +AFLAGS += $(ARCHFLAGS) +LDFLAGS += $(ARCHFLAGS) + +OBJECTS += $(filter %.o,$(SOURCES:%.S=%.o)) +OBJECTS += $(filter %.o,$(SOURCES:%.c=%.o)) +OBJECTS += $(filter %.o,$(SOURCES:%.cpp=%.o)) + +all : default + +.PHONY : default clean dep all run_test + +%.o:%.S + $(CC) -D__ASSEMBLY__ $(AFLAGS) -c $< -o $@ + +%.o:%.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ + +%.o:%.cpp + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< + +%.s:%.c + $(CC) $(CFLAGS) $(CPPFLAGS) -S $< -o $@ + +#default : $(TARGET_EXE) +default : run_test + +$(TARGET_EXE) : $(OBJECTS) + $(CC) $(LDFLAGS) $^ -o $@ + +dep: depend + +depend: $(SOURCES) $(glob *.h) + echo '# autogenerated dependencies' > depend +ifneq ($(filter %.S,$(SOURCES)),) + $(CC) -D__ASSEMBLY__ $(AFLAGS) -w -E -M $(filter %.S,$(SOURCES)) \ + >> depend +endif +ifneq ($(filter %.c,$(SOURCES)),) + $(CC) $(CFLAGS) $(CPPFLAGS) -w -E -M $(filter %.c,$(SOURCES)) \ + >> depend +endif +ifneq ($(filter %.cpp,$(SOURCES)),) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -w -E -M $(filter %.cpp,$(SOURCES)) \ + >> depend +endif + +clean: + rm -f *.o *.a $(OBJECTS) $(TARGET_EXE) depend fibo_series.out fibo_limit.in + +#riscv64-unknown-elf-objdump --source fibo-hazards + +FIBO_SERIES_REF_FILE=fibo_series.ref +fibo_limit:=$(words $(filter-out 0x00000000,$(shell cat $(FIBO_SERIES_REF_FILE)))) +FIBO_SERIES_BYTES:=$(words $(shell seq 1 8) $(shell seq 1 $(fibo_limit)) $(shell seq 1 $(fibo_limit)) $(shell seq 1 $(fibo_limit)) $(shell seq 1 $(fibo_limit))) + +run_test: $(TARGET_EXE) + echo $(fibo_limit) >fibo_limit.in + qtrvsim_cli --pipelined --hazard-unit none \ + --dump-cycles $< \ + --load-range fibo_limit,fibo_limit.in \ + --dump-range fibo_series,$(FIBO_SERIES_BYTES),fibo_series.out + diff -u -B -b fibo_series.out $(FIBO_SERIES_REF_FILE) + +-include depend diff --git a/seminaries/qtrvsim/fibo-hazards/fibo-hazards-template.S b/seminaries/qtrvsim/fibo-hazards/fibo-hazards-template.S new file mode 100644 index 0000000000000000000000000000000000000000..acb5b5b16983a78a9c87dea7947ac575a2d9334d --- /dev/null +++ b/seminaries/qtrvsim/fibo-hazards/fibo-hazards-template.S @@ -0,0 +1,62 @@ +// fibo-hazards.S file template, rename and implement the algorithm +// Test algorithm in qtmips_gui program +// Select the CPU core configuration to +// Pipelined without hazard unit and cache +// This option select version where RAW dependencies which leads +// to hazards are not resolved in hardware, you need to schedule +// instruction execution according to the pipeline structure +// (classical 5-stage MIPS) such way, that no dependency results +// in a hazard + + +// copy directory with the project to your repository to +// the directory work/fibo-hazards +// critical is location of the file work/fibo-hazards/fibo-hazards.S +// which is checked by the scripts + +// The script loads number of the last Fibonacci series element to compute +// into fibo_limit variable and expects computed series in memory starting +// at address fibo_series, the series has to be followed by at least +// one zero element + +// When tested by actual qtmips_cli version, the variant without hazard +// unit cannot be selected (this is WIP for the test script), use qtmips_gui +// which is fully configurable + +// Directives to make interesting windows visible +#pragma qtmips show registers +#pragma qtmips show memory + +.option norelax + +.globl fibo_limit +.globl fibo_series + +.text +.globl _start + +_start: + + la a0, fibo_series + la a1, fibo_limit + lw a1, 0(a1) // number of elements in the array + +//Insert your code there + +//Final infinite loop +end_loop: + fence // flush cache memory + ebreak // stop the simulator + j end_loop + nop + +.data +// .align 2 // not supported by QtMips yet + +fibo_limit: + .word 15 +fibo_series: + .skip 1000*4 + +// Specify location to show in memory window +#pragma qtmips focus memory fibo_limit diff --git a/seminaries/qtrvsim/fibo-hazards/fibo_series.ref b/seminaries/qtrvsim/fibo-hazards/fibo_series.ref new file mode 100644 index 0000000000000000000000000000000000000000..eb32d95396c3cd8e27741a18e4efb92f54f92e5e --- /dev/null +++ b/seminaries/qtrvsim/fibo-hazards/fibo_series.ref @@ -0,0 +1,13 @@ +0x00000000 +0x00000001 +0x00000001 +0x00000002 +0x00000003 +0x00000005 +0x00000008 +0x0000000d +0x00000015 +0x00000022 +0x00000037 +0x00000059 +0x00000000