diff --git a/seminaries/qtmips/fibo-hazards/.gitignore b/seminaries/qtmips/fibo-hazards/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..8b8d27c61d41913654ad945bf2867cb504914253 --- /dev/null +++ b/seminaries/qtmips/fibo-hazards/.gitignore @@ -0,0 +1,7 @@ +*.o +depend +fibo-hazards +fibo_limit.in +fibo_series.out + + diff --git a/seminaries/qtmips/fibo-hazards/Makefile b/seminaries/qtmips/fibo-hazards/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..9e01d31a0aa4d7501d8fa322ae1b1f193c5530b6 --- /dev/null +++ b/seminaries/qtmips/fibo-hazards/Makefile @@ -0,0 +1,89 @@ +ARCH=mips-elf +#ARCH=mips-linux-gnu + +SOURCES = fibo-hazards.S +TARGET_EXE = fibo-hazards + +CC=$(ARCH)-gcc +CXX=$(ARCH)-g++ +AS=$(ARCH)-as +LD=$(ARCH)-ld +OBJCOPY=$(ARCH)-objcopy + +ARCHFLAGS += -march=mips32 +#ARCHFLAGS += -fno-lto +#ARCHFLAGS += -mno-shared + +CFLAGS += -ggdb -Os -Wall +CXXFLAGS+= -ggdb -Os -Wall +AFLAGS += -ggdb +LDFLAGS += -ggdb +LDFLAGS += -nostartfiles +LDFLAGS += -static +#LDFLAGS += -specs=/opt/musl/mips-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 + +#mips-elf-objdump --source -M no-aliases,reg-names=numeric qtmips_binrep + +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 + qtmips_cli --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/qtmips/fibo-hazards/fibo-hazards-template.S b/seminaries/qtmips/fibo-hazards/fibo-hazards-template.S new file mode 100644 index 0000000000000000000000000000000000000000..95fe88d5bfabb90d0cc41883167b66975183c8eb --- /dev/null +++ b/seminaries/qtmips/fibo-hazards/fibo-hazards-template.S @@ -0,0 +1,66 @@ +// 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 + +.set noreorder +.set noat + +.globl fibo_limit +.globl fibo_series + +.text +.globl _start +.ent _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: + cache 9, 0($0) // flush cache memory + break // stop the simulator + j end_loop + nop + +.end _start + +.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/qtmips/fibo-hazards/fibo_series.ref b/seminaries/qtmips/fibo-hazards/fibo_series.ref new file mode 100644 index 0000000000000000000000000000000000000000..eb32d95396c3cd8e27741a18e4efb92f54f92e5e --- /dev/null +++ b/seminaries/qtmips/fibo-hazards/fibo_series.ref @@ -0,0 +1,13 @@ +0x00000000 +0x00000001 +0x00000001 +0x00000002 +0x00000003 +0x00000005 +0x00000008 +0x0000000d +0x00000015 +0x00000022 +0x00000037 +0x00000059 +0x00000000