diff options
Diffstat (limited to 'test/mppa')
95 files changed, 1541 insertions, 0 deletions
diff --git a/test/mppa/.gitignore b/test/mppa/.gitignore new file mode 100644 index 00000000..e8ebeff8 --- /dev/null +++ b/test/mppa/.gitignore @@ -0,0 +1,20 @@ +check +asm_coverage +instr/Makefile +mmult/Makefile +prng/Makefile +sort/Makefile +prng/.zero +sort/.zero +sort/insertion-ccomp-k1c +sort/insertion-gcc-k1c +sort/insertion-gcc-x86 +sort/main-ccomp-k1c +sort/main-gcc-k1c +sort/main-gcc-x86 +sort/merge-ccomp-k1c +sort/merge-gcc-k1c +sort/merge-gcc-x86 +sort/selection-ccomp-k1c +sort/selection-gcc-k1c +sort/selection-gcc-x86 diff --git a/test/mppa/asm_coverage b/test/mppa/asm_coverage new file mode 160000 +Subproject a9c62b61552a9e9fd0ebf43df5ee0d5b88bb094 diff --git a/test/mppa/builtins/clzll.c b/test/mppa/builtins/clzll.c new file mode 100644 index 00000000..13905cba --- /dev/null +++ b/test/mppa/builtins/clzll.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = __builtin_clzll(a); +} +END_TEST() diff --git a/test/mppa/builtins/stsud.c b/test/mppa/builtins/stsud.c new file mode 100644 index 00000000..fb07b94f --- /dev/null +++ b/test/mppa/builtins/stsud.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST_N(unsigned long long, 2) +{ + c = __builtin_k1_stsud(t[0], t[1]); +} +END_TEST() diff --git a/test/mppa/check.sh b/test/mppa/check.sh new file mode 100755 index 00000000..8db50f1b --- /dev/null +++ b/test/mppa/check.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# Tests the execution of the binaries produced by CompCert + +source do_test.sh + +do_test check diff --git a/test/mppa/coverage.sh b/test/mppa/coverage.sh new file mode 100644 index 00000000..0a057ff9 --- /dev/null +++ b/test/mppa/coverage.sh @@ -0,0 +1,17 @@ +asmdir=$1 +to_cover_raw=/tmp/to_cover_raw +to_cover=/tmp/to_cover +covered_raw=/tmp/covered_raw +covered=/tmp/covered + +sed -n "s/^.*fprintf oc \" \(.*\) .*/\1/p" ../../mppa_k1c/TargetPrinter.ml > $to_cover_raw +sed -n "s/^.*fprintf oc \" \(.*\)\\n.*/\1/p" ../../mppa_k1c/TargetPrinter.ml >> $to_cover_raw +python2.7 coverage_helper.py $to_cover_raw > $to_cover + +rm -f $covered_raw +for asm in $(ls $asmdir/*.s); do + bash asm_coverage/asm-coverage.sh $asm >> $covered_raw +done +python2.7 coverage_helper.py $covered_raw > $covered + +vimdiff $to_cover $covered diff --git a/test/mppa/coverage_helper.py b/test/mppa/coverage_helper.py new file mode 100644 index 00000000..b086aca9 --- /dev/null +++ b/test/mppa/coverage_helper.py @@ -0,0 +1,35 @@ +import fileinput + +occurs = {} + +for line in fileinput.input(): + line_noc = line.replace('\n', '') + if line_noc not in occurs: + occurs[line_noc] = 0 + occurs[line_noc] += 1 + +# HACK: Removing all the instructions with "%a", replacing them with all their variations +# Also removing all instructions starting with '.' +pruned_occurs = dict(occurs) +for inst in occurs: + if inst[0] == '.': + del pruned_occurs[inst] + if "%a" not in inst: + continue + inst_no_a = inst.replace(".%a", "") + if inst_no_a in ("compw", "compd"): + del pruned_occurs[inst] + for mod in ("ne", "eq", "lt", "gt", "le", "ge", "ltu", "leu", "geu", + "gtu", "all", "any", "nall", "none"): + pruned_occurs[inst_no_a + "." + mod] = 1 + elif inst_no_a in ("cb"): + del pruned_occurs[inst] + for mod in ("wnez", "weqz", "wltz", "wgez", "wlez", "wgtz", "deqz", "dnez", + "dltz", "dgez", "dlez", "dgtz"): + pruned_occurs[inst_no_a + "." + mod] = 1 + else: + assert False, "Found instruction with %a: " + inst +occurs = pruned_occurs + +for inst in sorted(occurs): + print inst diff --git a/test/mppa/do_test.sh b/test/mppa/do_test.sh new file mode 100644 index 00000000..ee7cbcf7 --- /dev/null +++ b/test/mppa/do_test.sh @@ -0,0 +1,33 @@ +do_test () { +cat << EOF + +## +# PRNG tests +## +EOF +(cd prng && make $1 -j8) + +cat << EOF + +## +# Matrix Multiplication tests +## +EOF +(cd mmult && make $1 -j8) + +cat << EOF + +## +# List sort tests +## +EOF +(cd sort && make $1 -j8) + +cat << EOF + +## +# Instruction unit tests +## +EOF +(cd instr && make $1 -j8) +} diff --git a/test/mppa/general/clzd.c b/test/mppa/general/clzd.c new file mode 100644 index 00000000..4bedab97 --- /dev/null +++ b/test/mppa/general/clzd.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST_N(unsigned long long, 1) +{ + c = __builtin_k1_clzd(t[0]); +} +END_TEST() diff --git a/test/mppa/general/clzw.c b/test/mppa/general/clzw.c new file mode 100644 index 00000000..361492f2 --- /dev/null +++ b/test/mppa/general/clzw.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST_N(unsigned long long, 1) +{ + c = __builtin_k1_clzw(t[0]); +} +END_TEST() diff --git a/test/mppa/general/ctzd.c b/test/mppa/general/ctzd.c new file mode 100644 index 00000000..6f6586ad --- /dev/null +++ b/test/mppa/general/ctzd.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST_N(unsigned long long, 1) +{ + c = __builtin_k1_ctzd(t[0]); +} +END_TEST() diff --git a/test/mppa/general/ctzw.c b/test/mppa/general/ctzw.c new file mode 100644 index 00000000..b0f2c937 --- /dev/null +++ b/test/mppa/general/ctzw.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST_N(unsigned long long, 1) +{ + c = __builtin_k1_ctzw(t[0]); +} +END_TEST() diff --git a/test/mppa/general/satd.c b/test/mppa/general/satd.c new file mode 100644 index 00000000..d8d0d256 --- /dev/null +++ b/test/mppa/general/satd.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST_N(unsigned long long, 2) +{ + c = __builtin_k1_satd(t[0], t[1]); +} +END_TEST() diff --git a/test/mppa/general/sbmm8.c b/test/mppa/general/sbmm8.c new file mode 100644 index 00000000..beced8fc --- /dev/null +++ b/test/mppa/general/sbmm8.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST_N(unsigned long long, 2) +{ + c = __builtin_k1_sbmm8(t[0], t[1]); +} +END_TEST() diff --git a/test/mppa/general/sbmmt8.c b/test/mppa/general/sbmmt8.c new file mode 100644 index 00000000..8a64e7e7 --- /dev/null +++ b/test/mppa/general/sbmmt8.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST_N(unsigned long long, 2) +{ + c = __builtin_k1_sbmmt8(t[0], t[1]); +} +END_TEST() diff --git a/test/mppa/instr/.gitignore b/test/mppa/instr/.gitignore new file mode 100644 index 00000000..ea1472ec --- /dev/null +++ b/test/mppa/instr/.gitignore @@ -0,0 +1 @@ +output/ diff --git a/test/mppa/instr/Makefile b/test/mppa/instr/Makefile new file mode 100644 index 00000000..89ff9a73 --- /dev/null +++ b/test/mppa/instr/Makefile @@ -0,0 +1,111 @@ +K1CC ?= k1-mbr-gcc +CC ?= gcc +CCOMP ?= ccomp +CFLAGS ?= -O2 +SIMU ?= k1-cluster +TIMEOUT ?= 10s + +DIR=./ +SRCDIR=$(DIR) +OUTDIR=$(DIR)/out +BINDIR=$(DIR)/bin +ASMDIR=$(DIR)/asm + +## +# Intended flow : .c -> .gcc.s -> .gcc.bin -> .gcc.out +# -> .ccomp.s -> .ccomp.bin -> .ccomp.out +## + +K1CCPATH=$(shell which $(K1CC)) +CCPATH=$(shell which $(CC)) +CCOMPPATH=$(shell which $(CCOMP)) +SIMUPATH=$(shell which $(SIMU)) + +TESTNAMES=$(notdir $(subst .c,,$(wildcard $(DIR)/*.c))) +X86_GCC_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .x86-gcc.out,$(TESTNAMES))) +GCC_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .gcc.out,$(TESTNAMES))) +CCOMP_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .ccomp.out,$(TESTNAMES))) + +OUT=$(X86_GCC_OUT) $(GCC_OUT) $(CCOMP_OUT) +BIN=$(addprefix $(BINDIR)/,$(addsuffix .x86-gcc.bin,$(TESTNAMES)))\ + $(addprefix $(BINDIR)/,$(addsuffix .gcc.bin,$(TESTNAMES)))\ + $(addprefix $(BINDIR)/,$(addsuffix .ccomp.bin,$(TESTNAMES))) + +## +# Targets +## + +all: $(BIN) + +.PHONY: +test: $(X86_GCC_OUT) $(GCC_OUT) + @echo "Comparing x86 gcc output to k1 gcc.." + @for test in $(TESTNAMES); do\ + x86out=$(OUTDIR)/$$test.x86-gcc.out;\ + gccout=$(OUTDIR)/$$test.gcc.out;\ + if ! diff $$x86out $$gccout; then\ + >&2 echo "ERROR: $$x86out and $$gccout differ";\ + else\ + echo "GOOD: $$x86out and $$gccout concur";\ + fi;\ + done + +.PHONY: +check: $(GCC_OUT) $(CCOMP_OUT) + @echo "Comparing k1 gcc output to ccomp.." + @for test in $(TESTNAMES); do\ + gccout=$(OUTDIR)/$$test.gcc.out;\ + ccompout=$(OUTDIR)/$$test.ccomp.out;\ + if ! diff $$ccompout $$gccout; then\ + >&2 echo "ERROR: $$ccompout and $$gccout differ";\ + else\ + echo "GOOD: $$ccompout and $$gccout concur";\ + fi;\ + done + +## +# Rules +## + +.SECONDARY: +# Generating output + +$(OUTDIR)/%.x86-gcc.out: $(BINDIR)/%.x86-gcc.bin + @mkdir -p $(@D) + ret=0; timeout $(TIMEOUT) ./$< > $@ || { ret=$$?; }; echo $$ret >> $@ + +$(OUTDIR)/%.gcc.out: $(BINDIR)/%.gcc.bin $(SIMUPATH) + @mkdir -p $(@D) + ret=0; timeout $(TIMEOUT) $(SIMU) -- $< > $@ || { ret=$$?; }; echo $$ret >> $@ + +$(OUTDIR)/%.ccomp.out: $(BINDIR)/%.ccomp.bin $(SIMUPATH) + @mkdir -p $(@D) + ret=0; timeout $(TIMEOUT) $(SIMU) -- $< > $@ || { ret=$$?; }; echo $$ret >> $@ + +# Assembly to binary + +$(BINDIR)/%.x86-gcc.bin: $(ASMDIR)/%.x86-gcc.s $(CCPATH) + @mkdir -p $(@D) + $(CC) $(CFLAGS) $< -o $@ + +$(BINDIR)/%.gcc.bin: $(ASMDIR)/%.gcc.s $(K1CCPATH) + @mkdir -p $(@D) + $(K1CC) $(CFLAGS) $< -o $@ + +$(BINDIR)/%.ccomp.bin: $(ASMDIR)/%.ccomp.s $(CCOMPPATH) + @mkdir -p $(@D) + $(CCOMP) $(CFLAGS) $< -o $@ + +# Source to assembly + +$(ASMDIR)/%.x86-gcc.s: $(SRCDIR)/%.c $(CCPATH) + @mkdir -p $(@D) + $(CC) $(CFLAGS) -S $< -o $@ + +$(ASMDIR)/%.gcc.s: $(SRCDIR)/%.c $(K1CCPATH) + @mkdir -p $(@D) + $(K1CC) $(CFLAGS) -S $< -o $@ + +$(ASMDIR)/%.ccomp.s: $(SRCDIR)/%.c $(CCOMPPATH) + @mkdir -p $(@D) + $(CCOMP) $(CFLAGS) -S $< -o $@ diff --git a/test/mppa/instr/addw.c b/test/mppa/instr/addw.c new file mode 100644 index 00000000..be8afc67 --- /dev/null +++ b/test/mppa/instr/addw.c @@ -0,0 +1,5 @@ +#include "framework.h" + +BEGIN_TEST(int) + c = a+b; +END_TEST() diff --git a/test/mppa/instr/andd.c b/test/mppa/instr/andd.c new file mode 100644 index 00000000..4f503764 --- /dev/null +++ b/test/mppa/instr/andd.c @@ -0,0 +1,5 @@ +#include "framework.h" + +BEGIN_TEST(long long) + return a&b; +END_TEST() diff --git a/test/mppa/instr/andw.c b/test/mppa/instr/andw.c new file mode 100644 index 00000000..99de0049 --- /dev/null +++ b/test/mppa/instr/andw.c @@ -0,0 +1,5 @@ +#include "framework.h" + +BEGIN_TEST(int) + c = a&b; +END_TEST() diff --git a/test/mppa/instr/branch.c b/test/mppa/instr/branch.c new file mode 100644 index 00000000..72e7e20e --- /dev/null +++ b/test/mppa/instr/branch.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + if ((a & 0x1) == 1) + c = 0; + else + c = 1; +} +END_TEST() diff --git a/test/mppa/instr/branchz.c b/test/mppa/instr/branchz.c new file mode 100644 index 00000000..fb86d357 --- /dev/null +++ b/test/mppa/instr/branchz.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + if (a & 0x1 == 0) + c = 0; + else + c = 1; +} +END_TEST() diff --git a/test/mppa/instr/branchzu.c b/test/mppa/instr/branchzu.c new file mode 100644 index 00000000..97adb605 --- /dev/null +++ b/test/mppa/instr/branchzu.c @@ -0,0 +1,11 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + b = !(a & 0x01); + if (!b) + c = 0; + else + c = 1; +} +END_TEST() diff --git a/test/mppa/instr/call.c b/test/mppa/instr/call.c new file mode 100644 index 00000000..727cef63 --- /dev/null +++ b/test/mppa/instr/call.c @@ -0,0 +1,16 @@ +#include "framework.h" + +int sum(int a, int b){ + return a+b; +} + +int make(int a){ + return a; +} + +BEGIN_TEST(int) +{ + c = sum(make(a), make(b)); +} +END_TEST() +/* RETURN VALUE: 60 */ diff --git a/test/mppa/instr/cb.deqz.c b/test/mppa/instr/cb.deqz.c new file mode 100644 index 00000000..c56733f0 --- /dev/null +++ b/test/mppa/instr/cb.deqz.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + if (0 != (a & 0x1LL)) + c = 1; + else + c = 0; +} +END_TEST() diff --git a/test/mppa/instr/cb.dgez.c b/test/mppa/instr/cb.dgez.c new file mode 100644 index 00000000..abb6ec57 --- /dev/null +++ b/test/mppa/instr/cb.dgez.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + if (0 > (a & 0x1LL)) + c = 1; + else + c = 0; +} +END_TEST() diff --git a/test/mppa/instr/cb.dgtz.c b/test/mppa/instr/cb.dgtz.c new file mode 100644 index 00000000..d4271845 --- /dev/null +++ b/test/mppa/instr/cb.dgtz.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + if (0 >= (a & 0x1LL) - 1) + c = 1; + else + c = 0; +} +END_TEST() diff --git a/test/mppa/instr/cb.dlez.c b/test/mppa/instr/cb.dlez.c new file mode 100644 index 00000000..18e67f06 --- /dev/null +++ b/test/mppa/instr/cb.dlez.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + if (a & 0x1LL > 0) + c = 1; + else + c = 0; +} +END_TEST() diff --git a/test/mppa/instr/cb.dltz.c b/test/mppa/instr/cb.dltz.c new file mode 100644 index 00000000..366aea49 --- /dev/null +++ b/test/mppa/instr/cb.dltz.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + if ((a & 0x1LL) - 1 >= 0) + c = 1; + else + c = 0; +} +END_TEST() diff --git a/test/mppa/instr/cb.dnez.c b/test/mppa/instr/cb.dnez.c new file mode 100644 index 00000000..81c2cd29 --- /dev/null +++ b/test/mppa/instr/cb.dnez.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + if (0 == (a & 0x1LL)) + c = 1; + else + c = 0; +} +END_TEST() diff --git a/test/mppa/instr/cb.wgez.c b/test/mppa/instr/cb.wgez.c new file mode 100644 index 00000000..477f4bc6 --- /dev/null +++ b/test/mppa/instr/cb.wgez.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + if (0 > (a & 0x1) - 1) + c = 1; + else + c = 0; +} +END_TEST() diff --git a/test/mppa/instr/cb.wgtz.c b/test/mppa/instr/cb.wgtz.c new file mode 100644 index 00000000..c9ab9a06 --- /dev/null +++ b/test/mppa/instr/cb.wgtz.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + if (0 >= (a & 0x1)) + c = 1; + else + c = 0; +} +END_TEST() diff --git a/test/mppa/instr/cb.wlez.c b/test/mppa/instr/cb.wlez.c new file mode 100644 index 00000000..c3069fda --- /dev/null +++ b/test/mppa/instr/cb.wlez.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + if ((a & 0x1) > 0) + c = 1; + else + c = 0; +} +END_TEST() diff --git a/test/mppa/instr/cb.wltz.c b/test/mppa/instr/cb.wltz.c new file mode 100644 index 00000000..6cf5fcf0 --- /dev/null +++ b/test/mppa/instr/cb.wltz.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + if ((a & 0x1) - 1 >= 0) + c = 1; + else + c = 0; +} +END_TEST() diff --git a/test/mppa/instr/compd.eq.c b/test/mppa/instr/compd.eq.c new file mode 100644 index 00000000..d19a4d20 --- /dev/null +++ b/test/mppa/instr/compd.eq.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = ((a & 0x1LL) == (b & 0x1LL)); +} +END_TEST() diff --git a/test/mppa/instr/compd.geu.c b/test/mppa/instr/compd.geu.c new file mode 100644 index 00000000..edc31183 --- /dev/null +++ b/test/mppa/instr/compd.geu.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = (a >= b); +} +END_TEST() diff --git a/test/mppa/instr/compd.gt.c b/test/mppa/instr/compd.gt.c new file mode 100644 index 00000000..24147779 --- /dev/null +++ b/test/mppa/instr/compd.gt.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = (a > b); +} +END_TEST() diff --git a/test/mppa/instr/compd.gtu.c b/test/mppa/instr/compd.gtu.c new file mode 100644 index 00000000..5ce82569 --- /dev/null +++ b/test/mppa/instr/compd.gtu.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = (a > b); +} +END_TEST() diff --git a/test/mppa/instr/compd.le.c b/test/mppa/instr/compd.le.c new file mode 100644 index 00000000..a84aad97 --- /dev/null +++ b/test/mppa/instr/compd.le.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = (a <= b); +} +END_TEST() diff --git a/test/mppa/instr/compd.leu.c b/test/mppa/instr/compd.leu.c new file mode 100644 index 00000000..e386bc27 --- /dev/null +++ b/test/mppa/instr/compd.leu.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = (a <= b); +} +END_TEST() diff --git a/test/mppa/instr/compd.lt.c b/test/mppa/instr/compd.lt.c new file mode 100644 index 00000000..df07a708 --- /dev/null +++ b/test/mppa/instr/compd.lt.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = (a < b); +} +END_TEST() diff --git a/test/mppa/instr/compd.ltu.c b/test/mppa/instr/compd.ltu.c new file mode 100644 index 00000000..dfaa8921 --- /dev/null +++ b/test/mppa/instr/compd.ltu.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = (a < b); +} +END_TEST() diff --git a/test/mppa/instr/compd.ne.c b/test/mppa/instr/compd.ne.c new file mode 100644 index 00000000..19ce0a69 --- /dev/null +++ b/test/mppa/instr/compd.ne.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = ((a & 0x1ULL) != (b & 0x1ULL)); +} +END_TEST() diff --git a/test/mppa/instr/compw.eq.c b/test/mppa/instr/compw.eq.c new file mode 100644 index 00000000..dc7a3ab1 --- /dev/null +++ b/test/mppa/instr/compw.eq.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + c = ((a & 0x1) == (b & 0x1)); +} +END_TEST() diff --git a/test/mppa/instr/compw.geu.c b/test/mppa/instr/compw.geu.c new file mode 100644 index 00000000..d72ca56c --- /dev/null +++ b/test/mppa/instr/compw.geu.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned int) +{ + c = (a >= b); +} +END_TEST() diff --git a/test/mppa/instr/compw.gt.c b/test/mppa/instr/compw.gt.c new file mode 100644 index 00000000..9ad02610 --- /dev/null +++ b/test/mppa/instr/compw.gt.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + c = (a > b); +} +END_TEST() diff --git a/test/mppa/instr/compw.gtu.c b/test/mppa/instr/compw.gtu.c new file mode 100644 index 00000000..77f04989 --- /dev/null +++ b/test/mppa/instr/compw.gtu.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned int) +{ + c = (a > b); +} +END_TEST() diff --git a/test/mppa/instr/compw.le.c b/test/mppa/instr/compw.le.c new file mode 100644 index 00000000..b7a7a432 --- /dev/null +++ b/test/mppa/instr/compw.le.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + c = (a <= b); +} +END_TEST() diff --git a/test/mppa/instr/compw.leu.c b/test/mppa/instr/compw.leu.c new file mode 100644 index 00000000..4892f06c --- /dev/null +++ b/test/mppa/instr/compw.leu.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned int) +{ + c = (a <= b); +} +END_TEST() diff --git a/test/mppa/instr/compw.lt.c b/test/mppa/instr/compw.lt.c new file mode 100644 index 00000000..2cc151bf --- /dev/null +++ b/test/mppa/instr/compw.lt.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + c = (a < b); +} +END_TEST() diff --git a/test/mppa/instr/compw.ltu.c b/test/mppa/instr/compw.ltu.c new file mode 100644 index 00000000..b524127f --- /dev/null +++ b/test/mppa/instr/compw.ltu.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned int) +{ + c = (a < b); +} +END_TEST() diff --git a/test/mppa/instr/compw.ne.c b/test/mppa/instr/compw.ne.c new file mode 100644 index 00000000..433b0b86 --- /dev/null +++ b/test/mppa/instr/compw.ne.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned int) +{ + c = ((a & 0x1U) != (b & 0x1U)); +} +END_TEST() diff --git a/test/mppa/instr/div2.c b/test/mppa/instr/div2.c new file mode 100644 index 00000000..01a4b575 --- /dev/null +++ b/test/mppa/instr/div2.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + c = (a + b) / 2; +} +END_TEST() diff --git a/test/mppa/instr/for.c b/test/mppa/instr/for.c new file mode 100644 index 00000000..d6870afb --- /dev/null +++ b/test/mppa/instr/for.c @@ -0,0 +1,9 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + int j; + for (j = 0 ; j < 10 ; j++) + c += a; +} +END_TEST() diff --git a/test/mppa/instr/forvar.c b/test/mppa/instr/forvar.c new file mode 100644 index 00000000..57548274 --- /dev/null +++ b/test/mppa/instr/forvar.c @@ -0,0 +1,9 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + int j; + for (j = 0 ; j < (b & 0x8) ; j++) + c += a; +} +END_TEST() diff --git a/test/mppa/instr/forvarl.c b/test/mppa/instr/forvarl.c new file mode 100644 index 00000000..30717a51 --- /dev/null +++ b/test/mppa/instr/forvarl.c @@ -0,0 +1,10 @@ +#include "framework.h" + +BEGIN_TEST(long long int) +{ + int j; + + for (j = 0 ; j < (b & 0x8LL) ; j++) + c += a; +} +END_TEST() diff --git a/test/mppa/instr/framework.h b/test/mppa/instr/framework.h new file mode 100644 index 00000000..52ba97bc --- /dev/null +++ b/test/mppa/instr/framework.h @@ -0,0 +1,37 @@ +#ifndef __FRAMEWORK_H__ +#define __FRAMEWORK_H__ + +#include "../prng/prng.c" + +#define BEGIN_TEST_N(type, N)\ + int main(void){\ + type t[N], c, i, j, S;\ + srand(0);\ + S = 0;\ + for (i = 0 ; i < 100 ; i++){\ + c = randlong();\ + for (j = 0 ; j < N ; j++)\ + t[j] = randlong();\ + /* END BEGIN_TEST_N */ + +#define BEGIN_TEST(type)\ + int main(void){\ + type a, b, c, i, S;\ + srand(0);\ + S = 0;\ + for (i = 0 ; i < 100 ; i++){\ + c = randlong();\ + a = randlong();\ + b = randlong(); + /* END BEGIN_TEST */ + +/* In between BEGIN_TEST and END_TEST : definition of c */ + +#define END_TEST()\ + S += c;\ + }\ + return S;\ + } + /* END END_TEST */ + +#endif diff --git a/test/mppa/instr/lbs.c b/test/mppa/instr/lbs.c new file mode 100644 index 00000000..f104d62b --- /dev/null +++ b/test/mppa/instr/lbs.c @@ -0,0 +1,9 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + char s[] = "Tome and Cherry at the playa\n"; + + c = s[(a & (sizeof(s)-1))]; +} +END_TEST() diff --git a/test/mppa/instr/lbz.c b/test/mppa/instr/lbz.c new file mode 100644 index 00000000..2deeaebe --- /dev/null +++ b/test/mppa/instr/lbz.c @@ -0,0 +1,9 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + unsigned char s[] = "Tim is sorry at the playa\n"; + + c = s[a & (sizeof(s) - 1)]; +} +END_TEST() diff --git a/test/mppa/instr/muld.c b/test/mppa/instr/muld.c new file mode 100644 index 00000000..9a40f389 --- /dev/null +++ b/test/mppa/instr/muld.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = a*b; +} +END_TEST() diff --git a/test/mppa/instr/mulw.c b/test/mppa/instr/mulw.c new file mode 100644 index 00000000..bf517ce8 --- /dev/null +++ b/test/mppa/instr/mulw.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + c = a * b; +} +END_TEST() diff --git a/test/mppa/instr/negd.c b/test/mppa/instr/negd.c new file mode 100644 index 00000000..a8e8ff45 --- /dev/null +++ b/test/mppa/instr/negd.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = -a; +} +END_TEST() diff --git a/test/mppa/instr/ord.c b/test/mppa/instr/ord.c new file mode 100644 index 00000000..eaedcb28 --- /dev/null +++ b/test/mppa/instr/ord.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = a | b; +} +END_TEST() diff --git a/test/mppa/instr/sbfd.c b/test/mppa/instr/sbfd.c new file mode 100644 index 00000000..912f1fdb --- /dev/null +++ b/test/mppa/instr/sbfd.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = a-b; +} +END_TEST() diff --git a/test/mppa/instr/sbfw.c b/test/mppa/instr/sbfw.c new file mode 100644 index 00000000..feffd497 --- /dev/null +++ b/test/mppa/instr/sbfw.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + c = a-b; +} +END_TEST() diff --git a/test/mppa/instr/simple.c b/test/mppa/instr/simple.c new file mode 100644 index 00000000..89bba27e --- /dev/null +++ b/test/mppa/instr/simple.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + c = a+b; +} +END_TEST() diff --git a/test/mppa/instr/sllw.c b/test/mppa/instr/sllw.c new file mode 100644 index 00000000..df55c9e8 --- /dev/null +++ b/test/mppa/instr/sllw.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + c = a << (b & 0x8); +} +END_TEST() diff --git a/test/mppa/instr/srad.c b/test/mppa/instr/srad.c new file mode 100644 index 00000000..b4047bc7 --- /dev/null +++ b/test/mppa/instr/srad.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = a >> (b & 0x8LL); +} +END_TEST() diff --git a/test/mppa/instr/srld.c b/test/mppa/instr/srld.c new file mode 100644 index 00000000..71e82b2a --- /dev/null +++ b/test/mppa/instr/srld.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = a >> (b & 0x8ULL); +} +END_TEST() diff --git a/test/mppa/instr/udivd.c b/test/mppa/instr/udivd.c new file mode 100644 index 00000000..52e0d412 --- /dev/null +++ b/test/mppa/instr/udivd.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = a/b; +} +END_TEST() diff --git a/test/mppa/instr/umodd.c b/test/mppa/instr/umodd.c new file mode 100644 index 00000000..e7dd506f --- /dev/null +++ b/test/mppa/instr/umodd.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = a%b; +} +END_TEST() diff --git a/test/mppa/instr/xord.c b/test/mppa/instr/xord.c new file mode 100644 index 00000000..b9d86f06 --- /dev/null +++ b/test/mppa/instr/xord.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = a^b; +} +END_TEST() diff --git a/test/mppa/mmult/.gitignore b/test/mppa/mmult/.gitignore new file mode 100644 index 00000000..c9cd4c65 --- /dev/null +++ b/test/mppa/mmult/.gitignore @@ -0,0 +1,4 @@ +mmult-test-ccomp-k1c +mmult-test-gcc-k1c +mmult-test-gcc-x86 +.zero diff --git a/test/mppa/mmult/Makefile b/test/mppa/mmult/Makefile new file mode 100644 index 00000000..cf82e359 --- /dev/null +++ b/test/mppa/mmult/Makefile @@ -0,0 +1,67 @@ +K1CC ?= k1-mbr-gcc +CC ?= gcc +CCOMP ?= ccomp +CFLAGS ?= -O2 +SIMU ?= k1-cluster +TIMEOUT ?= 10s + +K1CCPATH=$(shell which $(K1CC)) +CCPATH=$(shell which $(CC)) +CCOMPPATH=$(shell which $(CCOMP)) +SIMUPATH=$(shell which $(SIMU)) + +PRNG=../prng/prng.c + +ALL= mmult-test-gcc-x86 mmult-test-gcc-k1c mmult-test-ccomp-k1c +CCOMP_OUT= mmult-test-ccomp-k1c.out +GCC_OUT= mmult-test-gcc-k1c.out +X86_GCC_OUT= mmult-test-gcc-x86.out +STUB_OUT=.zero + +all: $(ALL) + +mmult-test-gcc-x86: mmult.c $(PRNG) $(CCPATH) + $(CC) $(CFLAGS) $(filter-out $(CCPATH),$^) -o $@ + +mmult-test-gcc-k1c: mmult.c $(PRNG) $(K1CCPATH) + $(K1CC) $(CFLAGS) $(filter-out $(K1CCPATH),$^) -o $@ + +mmult-test-ccomp-k1c: mmult.c $(PRNG) $(CCOMPPATH) + $(CCOMP) $(CFLAGS) $(filter-out $(CCOMPPATH),$^) -o $@ + +.SECONDARY: +%k1c.out: %k1c $(SIMUPATH) + ret=0; timeout $(TIMEOUT) $(SIMU) -- $< > $@ || { ret=$$?; }; echo $$ret >> $@ + +%x86.out: %x86 + ret=0; timeout $(TIMEOUT) ./$< > $@ || { ret=$$?; }; echo $$ret >> $@ + +.zero: + @echo "0" > $@ + +.PHONY: +test: test-x86 test-k1c + +.PHONY: +test-x86: $(X86_GCC_OUT) $(STUB_OUT) + @if ! diff $< $(STUB_OUT); then\ + >&2 echo "ERROR x86: $< failed";\ + else\ + echo "GOOD x86: $< succeeded";\ + fi + +.PHONY: +test-k1c: $(GCC_OUT) $(STUB_OUT) + @if ! diff $< $(STUB_OUT); then\ + >&2 echo "ERROR k1c: $< failed";\ + else\ + echo "GOOD k1c: $< succeeded";\ + fi + +.PHONY: +check: $(CCOMP_OUT) $(STUB_OUT) + @if ! diff $< $(STUB_OUT); then\ + >&2 echo "ERROR k1c: $< failed";\ + else\ + echo "GOOD k1c: $< succeeded";\ + fi diff --git a/test/mppa/mmult/README.md b/test/mppa/mmult/README.md new file mode 100644 index 00000000..ef2bff7e --- /dev/null +++ b/test/mppa/mmult/README.md @@ -0,0 +1,17 @@ +MMULT +===== + +Examples of matrix multiplication using different methods. + +We compute matrix multiplication using column-based matrix multiplication, then row-based, and finally block based. + +The test verifies that the result is the same on the three methods. If it is the same, 0 will be returned. + +The following commands can be run inside the folder: + +- `make`: produces the unitary test binaries + - `mmult-test-gcc-x86` : binary from gcc on x86 + - `mmult-test-k1c-x86` : binary from gcc on k1c + - `mmult-test-ccomp-x86` : binary from ccomp on k1c +- `make test`: tests the return value of the binaries produced by gcc. +- `make check`: tests the return value of the binary produced by CompCert. diff --git a/test/mppa/mmult/mmult.c b/test/mppa/mmult/mmult.c new file mode 100644 index 00000000..aeb91d48 --- /dev/null +++ b/test/mppa/mmult/mmult.c @@ -0,0 +1,146 @@ +#include "../prng/types.h" +#include "../prng/prng.h" + +#define __UNIT_TEST_MMULT__ + +#ifdef __UNIT_TEST_MMULT__ +#define SIZE 10 +#else +#include "test.h" +#endif + +void mmult_row(uint64_t C[][SIZE], uint64_t A[][SIZE], uint64_t B[][SIZE]){ + int i, j, k; + + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++) + C[i][j] = 0; + + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++) + for (k = 0 ; k < SIZE ; k++) + C[i][j] += A[i][k] * B[k][j]; +} + +void mmult_col(uint64_t C[][SIZE], uint64_t A[][SIZE], uint64_t B[][SIZE]){ + int i, j, k; + + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++) + C[i][j] = 0; + + for (k = 0 ; k < SIZE ; k++) + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++) + C[i][j] += A[i][k] * B[k][j]; +} + +typedef struct mblock { + int imin, imax, jmin, jmax; + uint64_t *mat; +} mblock; + +#define MAT_XY(mat, x, y) (mat)[(x)*SIZE + (y)] +#define MAT_IJ(block, i, j) MAT_XY((block)->mat, (block)->imin + (i), block->jmin + (j)) + +void divac_mul(mblock *C, const mblock *A, const mblock *B){ + const int size = C->imax - C->imin; + int i, j, k; + + for (i = 0 ; i < size ; i++) + for (j = 0 ; j < size ; j++) + for (k = 0 ; k < size ; k++) + MAT_IJ(C, i, j) += MAT_IJ(A, i, k) * MAT_IJ(B, k, j); +} + +#define BLOCK_X_MID(block) ((block)->imin + (block)->imax) / 2 +#define BLOCK_Y_MID(block) ((block)->jmin + (block)->jmax) / 2 + +#define MAKE_MBLOCK(newb, block, I, J) \ + mblock newb = {.mat=(block)->mat};\ + if ((I) == 0){\ + newb.imin = (block)->imin;\ + newb.imax = BLOCK_X_MID((block));\ + } else {\ + newb.imin = BLOCK_X_MID((block));\ + newb.imax = (block)->imax;\ + } if ((J) == 0){\ + newb.jmin = (block)->jmin;\ + newb.jmax = BLOCK_Y_MID((block));\ + } else {\ + newb.jmin = BLOCK_Y_MID((block));\ + newb.jmax = (block)->jmax;\ + } + +void divac_part(mblock *C, const mblock *A, const mblock *B); + +void divac_wrap(mblock *C , char IC, char JC, + const mblock *A, char IA, char JA, + const mblock *B, char IB, char JB){ + MAKE_MBLOCK(Cb, C, IC, JC); + MAKE_MBLOCK(Ab, A, IA, JA); + MAKE_MBLOCK(Bb, B, IB, JB); + + divac_part(&Cb, &Ab, &Bb); +} + + +void divac_part(mblock *C, const mblock *A, const mblock *B){ + const int size = C->imax - C->imin; + + if (size % 2 == 1) + divac_mul(C, A, B); + else{ + /* C_00 = A_00 B_00 + A_01 B_10 */ + divac_wrap(C, 0, 0, A, 0, 0, B, 0, 0); + divac_wrap(C, 0, 0, A, 0, 1, B, 1, 0); + + /* C_10 = A_10 B_00 + A_11 B_10 */ + divac_wrap(C, 1, 0, A, 1, 0, B, 0, 0); + divac_wrap(C, 1, 0, A, 1, 1, B, 1, 0); + + /* C_01 = A_00 B_01 + A_01 B_11 */ + divac_wrap(C, 0, 1, A, 0, 0, B, 0, 1); + divac_wrap(C, 0, 1, A, 0, 1, B, 1, 1); + + /* C_11 = A_10 B_01 + A_11 B_11 */ + divac_wrap(C, 1, 1, A, 1, 0, B, 0, 1); + divac_wrap(C, 1, 1, A, 1, 1, B, 1, 1); + } + +} + +void mmult_divac(uint64_t C[][SIZE], uint64_t A[][SIZE], uint64_t B[][SIZE]){ + mblock Cb = {.mat = (uint64_t *) C, .imin = 0, .imax = SIZE, .jmin = 0, .jmax = SIZE}; + mblock Ab = {.mat = (uint64_t *) A , .imin = 0, .imax = SIZE, .jmin = 0, .jmax = SIZE}; + mblock Bb = {.mat = (uint64_t *) B , .imin = 0, .imax = SIZE, .jmin = 0, .jmax = SIZE}; + + divac_part(&Cb, &Ab, &Bb); +} + +#ifdef __UNIT_TEST_MMULT__ +static uint64_t C1[SIZE][SIZE], C2[SIZE][SIZE], C3[SIZE][SIZE]; +static uint64_t A[SIZE][SIZE], B[SIZE][SIZE]; + +int main(void){ + srand(42); + int i, j; + + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++){ + A[i][j] = randlong(); + B[i][j] = randlong(); + } + + mmult_row(C1, A, B); + mmult_col(C2, A, B); + mmult_divac(C3, A, B); + + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++) + if (!(C1[i][j] == C2[i][j] && C1[i][j] == C3[i][j])) + return -1; + + return 0; +} +#endif /* __UNIT_TEST_MMULT__ */ diff --git a/test/mppa/mmult/mmult.h b/test/mppa/mmult/mmult.h new file mode 100644 index 00000000..3721784a --- /dev/null +++ b/test/mppa/mmult/mmult.h @@ -0,0 +1,10 @@ +#ifndef __MMULT_H__ +#define __MMULT_H__ + +#include "../lib/types.h" + +void mmult_row(uint64_t *A, const uint64_t *B, const uint64_t *C); +void mmult_column(uint64_t *A, const uint64_t *B, const uint64_t *C); +void mmult_strassen(uint64_t *A, const uint64_t *B, const uint64_t *C); + +#endif /* __MMULT_H__ */ diff --git a/test/mppa/prng/.gitignore b/test/mppa/prng/.gitignore new file mode 100644 index 00000000..0792a78b --- /dev/null +++ b/test/mppa/prng/.gitignore @@ -0,0 +1,3 @@ +prng-test-ccomp-k1c +prng-test-gcc-x86 +prng-test-gcc-k1c diff --git a/test/mppa/prng/Makefile b/test/mppa/prng/Makefile new file mode 100644 index 00000000..5580cd8e --- /dev/null +++ b/test/mppa/prng/Makefile @@ -0,0 +1,69 @@ +K1CC ?= k1-mbr-gcc +CC ?= gcc +CCOMP ?= ccomp +CFLAGS ?= -O2 +SIMU ?= k1-cluster +TIMEOUT ?= 10s + +K1CCPATH=$(shell which $(K1CC)) +CCPATH=$(shell which $(CC)) +CCOMPPATH=$(shell which $(CCOMP)) +SIMUPATH=$(shell which $(SIMU)) + +ALL= prng-test-gcc-x86 prng-test-gcc-k1c prng-test-ccomp-k1c +CCOMP_OUT= prng-test-ccomp-k1c.out +GCC_OUT= prng-test-gcc-k1c.out +X86_GCC_OUT= prng-test-gcc-x86.out +STUB_OUT=.zero + +all: $(ALL) + +prng-test-gcc-x86: prng.c $(CCPATH) + $(CC) -D__UNIT_TEST_PRNG__ $(CFLAGS) $< -o $@ + +prng-test-gcc-k1c: prng.c $(K1CCPATH) + $(K1CC) -D__UNIT_TEST_PRNG__ $(CFLAGS) $< -o $@ + +prng-test-ccomp-k1c: prng.c $(CCOMPPATH) + $(CCOMP) -D__UNIT_TEST_PRNG__ $(CFLAGS) $< -o $@ + +.SECONDARY: +%k1c.out: %k1c $(SIMUPATH) + ret=0; timeout $(TIMEOUT) $(SIMU) -- $< > $@ || { ret=$$?; }; echo $$ret >> $@ + +%x86.out: %x86 + ret=0; timeout $(TIMEOUT) ./$< > $@ || { ret=$$?; }; echo $$ret >> $@ + +.zero: + @echo "0" > $@ + +.PHONY: +test: test-x86 test-k1c + +.PHONY: +test-x86: $(X86_GCC_OUT) $(STUB_OUT) + @if ! diff $< $(STUB_OUT); then\ + >&2 echo "ERROR x86: $< failed";\ + else\ + echo "GOOD x86: $< succeeded";\ + fi + +.PHONY: +test-k1c: $(GCC_OUT) $(STUB_OUT) + @if ! diff $< $(STUB_OUT); then\ + >&2 echo "ERROR k1c: $< failed";\ + else\ + echo "GOOD k1c: $< succeeded";\ + fi + +.PHONY: +check: $(CCOMP_OUT) $(STUB_OUT) + @if ! diff $< $(STUB_OUT); then\ + >&2 echo "ERROR k1c: $< failed";\ + else\ + echo "GOOD k1c: $< succeeded";\ + fi + +.PHONY: +clean: + rm -f prng-test-gcc-x86 prng-test-gcc-k1c prng-test-ccomp-k1c diff --git a/test/mppa/prng/README.md b/test/mppa/prng/README.md new file mode 100644 index 00000000..b4c2279b --- /dev/null +++ b/test/mppa/prng/README.md @@ -0,0 +1,17 @@ +PRNG +==== + +This is a simple Pseudo Random Number Generator. + +`prng.c` contains a simple unitary test that compares the sum of the "bytewise sum" +of 1000 generated numbers to a hardcoded result, that is the one obtained with +`gcc -O2` on a x86 processor, and returns 0 if the result is correct. + +The following commands can be run inside that folder: + +- `make`: produces the unitary test binaries + - `prng-test-gcc-x86` : binary from gcc on x86 + - `prng-test-k1c-x86` : binary from gcc on k1c + - `prng-test-ccomp-x86` : binary from ccomp on k1c +- `make test`: tests the return value of the binaries produced by gcc. +- `make check`: tests the return value of the binary produced by CompCert. diff --git a/test/mppa/prng/prng.c b/test/mppa/prng/prng.c new file mode 100644 index 00000000..71de1dc3 --- /dev/null +++ b/test/mppa/prng/prng.c @@ -0,0 +1,41 @@ +// https://en.wikipedia.org/wiki/Linear_congruential_generator -> MMIX Donald Knuth +// modulo 2^64 = no need to do it explicitly + +#include "types.h" + +#define MULTIPLIER 6364136223846793005LL +#define INCREMENT 1442695040888963407LL + +static uint64_t current; + +void srand(uint64_t seed){ + current = seed; +} + +uint64_t randlong(void){ + return (current = MULTIPLIER * current + INCREMENT); +} + +#ifdef __UNIT_TEST_PRNG__ +char bytewise_sum(uint64_t to_check){ + char sum = 0; + int i; + + for (i = 0 ; i < 8 ; i++) + sum += (to_check & (uint64_t)(0xFFULL << i*8)) >> i*8; + + return sum; +} + +int main(void){ + srand(42); + int i; + + for (i = 0 ; i < 1000 ; i++) + randlong(); + + uint64_t last = randlong(); + + return !((unsigned char)bytewise_sum(last) == 155); +} +#endif // __UNIT_TEST_PRNG__ diff --git a/test/mppa/prng/prng.h b/test/mppa/prng/prng.h new file mode 100644 index 00000000..6abdb45a --- /dev/null +++ b/test/mppa/prng/prng.h @@ -0,0 +1,10 @@ +#ifndef __PRNG_H__ +#define __PRNG_H__ + +#include "types.h" + +void srand(uint64_t seed); + +uint64_t randlong(void); + +#endif // __PRNG_H__ diff --git a/test/mppa/prng/types.h b/test/mppa/prng/types.h new file mode 100644 index 00000000..584023e3 --- /dev/null +++ b/test/mppa/prng/types.h @@ -0,0 +1,7 @@ +#ifndef __TYPES_H__ +#define __TYPES_H__ + +#define uint64_t unsigned long long +#define int64_t signed long long + +#endif // __TYPES_H__ diff --git a/test/mppa/sort/.gitignore b/test/mppa/sort/.gitignore new file mode 100644 index 00000000..a8d6921c --- /dev/null +++ b/test/mppa/sort/.gitignore @@ -0,0 +1,9 @@ +main-test-ccomp-k1c +main-test-gcc-k1c +main-test-gcc-x86 +merge-test-gcc-k1c +merge-test-gcc-x86 +selection-test-gcc-k1c +selection-test-gcc-x86 +insertion-test-gcc-k1c +insertion-test-gcc-x86 diff --git a/test/mppa/sort/Makefile b/test/mppa/sort/Makefile new file mode 100644 index 00000000..ebbad5b5 --- /dev/null +++ b/test/mppa/sort/Makefile @@ -0,0 +1,91 @@ +K1CC ?= k1-mbr-gcc +CC ?= gcc +CCOMP ?= ccomp +CFLAGS ?= -O2 +SIMU ?= k1-cluster +TIMEOUT ?= 10s + +K1CCPATH=$(shell which $(K1CC)) +CCPATH=$(shell which $(CC)) +CCOMPPATH=$(shell which $(CCOMP)) +SIMUPATH=$(shell which $(SIMU)) + +PRNG=../prng/prng.c + +CFILES=insertion.c merge.c selection.c main.c + +ALL= insertion-gcc-x86 insertion-gcc-k1c insertion-ccomp-k1c\ + selection-gcc-x86 selection-gcc-k1c selection-ccomp-k1c\ + merge-gcc-x86 merge-gcc-k1c merge-ccomp-k1c\ + main-gcc-x86 main-gcc-k1c main-ccomp-k1c + +CCOMP_OUT= insertion-ccomp-k1c.out selection-ccomp-k1c.out merge-ccomp-k1c.out\ + main-ccomp-k1c.out +GCC_OUT= insertion-gcc-k1c.out selection-gcc-k1c.out merge-gcc-k1c.out\ + main-gcc-k1c.out +X86_GCC_OUT= insertion-gcc-x86.out selection-gcc-x86.out merge-gcc-x86.out\ + main-gcc-x86.out +STUB_OUT= .zero + +all: $(ALL) + +main-gcc-x86: $(CFILES) $(PRNG) $(CCPATH) + $(CC) $(CFLAGS) $(filter-out $(CCPATH),$^) -o $@ + +%-gcc-x86: %.c $(PRNG) $(CCPATH) + $(CC) -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ $(CFLAGS) $(filter-out $(CCPATH),$^) -o $@ + +main-gcc-k1c: $(CFILES) $(PRNG) $(CCPATH) + $(K1CC) $(CFLAGS) $(filter-out $(CCPATH),$^) -o $@ + +%-gcc-k1c: %.c $(PRNG) $(K1CCPATH) + $(K1CC) -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ $(CFLAGS) $(filter-out $(K1CCPATH),$^) -o $@ + +main-ccomp-k1c: $(CFILES) $(PRNG) $(CCOMPPATH) + $(CCOMP) $(CFLAGS) $(filter-out $(CCOMPPATH),$^) -o $@ + +%-ccomp-k1c: %.c $(PRNG) $(CCOMPPATH) + $(CCOMP) -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ $(CFLAGS) $(filter-out $(CCOMPPATH),$^) -o $@ + +.SECONDARY: +%x86.out: %x86 + ret=0; timeout $(TIMEOUT) ./$< > $@ || { ret=$$?; }; echo $$ret >> $@ + +%k1c.out: %k1c $(SIMUPATH) + ret=0; timeout $(TIMEOUT) $(SIMU) -- $< > $@ || { ret=$$?; }; echo $$ret >> $@ + +.zero: + @echo "0" > $@ + +.PHONY: +test-x86: $(STUB_OUT) $(X86_GCC_OUT) + @for test in $(wordlist 2,100,$^); do\ + if ! diff $$test $(STUB_OUT); then\ + >&2 echo "ERROR x86: $$test failed";\ + else\ + echo "GOOD x86: $$test succeeded";\ + fi;\ + done + +.PHONY: +test-k1c: $(STUB_OUT) $(GCC_OUT) + @for test in $(wordlist 2,100,$^); do\ + if ! diff $$test $(STUB_OUT); then\ + >&2 echo "ERROR k1c: $$test failed";\ + else\ + echo "GOOD k1c: $$test succeeded";\ + fi;\ + done + +.PHONY: +test: test-x86 test-k1c + +.PHONY: +check: $(STUB_OUT) $(CCOMP_OUT) + @for test in $(wordlist 2,100,$^); do\ + if ! diff $$test $(STUB_OUT); then\ + >&2 echo "ERROR k1c: $$test failed";\ + else\ + echo "GOOD k1c: $$test succeeded";\ + fi;\ + done diff --git a/test/mppa/sort/README.md b/test/mppa/sort/README.md new file mode 100644 index 00000000..b4c2279b --- /dev/null +++ b/test/mppa/sort/README.md @@ -0,0 +1,17 @@ +PRNG +==== + +This is a simple Pseudo Random Number Generator. + +`prng.c` contains a simple unitary test that compares the sum of the "bytewise sum" +of 1000 generated numbers to a hardcoded result, that is the one obtained with +`gcc -O2` on a x86 processor, and returns 0 if the result is correct. + +The following commands can be run inside that folder: + +- `make`: produces the unitary test binaries + - `prng-test-gcc-x86` : binary from gcc on x86 + - `prng-test-k1c-x86` : binary from gcc on k1c + - `prng-test-ccomp-x86` : binary from ccomp on k1c +- `make test`: tests the return value of the binaries produced by gcc. +- `make check`: tests the return value of the binary produced by CompCert. diff --git a/test/mppa/sort/insertion.c b/test/mppa/sort/insertion.c new file mode 100644 index 00000000..bca09599 --- /dev/null +++ b/test/mppa/sort/insertion.c @@ -0,0 +1,59 @@ +#include "../prng/prng.h" +#include "../prng/types.h" + +#ifdef __UNIT_TEST_INSERTION__ +#define SIZE 100 +#else +#include "test.h" +#endif + +void swap_ins(uint64_t *a, uint64_t *b){ + uint64_t tmp = *a; + *a = *b; + *b = tmp; +} + +int insert_sort(uint64_t *res, const uint64_t *T){ + int i, j; + + if (SIZE <= 0) + return -1; + + for (i = 0 ; i < SIZE ; i++) + res[i] = T[i]; + + for (i = 0 ; i < SIZE-1 ; i++){ + if (res[i] > res[i+1]){ + swap_ins(&res[i], &res[i+1]); + for (j = i ; j > 0 ; j--) + if (res[j-1] > res[j]) + swap_ins(&res[j-1], &res[j]); + } + } + + return 0; +} + +#ifdef __UNIT_TEST_INSERTION__ +int main(void){ + uint64_t T[SIZE]; + uint64_t res[SIZE]; + int i; + srand(42); + + for (i = 0 ; i < SIZE ; i++) + T[i] = randlong(); + + /* Sorting the table */ + if (insert_sort(res, T) < 0) return -1; + + /* Computing max(T) */ + uint64_t max = T[0]; + for (i = 1 ; i < SIZE ; i++) + if (T[i] > max) + max = T[i]; + + /* We should have: max(T) == res[SIZE] */ + return !(max == res[SIZE-1]); +} +#endif // __UNIT_TEST_INSERTION__ diff --git a/test/mppa/sort/insertion.h b/test/mppa/sort/insertion.h new file mode 100644 index 00000000..6e37c5fe --- /dev/null +++ b/test/mppa/sort/insertion.h @@ -0,0 +1,6 @@ +#ifndef __INSERTION_H__ +#define __INSERTION_H__ + +int insert_sort(uint64_t *res, const uint64_t *T); + +#endif // __INSERTION_H__ diff --git a/test/mppa/sort/main.c b/test/mppa/sort/main.c new file mode 100644 index 00000000..aef419aa --- /dev/null +++ b/test/mppa/sort/main.c @@ -0,0 +1,34 @@ +#include "../prng/prng.h" +#include "../prng/types.h" + +#include "test.h" +#include "insertion.h" +#include "selection.h" +#include "merge.h" + +int main(void){ + uint64_t T[SIZE]; + uint64_t res1[SIZE], res2[SIZE], res3[SIZE]; + int i; + srand(42); + + for (i = 0 ; i < SIZE ; i++) + T[i] = randlong(); + + /* insertion sort */ + if (insert_sort(res1, T) < 0) return -1; + + /* selection sort */ + if (select_sort(res2, T) < 0) return -2; + + /* merge sort */ + if (merge_sort(res3, T) < 0) return -3; + + /* We should have: res1[i] == res2[i] == res3[i] */ + for (i = 0 ; i < SIZE ; i++){ + if (!(res1[i] == res2[i] && res2[i] == res3[i])) + return -4; + } + + return 0; +} diff --git a/test/mppa/sort/merge.c b/test/mppa/sort/merge.c new file mode 100644 index 00000000..99f8ba85 --- /dev/null +++ b/test/mppa/sort/merge.c @@ -0,0 +1,92 @@ +#include "../prng/prng.h" +#include "../prng/types.h" + +//https://en.wikipedia.org/wiki/Merge_sort + +#ifdef __UNIT_TEST_MERGE__ +#define SIZE 100 +#else +#include "test.h" +#endif + +int min(int a, int b){ + return (a < b)?a:b; +} + +void BottomUpMerge(const uint64_t *A, int iLeft, int iRight, int iEnd, uint64_t *B) +{ + int i = iLeft, j = iRight, k; + for (k = iLeft; k < iEnd; k++) { + if (i < iRight && (j >= iEnd || A[i] <= A[j])) { + B[k] = A[i]; + i = i + 1; + } else { + B[k] = A[j]; + j = j + 1; + } + } +} + +void CopyArray(uint64_t *to, const uint64_t *from) +{ + const int n = SIZE; + int i; + + for(i = 0; i < n; i++) + to[i] = from[i]; +} + +void BottomUpMergeSort(uint64_t *A, uint64_t *B) +{ + const int n = SIZE; + int width, i; + + for (width = 1; width < n; width = 2 * width) + { + for (i = 0; i < n; i = i + 2 * width) + { + BottomUpMerge(A, i, min(i+width, n), min(i+2*width, n), B); + } + CopyArray(A, B); + } +} + +int merge_sort(uint64_t *res, const uint64_t *T){ + int i; + + if (SIZE <= 0) + return -1; + + uint64_t B[SIZE]; + uint64_t *A = res; + for (i = 0 ; i < SIZE ; i++) + A[i] = T[i]; + + BottomUpMergeSort(A, B); + + return 0; +} + +#ifdef __UNIT_TEST_MERGE__ +int main(void){ + uint64_t T[SIZE]; + uint64_t res[SIZE]; + int i; + srand(42); + + for (i = 0 ; i < SIZE ; i++) + T[i] = randlong(); + + /* Sorting the table */ + if (merge_sort(res, T) < 0) return -1; + + /* Computing max(T) */ + uint64_t max = T[0]; + for (i = 1 ; i < SIZE ; i++) + if (T[i] > max) + max = T[i]; + + /* We should have: max(T) == res[SIZE] */ + return !(max == res[SIZE-1]); +} +#endif // __UNIT_TEST_MERGE__ diff --git a/test/mppa/sort/merge.h b/test/mppa/sort/merge.h new file mode 100644 index 00000000..439ce64a --- /dev/null +++ b/test/mppa/sort/merge.h @@ -0,0 +1,7 @@ +#ifndef __MERGE_H__ +#define __MERGE_H__ + +int merge_sort(uint64_t *res, const uint64_t *T); + +#endif // __MERGE_H__ + diff --git a/test/mppa/sort/selection.c b/test/mppa/sort/selection.c new file mode 100644 index 00000000..df4be04f --- /dev/null +++ b/test/mppa/sort/selection.c @@ -0,0 +1,62 @@ +#include "../prng/prng.h" +#include "../prng/types.h" + +#ifdef __UNIT_TEST_SELECTION__ +#define SIZE 100 +#else +#include "test.h" +#endif + +void swap_sel(uint64_t *a, uint64_t *b){ + uint64_t tmp = *a; + *a = *b; + *b = tmp; +} + +int select_sort(uint64_t *res, const uint64_t *T){ + int i, j, iMin; + + if (SIZE <= 0) + return -1; + + for (i = 0 ; i < SIZE ; i++) + res[i] = T[i]; + + for (j = 0 ; j < SIZE ; j++){ + iMin = j; + for (i = j+1 ; i < SIZE ; i++) + if (res[i] < res[iMin]) + iMin = i; + + if (iMin != j) + swap_sel (&res[j], &res[iMin]); + } + + return 0; +} + +#ifdef __UNIT_TEST_SELECTION__ +int main(void){ + uint64_t T[SIZE]; + uint64_t res[SIZE]; + uint64_t max; + int i; + srand(42); + + for (i = 0 ; i < SIZE ; i++) + T[i] = randlong(); + + /* Sorting the table */ + if (select_sort(res, T) < 0) return -1; + + /* Computing max(T) */ + max = T[0]; + for (i = 1 ; i < SIZE ; i++) + if (T[i] > max) + max = T[i]; + + /* We should have: max(T) == res[SIZE] */ + return !(max == res[SIZE-1]); +} +#endif // __UNIT_TEST_SELECTION__ + diff --git a/test/mppa/sort/selection.h b/test/mppa/sort/selection.h new file mode 100644 index 00000000..92a6b461 --- /dev/null +++ b/test/mppa/sort/selection.h @@ -0,0 +1,6 @@ +#ifndef __SELECTION_H__ +#define __SELECTION_H__ + +int select_sort(uint64_t *res, const uint64_t *T); + +#endif // __SELECTION_H__ diff --git a/test/mppa/sort/test.h b/test/mppa/sort/test.h new file mode 100644 index 00000000..4501ee38 --- /dev/null +++ b/test/mppa/sort/test.h @@ -0,0 +1,6 @@ +#ifndef __TEST_H__ +#define __TEST_H__ + +#define SIZE 100 + +#endif diff --git a/test/mppa/test.sh b/test/mppa/test.sh new file mode 100755 index 00000000..dfeb153a --- /dev/null +++ b/test/mppa/test.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# Tests the validity of the tests + +source do_test.sh + +do_test test |