From f677664f63ca17c0a514c449f62ad958b5f9eb68 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Thu, 15 Mar 2018 12:05:57 +0100 Subject: MPPA - The project compiles. Supports very simple programs that load integer immediates. It starts the main, loads integer in registers, and return correctly. Addition in Mach not yet supported, but should not be hard to add them. Function calls are not yet supported. The ABI for now is the same as the RiscV, with a small twist: $ra is first loaded in a user register, then this user register is pushed (instead of pushing $ra straight away). --- test/mppa/Makefile | 26 ++++++++++++++++++++++++++ test/mppa/simple.c | 6 ++++++ 2 files changed, 32 insertions(+) create mode 100644 test/mppa/Makefile create mode 100644 test/mppa/simple.c (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile new file mode 100644 index 00000000..6481af5e --- /dev/null +++ b/test/mppa/Makefile @@ -0,0 +1,26 @@ +ELF=simple.bin +DEBUG:=$(if $(DEBUG),"-dall",) + +all: $(ELF) + +%.bin: %.s + k1-gcc $< -o $@ + +.SECONDARY: +%.s: %.c + ccomp $(DEBUG) -v -S $< -o $@ + +.PHONY: +clean: + rm -f *.alloctrace + rm -f *.cm + rm -f *.compcert.c + rm -f *.i + rm -f *.light.c + rm -f *.ltl + rm -f *.mach + rm -f *.parsed.c + rm -f *.rtl.? + rm -f *.s + rm -rf profile/ + rm -f $(ELF) diff --git a/test/mppa/simple.c b/test/mppa/simple.c new file mode 100644 index 00000000..5a54b3d8 --- /dev/null +++ b/test/mppa/simple.c @@ -0,0 +1,6 @@ +int main(void){ + int a = 4; + int b = 3; + + return (a+b); +} -- cgit From 348aa9268bb3f7f2fe4357586a4e1d3181e0c9b3 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Fri, 16 Mar 2018 15:06:28 +0100 Subject: MPPA - code cleaning --- test/mppa/simple.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/mppa/simple.c b/test/mppa/simple.c index 5a54b3d8..725aff68 100644 --- a/test/mppa/simple.c +++ b/test/mppa/simple.c @@ -1,6 +1,6 @@ int main(void){ int a = 4; int b = 3; - + return (a+b); } -- cgit From 447ceed8642e2ed000a20036298adb8448ac594b Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 21 Mar 2018 17:46:45 +0100 Subject: MPPA - Added Msetstack + bunch of store --> on a des call ! --- test/mppa/Makefile | 2 +- test/mppa/call.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/mppa/call.c (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 6481af5e..9078bdb9 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,4 +1,4 @@ -ELF=simple.bin +ELF=simple.bin call.bin DEBUG:=$(if $(DEBUG),"-dall",) all: $(ELF) diff --git a/test/mppa/call.c b/test/mppa/call.c new file mode 100644 index 00000000..3f58b756 --- /dev/null +++ b/test/mppa/call.c @@ -0,0 +1,16 @@ +int sum(int a, int b){ + return a + b; +} + +int make_42(void){ + return 42; +} + +int make_18(void){ + return 18; +} + +int main(void){ + return sum(make_42(), make_18()); + //return make_42() + make_18(); +} -- cgit From 69813ed0107cd76caa322db5e1df1b7b969b7012 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 3 Apr 2018 17:07:09 +0200 Subject: MPPA - 32-bits immediate eq/neq branches --- test/mppa/Makefile | 4 ++-- test/mppa/branch.c | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/mppa/branch.c (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 9078bdb9..e73dcb38 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,4 +1,4 @@ -ELF=simple.bin call.bin +ELF=simple.bin call.bin branch.bin DEBUG:=$(if $(DEBUG),"-dall",) all: $(ELF) @@ -8,7 +8,7 @@ all: $(ELF) .SECONDARY: %.s: %.c - ccomp $(DEBUG) -v -S $< -o $@ + ccomp $(DEBUG) -O0 -v -S $< -o $@ .PHONY: clean: diff --git a/test/mppa/branch.c b/test/mppa/branch.c new file mode 100644 index 00000000..dee15568 --- /dev/null +++ b/test/mppa/branch.c @@ -0,0 +1,12 @@ +int main(void){ + int a=1; + int b; + + if(a){ + b = a+4; + } else { + b = a+2; + } + + return b; +} -- cgit From 36076263491312d634bd0d39f8de718f32462da2 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 4 Apr 2018 11:40:16 +0200 Subject: MPPA - Added signed immediate comparison --- test/mppa/Makefile | 5 ++++- test/mppa/for.c | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/mppa/for.c (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index e73dcb38..b1f25ef1 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,8 +1,11 @@ -ELF=simple.bin call.bin branch.bin +ELF=simple.bin call.bin branch.bin for.bin +ASM=$(subst .bin,.s,$(ELF)) DEBUG:=$(if $(DEBUG),"-dall",) all: $(ELF) +nobin: $(ASM) + %.bin: %.s k1-gcc $< -o $@ diff --git a/test/mppa/for.c b/test/mppa/for.c new file mode 100644 index 00000000..6a3a6cc8 --- /dev/null +++ b/test/mppa/for.c @@ -0,0 +1,9 @@ +int main(void){ + int a = 4; + int i; + + for (i = 0 ; i < 12 ; i++) + a++; + + return a; +} -- cgit From ca090744f399788a81f103206947d4d56cba9d87 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 4 Apr 2018 13:58:10 +0200 Subject: MPPA - Added non immediate comparison --- test/mppa/Makefile | 6 ++++-- test/mppa/forvar.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/mppa/forvar.c (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index b1f25ef1..be8eaab2 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,5 +1,7 @@ -ELF=simple.bin call.bin branch.bin for.bin -ASM=$(subst .bin,.s,$(ELF)) +TESTS=simple call branch for forvar + +ELF=$(addsuffix .bin,$(TESTS)) +ASM=$(addsuffix .s,$(TESTS)) DEBUG:=$(if $(DEBUG),"-dall",) all: $(ELF) diff --git a/test/mppa/forvar.c b/test/mppa/forvar.c new file mode 100644 index 00000000..1a075734 --- /dev/null +++ b/test/mppa/forvar.c @@ -0,0 +1,10 @@ +int main(void){ + int i; + int a = 4; + int b = 12; + + for (i = 0 ; i < b ; i++) + a++; + + return a; +} -- cgit From 17c38f7c4a01cbe5cf20a4f8d5f5d8c0ca888855 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 4 Apr 2018 16:21:02 +0200 Subject: MPPA - added test forvarl.c --- test/mppa/Makefile | 2 +- test/mppa/forvarl.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/mppa/forvarl.c (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index be8eaab2..07224dc8 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,4 +1,4 @@ -TESTS=simple call branch for forvar +TESTS=simple call branch for forvar forvarl ELF=$(addsuffix .bin,$(TESTS)) ASM=$(addsuffix .s,$(TESTS)) diff --git a/test/mppa/forvarl.c b/test/mppa/forvarl.c new file mode 100644 index 00000000..90de7411 --- /dev/null +++ b/test/mppa/forvarl.c @@ -0,0 +1,11 @@ +int main(void) +{ + long long int a = 42; + long long int b = 84; + long long int i; + + for (i = 0 ; i < a ; i++) + b++; + + return 0; +} -- cgit From ebf476c1c9bebaf9b108302ed4c1a5a8da0243a3 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Thu, 5 Apr 2018 11:53:42 +0200 Subject: MPPA - Added regression tests --- test/mppa/Makefile | 35 +++++++++++++++++++------------- test/mppa/branch.c | 12 ----------- test/mppa/call.c | 16 --------------- test/mppa/for.c | 9 -------- test/mppa/forvar.c | 10 --------- test/mppa/forvarl.c | 11 ---------- test/mppa/general/branch.c | 12 +++++++++++ test/mppa/general/call.c | 16 +++++++++++++++ test/mppa/general/for.c | 9 ++++++++ test/mppa/general/forvar.c | 10 +++++++++ test/mppa/general/forvarl.c | 11 ++++++++++ test/mppa/general/output/branch.bin.exp | 1 + test/mppa/general/output/call.bin.exp | 1 + test/mppa/general/output/for.bin.exp | 1 + test/mppa/general/output/forvar.bin.exp | 1 + test/mppa/general/output/forvarl.bin.exp | 1 + test/mppa/general/output/simple.bin.exp | 1 + test/mppa/general/simple.c | 6 ++++++ test/mppa/simple.c | 6 ------ 19 files changed, 91 insertions(+), 78 deletions(-) delete mode 100644 test/mppa/branch.c delete mode 100644 test/mppa/call.c delete mode 100644 test/mppa/for.c delete mode 100644 test/mppa/forvar.c delete mode 100644 test/mppa/forvarl.c create mode 100644 test/mppa/general/branch.c create mode 100644 test/mppa/general/call.c create mode 100644 test/mppa/general/for.c create mode 100644 test/mppa/general/forvar.c create mode 100644 test/mppa/general/forvarl.c create mode 100644 test/mppa/general/output/branch.bin.exp create mode 100644 test/mppa/general/output/call.bin.exp create mode 100644 test/mppa/general/output/for.bin.exp create mode 100644 test/mppa/general/output/forvar.bin.exp create mode 100644 test/mppa/general/output/forvarl.bin.exp create mode 100644 test/mppa/general/output/simple.bin.exp create mode 100644 test/mppa/general/simple.c delete mode 100644 test/mppa/simple.c (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 07224dc8..60433f03 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,5 +1,7 @@ -TESTS=simple call branch for forvar forvarl +DIR=general +TESTNAMES=simple call branch for forvar forvarl +TESTS=$(addprefix $(DIR)/,$(TESTNAMES)) ELF=$(addsuffix .bin,$(TESTS)) ASM=$(addsuffix .s,$(TESTS)) DEBUG:=$(if $(DEBUG),"-dall",) @@ -8,24 +10,29 @@ all: $(ELF) nobin: $(ASM) -%.bin: %.s +$(DIR)/%.bin: $(DIR)/%.s k1-gcc $< -o $@ .SECONDARY: -%.s: %.c +$(DIR)/%.s: $(DIR)/%.c ccomp $(DEBUG) -O0 -v -S $< -o $@ +.PHONY: +check: $(ELF) + bash check.sh $(ELF) + .PHONY: clean: - rm -f *.alloctrace - rm -f *.cm - rm -f *.compcert.c - rm -f *.i - rm -f *.light.c - rm -f *.ltl - rm -f *.mach - rm -f *.parsed.c - rm -f *.rtl.? - rm -f *.s - rm -rf profile/ + rm -f $(DIR)/*.alloctrace + rm -f $(DIR)/*.cm + rm -f $(DIR)/*.compcert.c + rm -f $(DIR)/*.i + rm -f $(DIR)/*.light.c + rm -f $(DIR)/*.ltl + rm -f $(DIR)/*.mach + rm -f $(DIR)/*.parsed.c + rm -f $(DIR)/*.rtl.? + rm -f $(DIR)/*.s + rm -f $(DIR)/output/*.out + rm -rf $(DIR)/profile/ rm -f $(ELF) diff --git a/test/mppa/branch.c b/test/mppa/branch.c deleted file mode 100644 index dee15568..00000000 --- a/test/mppa/branch.c +++ /dev/null @@ -1,12 +0,0 @@ -int main(void){ - int a=1; - int b; - - if(a){ - b = a+4; - } else { - b = a+2; - } - - return b; -} diff --git a/test/mppa/call.c b/test/mppa/call.c deleted file mode 100644 index 3f58b756..00000000 --- a/test/mppa/call.c +++ /dev/null @@ -1,16 +0,0 @@ -int sum(int a, int b){ - return a + b; -} - -int make_42(void){ - return 42; -} - -int make_18(void){ - return 18; -} - -int main(void){ - return sum(make_42(), make_18()); - //return make_42() + make_18(); -} diff --git a/test/mppa/for.c b/test/mppa/for.c deleted file mode 100644 index 6a3a6cc8..00000000 --- a/test/mppa/for.c +++ /dev/null @@ -1,9 +0,0 @@ -int main(void){ - int a = 4; - int i; - - for (i = 0 ; i < 12 ; i++) - a++; - - return a; -} diff --git a/test/mppa/forvar.c b/test/mppa/forvar.c deleted file mode 100644 index 1a075734..00000000 --- a/test/mppa/forvar.c +++ /dev/null @@ -1,10 +0,0 @@ -int main(void){ - int i; - int a = 4; - int b = 12; - - for (i = 0 ; i < b ; i++) - a++; - - return a; -} diff --git a/test/mppa/forvarl.c b/test/mppa/forvarl.c deleted file mode 100644 index 90de7411..00000000 --- a/test/mppa/forvarl.c +++ /dev/null @@ -1,11 +0,0 @@ -int main(void) -{ - long long int a = 42; - long long int b = 84; - long long int i; - - for (i = 0 ; i < a ; i++) - b++; - - return 0; -} diff --git a/test/mppa/general/branch.c b/test/mppa/general/branch.c new file mode 100644 index 00000000..dee15568 --- /dev/null +++ b/test/mppa/general/branch.c @@ -0,0 +1,12 @@ +int main(void){ + int a=1; + int b; + + if(a){ + b = a+4; + } else { + b = a+2; + } + + return b; +} diff --git a/test/mppa/general/call.c b/test/mppa/general/call.c new file mode 100644 index 00000000..3f58b756 --- /dev/null +++ b/test/mppa/general/call.c @@ -0,0 +1,16 @@ +int sum(int a, int b){ + return a + b; +} + +int make_42(void){ + return 42; +} + +int make_18(void){ + return 18; +} + +int main(void){ + return sum(make_42(), make_18()); + //return make_42() + make_18(); +} diff --git a/test/mppa/general/for.c b/test/mppa/general/for.c new file mode 100644 index 00000000..6a3a6cc8 --- /dev/null +++ b/test/mppa/general/for.c @@ -0,0 +1,9 @@ +int main(void){ + int a = 4; + int i; + + for (i = 0 ; i < 12 ; i++) + a++; + + return a; +} diff --git a/test/mppa/general/forvar.c b/test/mppa/general/forvar.c new file mode 100644 index 00000000..1a075734 --- /dev/null +++ b/test/mppa/general/forvar.c @@ -0,0 +1,10 @@ +int main(void){ + int i; + int a = 4; + int b = 12; + + for (i = 0 ; i < b ; i++) + a++; + + return a; +} diff --git a/test/mppa/general/forvarl.c b/test/mppa/general/forvarl.c new file mode 100644 index 00000000..90de7411 --- /dev/null +++ b/test/mppa/general/forvarl.c @@ -0,0 +1,11 @@ +int main(void) +{ + long long int a = 42; + long long int b = 84; + long long int i; + + for (i = 0 ; i < a ; i++) + b++; + + return 0; +} diff --git a/test/mppa/general/output/branch.bin.exp b/test/mppa/general/output/branch.bin.exp new file mode 100644 index 00000000..7ed6ff82 --- /dev/null +++ b/test/mppa/general/output/branch.bin.exp @@ -0,0 +1 @@ +5 diff --git a/test/mppa/general/output/call.bin.exp b/test/mppa/general/output/call.bin.exp new file mode 100644 index 00000000..abdfb053 --- /dev/null +++ b/test/mppa/general/output/call.bin.exp @@ -0,0 +1 @@ +60 diff --git a/test/mppa/general/output/for.bin.exp b/test/mppa/general/output/for.bin.exp new file mode 100644 index 00000000..b6a7d89c --- /dev/null +++ b/test/mppa/general/output/for.bin.exp @@ -0,0 +1 @@ +16 diff --git a/test/mppa/general/output/forvar.bin.exp b/test/mppa/general/output/forvar.bin.exp new file mode 100644 index 00000000..b6a7d89c --- /dev/null +++ b/test/mppa/general/output/forvar.bin.exp @@ -0,0 +1 @@ +16 diff --git a/test/mppa/general/output/forvarl.bin.exp b/test/mppa/general/output/forvarl.bin.exp new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/test/mppa/general/output/forvarl.bin.exp @@ -0,0 +1 @@ +0 diff --git a/test/mppa/general/output/simple.bin.exp b/test/mppa/general/output/simple.bin.exp new file mode 100644 index 00000000..7f8f011e --- /dev/null +++ b/test/mppa/general/output/simple.bin.exp @@ -0,0 +1 @@ +7 diff --git a/test/mppa/general/simple.c b/test/mppa/general/simple.c new file mode 100644 index 00000000..725aff68 --- /dev/null +++ b/test/mppa/general/simple.c @@ -0,0 +1,6 @@ +int main(void){ + int a = 4; + int b = 3; + + return (a+b); +} diff --git a/test/mppa/simple.c b/test/mppa/simple.c deleted file mode 100644 index 725aff68..00000000 --- a/test/mppa/simple.c +++ /dev/null @@ -1,6 +0,0 @@ -int main(void){ - int a = 4; - int b = 3; - - return (a+b); -} -- cgit From a724c959659d94425b8dd4a0dc2e343ecdba3edc Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Thu, 5 Apr 2018 11:54:13 +0200 Subject: MPPA - forgot check.sh in last commit --- test/mppa/check.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/mppa/check.sh (limited to 'test') diff --git a/test/mppa/check.sh b/test/mppa/check.sh new file mode 100644 index 00000000..813796d9 --- /dev/null +++ b/test/mppa/check.sh @@ -0,0 +1,29 @@ + +while [ $# -gt 0 ]; do + elffile="$1" + + if [ ! -f $elffile ]; then + >&2 echo "ERROR: $elffile not found" + shift; continue + fi + + dir="$(dirname $elffile)" + elf="$(basename $elffile)" + exp="$dir/output/$elf.exp" + out="$dir/output/$elf.out" + if [ ! -f $exp ]; then + >&2 echo "ERROR: $exp not found" + shift; continue + fi + + k1-cluster -- $elffile > $out + echo $? >> $out + + if ! diff $exp $out; then + >&2 echo "ERROR: $exp and $out differ" + shift; continue + fi + + echo "PASSED: $elf" + shift +done -- cgit From e20c07dddf528ce50951a59cb92f98b4bca8da77 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Mon, 9 Apr 2018 13:55:44 +0200 Subject: MPPA - Optimized branch generation for word compare to 0 --- test/mppa/Makefile | 2 +- test/mppa/general/branchz.c | 12 ++++++++++++ test/mppa/general/branchzu.c | 12 ++++++++++++ test/mppa/general/output/branchz.exp | 1 + test/mppa/general/output/branchzu.exp | 1 + 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/mppa/general/branchz.c create mode 100644 test/mppa/general/branchzu.c create mode 100644 test/mppa/general/output/branchz.exp create mode 100644 test/mppa/general/output/branchzu.exp (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 60433f03..36bd49bc 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,5 +1,5 @@ DIR=general -TESTNAMES=simple call branch for forvar forvarl +TESTNAMES=simple call branch for forvar forvarl branchz branchzu TESTS=$(addprefix $(DIR)/,$(TESTNAMES)) ELF=$(addsuffix .bin,$(TESTS)) diff --git a/test/mppa/general/branchz.c b/test/mppa/general/branchz.c new file mode 100644 index 00000000..5e3226d5 --- /dev/null +++ b/test/mppa/general/branchz.c @@ -0,0 +1,12 @@ +int main(void){ + int a=1; + int b; + + if(a==0){ + b = a+4; + } else { + b = a+2; + } + + return b; +} diff --git a/test/mppa/general/branchzu.c b/test/mppa/general/branchzu.c new file mode 100644 index 00000000..0ff25763 --- /dev/null +++ b/test/mppa/general/branchzu.c @@ -0,0 +1,12 @@ +int main(void){ + int a=1; + int b; + + if(!a){ + b = a+4; + } else { + b = a+2; + } + + return b; +} diff --git a/test/mppa/general/output/branchz.exp b/test/mppa/general/output/branchz.exp new file mode 100644 index 00000000..00750edc --- /dev/null +++ b/test/mppa/general/output/branchz.exp @@ -0,0 +1 @@ +3 diff --git a/test/mppa/general/output/branchzu.exp b/test/mppa/general/output/branchzu.exp new file mode 100644 index 00000000..00750edc --- /dev/null +++ b/test/mppa/general/output/branchzu.exp @@ -0,0 +1 @@ +3 -- cgit From 38b906f983a685af967b51bae2f8038c47d87b91 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 10 Apr 2018 09:56:52 +0200 Subject: MPPA - fixed wrong extension in test files --- test/mppa/general/output/branchz.bin.exp | 1 + test/mppa/general/output/branchz.exp | 1 - test/mppa/general/output/branchzu.bin.exp | 1 + test/mppa/general/output/branchzu.exp | 1 - 4 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 test/mppa/general/output/branchz.bin.exp delete mode 100644 test/mppa/general/output/branchz.exp create mode 100644 test/mppa/general/output/branchzu.bin.exp delete mode 100644 test/mppa/general/output/branchzu.exp (limited to 'test') diff --git a/test/mppa/general/output/branchz.bin.exp b/test/mppa/general/output/branchz.bin.exp new file mode 100644 index 00000000..00750edc --- /dev/null +++ b/test/mppa/general/output/branchz.bin.exp @@ -0,0 +1 @@ +3 diff --git a/test/mppa/general/output/branchz.exp b/test/mppa/general/output/branchz.exp deleted file mode 100644 index 00750edc..00000000 --- a/test/mppa/general/output/branchz.exp +++ /dev/null @@ -1 +0,0 @@ -3 diff --git a/test/mppa/general/output/branchzu.bin.exp b/test/mppa/general/output/branchzu.bin.exp new file mode 100644 index 00000000..00750edc --- /dev/null +++ b/test/mppa/general/output/branchzu.bin.exp @@ -0,0 +1 @@ +3 diff --git a/test/mppa/general/output/branchzu.exp b/test/mppa/general/output/branchzu.exp deleted file mode 100644 index 00750edc..00000000 --- a/test/mppa/general/output/branchzu.exp +++ /dev/null @@ -1 +0,0 @@ -3 -- cgit From 5541fb2f156aa314e26cac65546458e47ba03264 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 10 Apr 2018 10:35:09 +0200 Subject: MPPA - Running tests in parallel --- test/mppa/Makefile | 11 +++++++++-- test/mppa/check.sh | 56 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 41 insertions(+), 26 deletions(-) (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 36bd49bc..6f7ea55a 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -3,6 +3,7 @@ TESTNAMES=simple call branch for forvar forvarl branchz branchzu TESTS=$(addprefix $(DIR)/,$(TESTNAMES)) ELF=$(addsuffix .bin,$(TESTS)) +TOK=$(addsuffix .tok,$(TESTS)) ASM=$(addsuffix .s,$(TESTS)) DEBUG:=$(if $(DEBUG),"-dall",) @@ -17,9 +18,14 @@ $(DIR)/%.bin: $(DIR)/%.s $(DIR)/%.s: $(DIR)/%.c ccomp $(DEBUG) -O0 -v -S $< -o $@ +$(DIR)/%.tok: $(DIR)/%.bin FORCE + @bash check.sh $< $@ + +.PHONY: FORCE +FORCE: + .PHONY: -check: $(ELF) - bash check.sh $(ELF) +check: $(TOK) .PHONY: clean: @@ -33,6 +39,7 @@ clean: rm -f $(DIR)/*.parsed.c rm -f $(DIR)/*.rtl.? rm -f $(DIR)/*.s + rm -f $(DIR)/*.tok rm -f $(DIR)/output/*.out rm -rf $(DIR)/profile/ rm -f $(ELF) diff --git a/test/mppa/check.sh b/test/mppa/check.sh index 813796d9..8e889175 100644 --- a/test/mppa/check.sh +++ b/test/mppa/check.sh @@ -1,29 +1,37 @@ +# $1: binary file to check +# $2: output check token -while [ $# -gt 0 ]; do - elffile="$1" - - if [ ! -f $elffile ]; then - >&2 echo "ERROR: $elffile not found" - shift; continue - fi +elffile="$1" +token="$2" - dir="$(dirname $elffile)" - elf="$(basename $elffile)" - exp="$dir/output/$elf.exp" - out="$dir/output/$elf.out" - if [ ! -f $exp ]; then - >&2 echo "ERROR: $exp not found" - shift; continue - fi +if [ ! -f $elffile ]; then + >&2 echo "ERROR: $elffile not found" + shift; continue +fi - k1-cluster -- $elffile > $out - echo $? >> $out +if [ -f $token ]; then + echo "ALREADY PASSED: $elffile" + exit +fi - if ! diff $exp $out; then - >&2 echo "ERROR: $exp and $out differ" - shift; continue - fi +dir="$(dirname $elffile)" +elf="$(basename $elffile)" +exp="$dir/output/$elf.exp" +out="$dir/output/$elf.out" +if [ ! -f $exp ]; then + >&2 echo "ERROR: $exp not found" + shift; continue +fi - echo "PASSED: $elf" - shift -done +k1-cluster -- $elffile > $out +echo $? >> $out + +if ! diff $exp $out; then + >&2 echo "ERROR: $exp and $out differ" + exit + #shift; continue +fi + +echo "PASSED: $elf" +touch $token +#shift -- cgit From 9862e89118492e6ab530b2e2992161dd4eb52d0a Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 10 Apr 2018 13:51:50 +0200 Subject: MPPA - Onegl + Pnegl --- test/mppa/Makefile | 5 +++-- test/mppa/check.sh | 5 ----- 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 6f7ea55a..c02f8d94 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,6 +1,7 @@ DIR=general TESTNAMES=simple call branch for forvar forvarl branchz branchzu +CCOMP=../../ccomp TESTS=$(addprefix $(DIR)/,$(TESTNAMES)) ELF=$(addsuffix .bin,$(TESTS)) TOK=$(addsuffix .tok,$(TESTS)) @@ -15,10 +16,10 @@ $(DIR)/%.bin: $(DIR)/%.s k1-gcc $< -o $@ .SECONDARY: -$(DIR)/%.s: $(DIR)/%.c +$(DIR)/%.s: $(DIR)/%.c $(CCOMP) ccomp $(DEBUG) -O0 -v -S $< -o $@ -$(DIR)/%.tok: $(DIR)/%.bin FORCE +$(DIR)/%.tok: $(DIR)/%.bin @bash check.sh $< $@ .PHONY: FORCE diff --git a/test/mppa/check.sh b/test/mppa/check.sh index 8e889175..f38d3f0d 100644 --- a/test/mppa/check.sh +++ b/test/mppa/check.sh @@ -9,11 +9,6 @@ if [ ! -f $elffile ]; then shift; continue fi -if [ -f $token ]; then - echo "ALREADY PASSED: $elffile" - exit -fi - dir="$(dirname $elffile)" elf="$(basename $elffile)" exp="$dir/output/$elf.exp" -- cgit From 5e35117f8dd7cc4c548ecd704e11f3ca8845dedd Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 11 Apr 2018 10:54:56 +0200 Subject: MPPA - reorganized the test directory --- test/mppa/Makefile | 23 ++++++++++++++--------- test/mppa/check.sh | 8 ++++---- 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index c02f8d94..f8b3f68c 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,25 +1,30 @@ DIR=general +BINDIR=bin +ASMDIR=asm TESTNAMES=simple call branch for forvar forvarl branchz branchzu CCOMP=../../ccomp -TESTS=$(addprefix $(DIR)/,$(TESTNAMES)) -ELF=$(addsuffix .bin,$(TESTS)) -TOK=$(addsuffix .tok,$(TESTS)) -ASM=$(addsuffix .s,$(TESTS)) +#TESTS=$(addprefix $(DIR)/,$(TESTNAMES)) +ELF=$(addprefix $(DIR)/$(BINDIR)/,$(addsuffix .bin,$(TESTNAMES))) +TOK=$(addprefix $(DIR)/$(BINDIR)/,$(addsuffix .tok,$(TESTNAMES))) +ASM=$(addprefix $(DIR)/$(ASMDIR)/,$(addsuffix .s,$(TESTNAMES))) DEBUG:=$(if $(DEBUG),"-dall",) all: $(ELF) nobin: $(ASM) -$(DIR)/%.bin: $(DIR)/%.s +$(DIR)/$(BINDIR)/%.bin: $(DIR)/$(ASMDIR)/%.s + @mkdir -p $(@D) k1-gcc $< -o $@ .SECONDARY: -$(DIR)/%.s: $(DIR)/%.c $(CCOMP) +$(DIR)/$(ASMDIR)/%.s: $(DIR)/%.c $(CCOMP) + @mkdir -p $(@D) ccomp $(DEBUG) -O0 -v -S $< -o $@ -$(DIR)/%.tok: $(DIR)/%.bin +$(DIR)/$(BINDIR)/%.tok: $(DIR)/$(BINDIR)/%.bin + @mkdir -p $(@D) @bash check.sh $< $@ .PHONY: FORCE @@ -39,8 +44,8 @@ clean: rm -f $(DIR)/*.mach rm -f $(DIR)/*.parsed.c rm -f $(DIR)/*.rtl.? - rm -f $(DIR)/*.s - rm -f $(DIR)/*.tok + rm -f $(DIR)/$(ASMDIR)/*.s + rm -f $(DIR)/$(BINDIR)/*.[bin,tok] rm -f $(DIR)/output/*.out rm -rf $(DIR)/profile/ rm -f $(ELF) diff --git a/test/mppa/check.sh b/test/mppa/check.sh index f38d3f0d..dd9691be 100644 --- a/test/mppa/check.sh +++ b/test/mppa/check.sh @@ -11,11 +11,12 @@ fi dir="$(dirname $elffile)" elf="$(basename $elffile)" -exp="$dir/output/$elf.exp" -out="$dir/output/$elf.out" + +exp="$dir/../output/$elf.exp" +out="$dir/../output/$elf.out" if [ ! -f $exp ]; then >&2 echo "ERROR: $exp not found" - shift; continue + exit fi k1-cluster -- $elffile > $out @@ -24,7 +25,6 @@ echo $? >> $out if ! diff $exp $out; then >&2 echo "ERROR: $exp and $out differ" exit - #shift; continue fi echo "PASSED: $elf" -- cgit From d407e23fe62ce837082820f777564c0050cf66c1 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 11 Apr 2018 16:28:49 +0200 Subject: MPPA - Automatic generation of expected value for tests --- test/mppa/Makefile | 9 +++++++-- test/mppa/general/branch.c | 1 + test/mppa/general/branchz.c | 1 + test/mppa/general/branchzu.c | 1 + test/mppa/general/call.c | 2 ++ test/mppa/general/for.c | 2 ++ test/mppa/general/forvar.c | 2 ++ test/mppa/general/forvarl.c | 2 ++ test/mppa/general/output/branch.bin.exp | 1 - test/mppa/general/output/branchz.bin.exp | 1 - test/mppa/general/output/branchzu.bin.exp | 1 - test/mppa/general/output/call.bin.exp | 1 - test/mppa/general/output/for.bin.exp | 1 - test/mppa/general/output/forvar.bin.exp | 1 - test/mppa/general/output/forvarl.bin.exp | 1 - test/mppa/general/output/simple.bin.exp | 1 - test/mppa/general/simple.c | 2 ++ test/mppa/generate.sh | 12 ++++++++++++ 18 files changed, 32 insertions(+), 10 deletions(-) delete mode 100644 test/mppa/general/output/branch.bin.exp delete mode 100644 test/mppa/general/output/branchz.bin.exp delete mode 100644 test/mppa/general/output/branchzu.bin.exp delete mode 100644 test/mppa/general/output/call.bin.exp delete mode 100644 test/mppa/general/output/for.bin.exp delete mode 100644 test/mppa/general/output/forvar.bin.exp delete mode 100644 test/mppa/general/output/forvarl.bin.exp delete mode 100644 test/mppa/general/output/simple.bin.exp create mode 100644 test/mppa/generate.sh (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index f8b3f68c..0e0b2eb2 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -23,10 +23,13 @@ $(DIR)/$(ASMDIR)/%.s: $(DIR)/%.c $(CCOMP) @mkdir -p $(@D) ccomp $(DEBUG) -O0 -v -S $< -o $@ -$(DIR)/$(BINDIR)/%.tok: $(DIR)/$(BINDIR)/%.bin +$(DIR)/$(BINDIR)/%.tok: $(DIR)/$(BINDIR)/%.bin $(DIR)/output/%.bin.exp @mkdir -p $(@D) @bash check.sh $< $@ +$(DIR)/output/%.bin.exp: $(DIR)/%.c + @bash generate.sh $< $@ + .PHONY: FORCE FORCE: @@ -45,7 +48,9 @@ clean: rm -f $(DIR)/*.parsed.c rm -f $(DIR)/*.rtl.? rm -f $(DIR)/$(ASMDIR)/*.s - rm -f $(DIR)/$(BINDIR)/*.[bin,tok] + rm -f $(DIR)/$(BINDIR)/*.bin + rm -f $(DIR)/$(BINDIR)/*.tok rm -f $(DIR)/output/*.out + rm -f $(DIR)/output/*.exp rm -rf $(DIR)/profile/ rm -f $(ELF) diff --git a/test/mppa/general/branch.c b/test/mppa/general/branch.c index dee15568..c9bb3865 100644 --- a/test/mppa/general/branch.c +++ b/test/mppa/general/branch.c @@ -10,3 +10,4 @@ int main(void){ return b; } +/* RETURN VALUE: 5 */ diff --git a/test/mppa/general/branchz.c b/test/mppa/general/branchz.c index 5e3226d5..685d3961 100644 --- a/test/mppa/general/branchz.c +++ b/test/mppa/general/branchz.c @@ -10,3 +10,4 @@ int main(void){ return b; } +/* RETURN VALUE: 3 */ diff --git a/test/mppa/general/branchzu.c b/test/mppa/general/branchzu.c index 0ff25763..16bbc4c1 100644 --- a/test/mppa/general/branchzu.c +++ b/test/mppa/general/branchzu.c @@ -10,3 +10,4 @@ int main(void){ return b; } +/* RETURN VALUE: 3 */ diff --git a/test/mppa/general/call.c b/test/mppa/general/call.c index 3f58b756..f35473b6 100644 --- a/test/mppa/general/call.c +++ b/test/mppa/general/call.c @@ -14,3 +14,5 @@ int main(void){ return sum(make_42(), make_18()); //return make_42() + make_18(); } + +/* RETURN VALUE: 60 */ diff --git a/test/mppa/general/for.c b/test/mppa/general/for.c index 6a3a6cc8..41669146 100644 --- a/test/mppa/general/for.c +++ b/test/mppa/general/for.c @@ -7,3 +7,5 @@ int main(void){ return a; } + +/* RETURN VALUE: 16 */ diff --git a/test/mppa/general/forvar.c b/test/mppa/general/forvar.c index 1a075734..5ada4357 100644 --- a/test/mppa/general/forvar.c +++ b/test/mppa/general/forvar.c @@ -8,3 +8,5 @@ int main(void){ return a; } + +/* RETURN VALUE: 16 */ diff --git a/test/mppa/general/forvarl.c b/test/mppa/general/forvarl.c index 90de7411..0ab31998 100644 --- a/test/mppa/general/forvarl.c +++ b/test/mppa/general/forvarl.c @@ -9,3 +9,5 @@ int main(void) return 0; } + +/* RETURN VALUE: 0 */ diff --git a/test/mppa/general/output/branch.bin.exp b/test/mppa/general/output/branch.bin.exp deleted file mode 100644 index 7ed6ff82..00000000 --- a/test/mppa/general/output/branch.bin.exp +++ /dev/null @@ -1 +0,0 @@ -5 diff --git a/test/mppa/general/output/branchz.bin.exp b/test/mppa/general/output/branchz.bin.exp deleted file mode 100644 index 00750edc..00000000 --- a/test/mppa/general/output/branchz.bin.exp +++ /dev/null @@ -1 +0,0 @@ -3 diff --git a/test/mppa/general/output/branchzu.bin.exp b/test/mppa/general/output/branchzu.bin.exp deleted file mode 100644 index 00750edc..00000000 --- a/test/mppa/general/output/branchzu.bin.exp +++ /dev/null @@ -1 +0,0 @@ -3 diff --git a/test/mppa/general/output/call.bin.exp b/test/mppa/general/output/call.bin.exp deleted file mode 100644 index abdfb053..00000000 --- a/test/mppa/general/output/call.bin.exp +++ /dev/null @@ -1 +0,0 @@ -60 diff --git a/test/mppa/general/output/for.bin.exp b/test/mppa/general/output/for.bin.exp deleted file mode 100644 index b6a7d89c..00000000 --- a/test/mppa/general/output/for.bin.exp +++ /dev/null @@ -1 +0,0 @@ -16 diff --git a/test/mppa/general/output/forvar.bin.exp b/test/mppa/general/output/forvar.bin.exp deleted file mode 100644 index b6a7d89c..00000000 --- a/test/mppa/general/output/forvar.bin.exp +++ /dev/null @@ -1 +0,0 @@ -16 diff --git a/test/mppa/general/output/forvarl.bin.exp b/test/mppa/general/output/forvarl.bin.exp deleted file mode 100644 index 573541ac..00000000 --- a/test/mppa/general/output/forvarl.bin.exp +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/test/mppa/general/output/simple.bin.exp b/test/mppa/general/output/simple.bin.exp deleted file mode 100644 index 7f8f011e..00000000 --- a/test/mppa/general/output/simple.bin.exp +++ /dev/null @@ -1 +0,0 @@ -7 diff --git a/test/mppa/general/simple.c b/test/mppa/general/simple.c index 725aff68..451522fc 100644 --- a/test/mppa/general/simple.c +++ b/test/mppa/general/simple.c @@ -4,3 +4,5 @@ int main(void){ return (a+b); } + +/* RETURN VALUE: 7 */ diff --git a/test/mppa/generate.sh b/test/mppa/generate.sh new file mode 100644 index 00000000..cfe6f7bb --- /dev/null +++ b/test/mppa/generate.sh @@ -0,0 +1,12 @@ +# $1: c file to examine +# $2: write file + +cfile="$1" +writefile="$2" + +if [ ! -f $cfile ]; then + >&2 echo "ERROR: $cfile not found" + shift; continue +fi + +sed -n "s/^.*\/\*\s*RETURN VALUE:\s*\([0-9]*\)\s*\*\//\1/p" $1 > $2 -- cgit From b26424165aa5ae75099792232eca9ea08e09d5a1 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Mon, 16 Apr 2018 17:31:27 +0200 Subject: MPPA - added PRNG generator in the tests --- test/mppa/lib/Makefile | 18 ++++++++++++++++++ test/mppa/lib/prng.c | 40 ++++++++++++++++++++++++++++++++++++++++ test/mppa/lib/prng.h | 8 ++++++++ 3 files changed, 66 insertions(+) create mode 100644 test/mppa/lib/Makefile create mode 100644 test/mppa/lib/prng.c create mode 100644 test/mppa/lib/prng.h (limited to 'test') diff --git a/test/mppa/lib/Makefile b/test/mppa/lib/Makefile new file mode 100644 index 00000000..10f40f23 --- /dev/null +++ b/test/mppa/lib/Makefile @@ -0,0 +1,18 @@ +prng-test-x86: prng.c + gcc -D__UNIT_TEST__ -O2 -std=c99 $< -o $@ + +.PHONY: +test: test-x86 + +.PHONY: +test-x86: prng-test-x86 + @if ! ./$<; then\ + >&2 echo "ERROR: $< failed";\ + exit;\ + else\ + echo "Test Succeeded";\ + fi + +.PHONY: +clean: + rm -f prng-test-x86 diff --git a/test/mppa/lib/prng.c b/test/mppa/lib/prng.c new file mode 100644 index 00000000..5846038c --- /dev/null +++ b/test/mppa/lib/prng.c @@ -0,0 +1,40 @@ +// https://en.wikipedia.org/wiki/Linear_congruential_generator -> MMIX Donald Knuth +// modulo 2^64 = no need to do it explicitly + +#define MULTIPLIER 6364136223846793005LL +#define INCREMENT 1442695040888963407LL + +static unsigned long long current; + +void srand(long long seed){ + seed = current; +} + +unsigned long long randlong(void){ + return (current = MULTIPLIER * current + INCREMENT); +} + +#ifdef __UNIT_TEST__ +char bytewise_sum(unsigned long long to_check){ + char sum = 0; + + for (int i = 0 ; i < 8 ; i++) + sum += (to_check & (unsigned long long)(0xFFULL << i*8)) >> i*8; + + return sum; +} + +int main(void){ + srand(42); + + if (bytewise_sum(0xdeadbeefb00b1355ULL) != 91) + return 1; + + for (int i = 0 ; i < 1000 ; i++) + randlong(); + + unsigned long long last = randlong(); + + return !((unsigned char)bytewise_sum(last) == 251); +} +#endif // __UNIT_TEST__ diff --git a/test/mppa/lib/prng.h b/test/mppa/lib/prng.h new file mode 100644 index 00000000..fee8c865 --- /dev/null +++ b/test/mppa/lib/prng.h @@ -0,0 +1,8 @@ +#ifndef __PRNG_H__ +#define __PRNG_H__ + +void srand(long long seed); + +long long randlong(void); + +#endif // __PRNG_H__ -- cgit From c740492e7a5c14a524c31bbc769a07af2e2ac6be Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 17 Apr 2018 09:59:42 +0200 Subject: MPPA - Added uint64_t types to the tests + k1c test --- test/mppa/lib/Makefile | 18 +++++++++++++++--- test/mppa/lib/prng.c | 14 ++++++++------ test/mppa/lib/prng.h | 6 ++++-- test/mppa/lib/types.h | 7 +++++++ 4 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 test/mppa/lib/types.h (limited to 'test') diff --git a/test/mppa/lib/Makefile b/test/mppa/lib/Makefile index 10f40f23..e6a75707 100644 --- a/test/mppa/lib/Makefile +++ b/test/mppa/lib/Makefile @@ -1,8 +1,11 @@ prng-test-x86: prng.c gcc -D__UNIT_TEST__ -O2 -std=c99 $< -o $@ +prng-test-k1c: prng.c + k1-gcc -D__UNIT_TEST__ -O2 -std=c99 $< -o $@ + .PHONY: -test: test-x86 +test: test-x86 test-k1c .PHONY: test-x86: prng-test-x86 @@ -10,9 +13,18 @@ test-x86: prng-test-x86 >&2 echo "ERROR: $< failed";\ exit;\ else\ - echo "Test Succeeded";\ + echo "x86: Test Succeeded";\ + fi + +.PHONY: +test-k1c: prng-test-k1c + @if ! k1-cluster -- ./$<; then\ + >&2 echo "ERROR: $< failed";\ + exit;\ + else\ + echo "k1c: Test Succeeded";\ fi .PHONY: clean: - rm -f prng-test-x86 + rm -f prng-test-x86 prng-test-k1c diff --git a/test/mppa/lib/prng.c b/test/mppa/lib/prng.c index 5846038c..bfc38678 100644 --- a/test/mppa/lib/prng.c +++ b/test/mppa/lib/prng.c @@ -1,25 +1,27 @@ // 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 unsigned long long current; +static uint64_t current; -void srand(long long seed){ +void srand(uint64_t seed){ seed = current; } -unsigned long long randlong(void){ +uint64_t randlong(void){ return (current = MULTIPLIER * current + INCREMENT); } #ifdef __UNIT_TEST__ -char bytewise_sum(unsigned long long to_check){ +char bytewise_sum(uint64_t to_check){ char sum = 0; for (int i = 0 ; i < 8 ; i++) - sum += (to_check & (unsigned long long)(0xFFULL << i*8)) >> i*8; + sum += (to_check & (uint64_t)(0xFFULL << i*8)) >> i*8; return sum; } @@ -33,7 +35,7 @@ int main(void){ for (int i = 0 ; i < 1000 ; i++) randlong(); - unsigned long long last = randlong(); + uint64_t last = randlong(); return !((unsigned char)bytewise_sum(last) == 251); } diff --git a/test/mppa/lib/prng.h b/test/mppa/lib/prng.h index fee8c865..6abdb45a 100644 --- a/test/mppa/lib/prng.h +++ b/test/mppa/lib/prng.h @@ -1,8 +1,10 @@ #ifndef __PRNG_H__ #define __PRNG_H__ -void srand(long long seed); +#include "types.h" -long long randlong(void); +void srand(uint64_t seed); + +uint64_t randlong(void); #endif // __PRNG_H__ diff --git a/test/mppa/lib/types.h b/test/mppa/lib/types.h new file mode 100644 index 00000000..584023e3 --- /dev/null +++ b/test/mppa/lib/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__ -- cgit From 04722ad007e7a4f0cef7fd2fd08a6f3219138299 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 17 Apr 2018 12:00:43 +0200 Subject: MPPA - changed UNIT_TEST names --- test/mppa/lib/Makefile | 4 ++-- test/mppa/lib/prng.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/mppa/lib/Makefile b/test/mppa/lib/Makefile index e6a75707..7aeab9f3 100644 --- a/test/mppa/lib/Makefile +++ b/test/mppa/lib/Makefile @@ -1,8 +1,8 @@ prng-test-x86: prng.c - gcc -D__UNIT_TEST__ -O2 -std=c99 $< -o $@ + gcc -D__UNIT_TEST_PRNG__ -O2 -std=c99 $< -o $@ prng-test-k1c: prng.c - k1-gcc -D__UNIT_TEST__ -O2 -std=c99 $< -o $@ + k1-gcc -D__UNIT_TEST_PRNG__ -O2 -std=c99 $< -o $@ .PHONY: test: test-x86 test-k1c diff --git a/test/mppa/lib/prng.c b/test/mppa/lib/prng.c index bfc38678..dfa97834 100644 --- a/test/mppa/lib/prng.c +++ b/test/mppa/lib/prng.c @@ -16,7 +16,7 @@ uint64_t randlong(void){ return (current = MULTIPLIER * current + INCREMENT); } -#ifdef __UNIT_TEST__ +#ifdef __UNIT_TEST_PRNG__ char bytewise_sum(uint64_t to_check){ char sum = 0; @@ -39,4 +39,4 @@ int main(void){ return !((unsigned char)bytewise_sum(last) == 251); } -#endif // __UNIT_TEST__ +#endif // __UNIT_TEST_PRNG__ -- cgit From eb1e1c79fa3fc882b68c67d781f7b64e74e00828 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 17 Apr 2018 12:01:18 +0200 Subject: MPPA - tests - added insertion sort and selection sort --- test/mppa/sort/Makefile | 40 +++++++++++++++++++++++++++++++++ test/mppa/sort/insertion.c | 52 +++++++++++++++++++++++++++++++++++++++++++ test/mppa/sort/insertion.h | 6 +++++ test/mppa/sort/selection.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++ test/mppa/sort/selection.h | 6 +++++ 5 files changed, 159 insertions(+) create mode 100644 test/mppa/sort/Makefile create mode 100644 test/mppa/sort/insertion.c create mode 100644 test/mppa/sort/insertion.h create mode 100644 test/mppa/sort/selection.c create mode 100644 test/mppa/sort/selection.h (limited to 'test') diff --git a/test/mppa/sort/Makefile b/test/mppa/sort/Makefile new file mode 100644 index 00000000..1f4a0d51 --- /dev/null +++ b/test/mppa/sort/Makefile @@ -0,0 +1,40 @@ +PRNG=../lib/prng.c + +insertion-test-x86: insertion.c $(PRNG) + gcc -g -D__UNIT_TEST_INSERTION__ -O2 -std=c99 $^ -o $@ + +insertion-test-k1c: insertion.c $(PRNG) + k1-gcc -D__UNIT_TEST_INSERTION__ -O2 -std=c99 $^ -o $@ + +selection-test-x86: selection.c $(PRNG) + gcc -g -D__UNIT_TEST_SELECTION__ -O2 -std=c99 $^ -o $@ + +selection-test-k1c: selection.c $(PRNG) + k1-gcc -D__UNIT_TEST_SELECTION__ -O2 -std=c99 $^ -o $@ + +.PHONY: +unittest: unittest-x86 unittest-k1c + +.PHONY: +unittest-x86: insertion-test-x86 selection-test-x86 + @for test in $^; do\ + if ! ./$$test; then\ + >&2 echo "ERROR: $$test failed";\ + else\ + echo "x86: Test $$test Succeeded";\ + fi;\ + done + +.PHONY: +unittest-k1c: insertion-test-k1c selection-test-k1c + @for test in $^; do\ + if ! k1-cluster -- ./$$test; then\ + >&2 echo "ERROR: $$test failed";\ + else\ + echo "k1c: Test $$test Succeeded";\ + fi;\ + done + +.PHONY: +clean: + rm -f insertion-test-x86 insertion-test-k1c selection-test-k1c selection-test-x86 diff --git a/test/mppa/sort/insertion.c b/test/mppa/sort/insertion.c new file mode 100644 index 00000000..2c6065e7 --- /dev/null +++ b/test/mppa/sort/insertion.c @@ -0,0 +1,52 @@ +#include "../lib/prng.h" +#include "../lib/types.h" + +void swap(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 size){ + if (size <= 0) + return -1; + + for (int i = 0 ; i < size ; i++) + res[i] = T[i]; + + for (int i = 0 ; i < size-1 ; i++){ + if (res[i] > res[i+1]){ + swap(&res[i], &res[i+1]); + for (int j = i ; j > 1 ; j--) + if (res[j-1] > res[j]) + swap(&res[j-1], &res[j]); + } + } + + return 0; +} + +#ifdef __UNIT_TEST_INSERTION__ +#define SIZE 100 + +int main(void){ + uint64_t T[SIZE]; + uint64_t res[SIZE]; + srand(42); + + for (int i = 0 ; i < SIZE ; i++) + T[i] = randlong(); + + /* Sorting the table */ + if (insert_sort(res, T, SIZE) < 0) return -1; + + /* Computing max(T) */ + uint64_t max = T[0]; + for (int 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..135b3bc1 --- /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, int size); + +#endif // __INSERTION_H__ diff --git a/test/mppa/sort/selection.c b/test/mppa/sort/selection.c new file mode 100644 index 00000000..432bbf49 --- /dev/null +++ b/test/mppa/sort/selection.c @@ -0,0 +1,55 @@ +#include "../lib/prng.h" +#include "../lib/types.h" + +void swap(uint64_t *a, uint64_t *b){ + uint64_t tmp = *a; + *a = *b; + *b = tmp; +} + +int selection_sort(uint64_t *res, const uint64_t *T, int size){ + if (size <= 0) + return -1; + + for (int i = 0 ; i < size ; i++) + res[i] = T[i]; + + for (int j = 0 ; j < size ; j++){ + int i; + int iMin = j; + for (i = j+1 ; i < size ; i++) + if (res[i] < res[iMin]) + iMin = i; + + if (iMin != j) + swap (&res[j], &res[iMin]); + } + + return 0; +} + +#ifdef __UNIT_TEST_SELECTION__ +#define SIZE 100 + +int main(void){ + uint64_t T[SIZE]; + uint64_t res[SIZE]; + srand(42); + + for (int i = 0 ; i < SIZE ; i++) + T[i] = randlong(); + + /* Sorting the table */ + if (selection_sort(res, T, SIZE) < 0) return -1; + + /* Computing max(T) */ + uint64_t max = T[0]; + for (int 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..b2b4aebe --- /dev/null +++ b/test/mppa/sort/selection.h @@ -0,0 +1,6 @@ +#ifndef __SELECTION_H__ +#define __SELECTION_H__ + +int selection_sort(uint64_t *res, const uint64_t *T, int size); + +#endif // __SELECTION_H__ -- cgit From 1b8cf73abc25b1bb167db770a622704f0d672691 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 17 Apr 2018 15:33:14 +0200 Subject: MPPA - added merge sort + corrected bug in insertion + testing them together --- test/mppa/lib/prng.c | 6 ++-- test/mppa/sort/Makefile | 52 +++++++++++++++++++++------- test/mppa/sort/insertion.c | 26 ++++++++------ test/mppa/sort/insertion.h | 2 +- test/mppa/sort/merge.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++ test/mppa/sort/merge.h | 7 ++++ test/mppa/sort/selection.c | 24 +++++++------ test/mppa/sort/selection.h | 2 +- test/mppa/sort/test.c | 33 ++++++++++++++++++ test/mppa/sort/test.h | 6 ++++ 10 files changed, 205 insertions(+), 38 deletions(-) create mode 100644 test/mppa/sort/merge.c create mode 100644 test/mppa/sort/merge.h create mode 100644 test/mppa/sort/test.c create mode 100644 test/mppa/sort/test.h (limited to 'test') diff --git a/test/mppa/lib/prng.c b/test/mppa/lib/prng.c index dfa97834..c902cc3e 100644 --- a/test/mppa/lib/prng.c +++ b/test/mppa/lib/prng.c @@ -9,11 +9,13 @@ static uint64_t current; void srand(uint64_t seed){ - seed = current; + //seed = current; + current=100; } uint64_t randlong(void){ - return (current = MULTIPLIER * current + INCREMENT); + //return (current = MULTIPLIER * current + INCREMENT); + return current--; } #ifdef __UNIT_TEST_PRNG__ diff --git a/test/mppa/sort/Makefile b/test/mppa/sort/Makefile index 1f4a0d51..ce86017d 100644 --- a/test/mppa/sort/Makefile +++ b/test/mppa/sort/Makefile @@ -1,35 +1,61 @@ PRNG=../lib/prng.c -insertion-test-x86: insertion.c $(PRNG) - gcc -g -D__UNIT_TEST_INSERTION__ -O2 -std=c99 $^ -o $@ +ALL= insertion-test-x86 insertion-test-k1c\ + selection-test-x86 selection-test-k1c\ + merge-test-x86 merge-test-k1c\ + test-x86 test-k1c -insertion-test-k1c: insertion.c $(PRNG) - k1-gcc -D__UNIT_TEST_INSERTION__ -O2 -std=c99 $^ -o $@ +all: $(ALL) -selection-test-x86: selection.c $(PRNG) - gcc -g -D__UNIT_TEST_SELECTION__ -O2 -std=c99 $^ -o $@ +%-test-x86: %.c $(PRNG) + gcc -g -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ -selection-test-k1c: selection.c $(PRNG) - k1-gcc -D__UNIT_TEST_SELECTION__ -O2 -std=c99 $^ -o $@ +%-test-k1c: %.c $(PRNG) + k1-gcc -g -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ + +test-x86: selection.c merge.c insertion.c test.c $(PRNG) + gcc -g -O2 -std=c99 $^ -o $@ + +test-k1c: selection.c merge.c insertion.c test.c $(PRNG) + k1-gcc -g -O2 -std=c99 $^ -o $@ .PHONY: unittest: unittest-x86 unittest-k1c .PHONY: -unittest-x86: insertion-test-x86 selection-test-x86 +check: check-x86 check-k1c + +.PHONY: +check-x86: test-x86 + @if ! ./$<; then\ + >&2 echo "ERROR x86: $< failed";\ + else\ + echo "x86: Test $< succeeded";\ + fi + +.PHONY: +check-k1c: test-k1c + @if ! k1-cluster -- ./$<; then\ + >&2 echo "ERROR k1c: $< failed";\ + else\ + echo "k1c: Test $< succeeded";\ + fi + +.PHONY: +unittest-x86: insertion-test-x86 selection-test-x86 merge-test-x86 @for test in $^; do\ if ! ./$$test; then\ - >&2 echo "ERROR: $$test failed";\ + >&2 echo "ERROR x86: $$test failed";\ else\ echo "x86: Test $$test Succeeded";\ fi;\ done .PHONY: -unittest-k1c: insertion-test-k1c selection-test-k1c +unittest-k1c: insertion-test-k1c selection-test-k1c merge-test-k1c @for test in $^; do\ if ! k1-cluster -- ./$$test; then\ - >&2 echo "ERROR: $$test failed";\ + >&2 echo "ERROR k1c: $$test failed";\ else\ echo "k1c: Test $$test Succeeded";\ fi;\ @@ -37,4 +63,4 @@ unittest-k1c: insertion-test-k1c selection-test-k1c .PHONY: clean: - rm -f insertion-test-x86 insertion-test-k1c selection-test-k1c selection-test-x86 + rm -f $(ALL) diff --git a/test/mppa/sort/insertion.c b/test/mppa/sort/insertion.c index 2c6065e7..88093b64 100644 --- a/test/mppa/sort/insertion.c +++ b/test/mppa/sort/insertion.c @@ -1,25 +1,31 @@ #include "../lib/prng.h" #include "../lib/types.h" -void swap(uint64_t *a, uint64_t *b){ +#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 size){ - if (size <= 0) +int insert_sort(uint64_t *res, const uint64_t *T){ + if (SIZE <= 0) return -1; - for (int i = 0 ; i < size ; i++) + for (int i = 0 ; i < SIZE ; i++) res[i] = T[i]; - for (int i = 0 ; i < size-1 ; i++){ + for (int i = 0 ; i < SIZE-1 ; i++){ if (res[i] > res[i+1]){ - swap(&res[i], &res[i+1]); - for (int j = i ; j > 1 ; j--) + swap_ins(&res[i], &res[i+1]); + for (int j = i ; j > 0 ; j--) if (res[j-1] > res[j]) - swap(&res[j-1], &res[j]); + swap_ins(&res[j-1], &res[j]); } } @@ -27,8 +33,6 @@ int insert_sort(uint64_t *res, const uint64_t *T, int size){ } #ifdef __UNIT_TEST_INSERTION__ -#define SIZE 100 - int main(void){ uint64_t T[SIZE]; uint64_t res[SIZE]; @@ -38,7 +42,7 @@ int main(void){ T[i] = randlong(); /* Sorting the table */ - if (insert_sort(res, T, SIZE) < 0) return -1; + if (insert_sort(res, T) < 0) return -1; /* Computing max(T) */ uint64_t max = T[0]; diff --git a/test/mppa/sort/insertion.h b/test/mppa/sort/insertion.h index 135b3bc1..6e37c5fe 100644 --- a/test/mppa/sort/insertion.h +++ b/test/mppa/sort/insertion.h @@ -1,6 +1,6 @@ #ifndef __INSERTION_H__ #define __INSERTION_H__ -int insert_sort(uint64_t *res, const uint64_t *T, int size); +int insert_sort(uint64_t *res, const uint64_t *T); #endif // __INSERTION_H__ diff --git a/test/mppa/sort/merge.c b/test/mppa/sort/merge.c new file mode 100644 index 00000000..63f662ac --- /dev/null +++ b/test/mppa/sort/merge.c @@ -0,0 +1,85 @@ +#include "../lib/prng.h" +#include "../lib/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, int64_t *B) +{ + int i = iLeft, j = iRight; + for (int 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; + + for(int i = 0; i < n; i++) + to[i] = from[i]; +} + +void BottomUpMergeSort(uint64_t *A, uint64_t *B) +{ + const int n = SIZE; + + for (int width = 1; width < n; width = 2 * width) + { + for (int 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){ + if (SIZE <= 0) + return -1; + + uint64_t B[SIZE]; + uint64_t *A = res; + for (int i = 0 ; i < SIZE ; i++) + A[i] = T[i]; + + BottomUpMergeSort(A, B); +} + +#ifdef __UNIT_TEST_MERGE__ +int main(void){ + uint64_t T[SIZE]; + uint64_t res[SIZE]; + srand(42); + + for (int 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 (int 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 index 432bbf49..89bc2c65 100644 --- a/test/mppa/sort/selection.c +++ b/test/mppa/sort/selection.c @@ -1,36 +1,40 @@ #include "../lib/prng.h" #include "../lib/types.h" -void swap(uint64_t *a, uint64_t *b){ +#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 selection_sort(uint64_t *res, const uint64_t *T, int size){ - if (size <= 0) +int select_sort(uint64_t *res, const uint64_t *T){ + if (SIZE <= 0) return -1; - for (int i = 0 ; i < size ; i++) + for (int i = 0 ; i < SIZE ; i++) res[i] = T[i]; - for (int j = 0 ; j < size ; j++){ + for (int j = 0 ; j < SIZE ; j++){ int i; int iMin = j; - for (i = j+1 ; i < size ; i++) + for (i = j+1 ; i < SIZE ; i++) if (res[i] < res[iMin]) iMin = i; if (iMin != j) - swap (&res[j], &res[iMin]); + swap_sel (&res[j], &res[iMin]); } return 0; } #ifdef __UNIT_TEST_SELECTION__ -#define SIZE 100 - int main(void){ uint64_t T[SIZE]; uint64_t res[SIZE]; @@ -40,7 +44,7 @@ int main(void){ T[i] = randlong(); /* Sorting the table */ - if (selection_sort(res, T, SIZE) < 0) return -1; + if (select_sort(res, T) < 0) return -1; /* Computing max(T) */ uint64_t max = T[0]; diff --git a/test/mppa/sort/selection.h b/test/mppa/sort/selection.h index b2b4aebe..92a6b461 100644 --- a/test/mppa/sort/selection.h +++ b/test/mppa/sort/selection.h @@ -1,6 +1,6 @@ #ifndef __SELECTION_H__ #define __SELECTION_H__ -int selection_sort(uint64_t *res, const uint64_t *T, int size); +int select_sort(uint64_t *res, const uint64_t *T); #endif // __SELECTION_H__ diff --git a/test/mppa/sort/test.c b/test/mppa/sort/test.c new file mode 100644 index 00000000..e5e14fef --- /dev/null +++ b/test/mppa/sort/test.c @@ -0,0 +1,33 @@ +#include "../lib/prng.h" +#include "../lib/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]; + srand(42); + + for (int 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 (int i = 0 ; i < SIZE ; i++){ + if (!(res1[i] == res2[i] && res2[i] == res3[i])) + return -4; + } + + return 0; +} 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 -- cgit From 8a77a2d41eb560ce9dbc3669971ccbc342743784 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 17 Apr 2018 15:41:14 +0200 Subject: MPPA - Added CompCert tests --- test/mppa/sort/Makefile | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/mppa/sort/Makefile b/test/mppa/sort/Makefile index ce86017d..69dfca23 100644 --- a/test/mppa/sort/Makefile +++ b/test/mppa/sort/Makefile @@ -3,7 +3,8 @@ PRNG=../lib/prng.c ALL= insertion-test-x86 insertion-test-k1c\ selection-test-x86 selection-test-k1c\ merge-test-x86 merge-test-k1c\ - test-x86 test-k1c + test-x86 test-k1c\ + test-ccomp all: $(ALL) @@ -19,12 +20,26 @@ test-x86: selection.c merge.c insertion.c test.c $(PRNG) test-k1c: selection.c merge.c insertion.c test.c $(PRNG) k1-gcc -g -O2 -std=c99 $^ -o $@ +%.s: %.c + ccomp -O2 -S $< -o $@ + +test-ccomp: selection.s merge.s insertion.s test.s $(subst .c,.s,$(PRNG)) + k1-gcc $^ -o $@ + .PHONY: unittest: unittest-x86 unittest-k1c .PHONY: check: check-x86 check-k1c +.PHONY: +compc-check: test-ccomp + @if ! k1-cluster -- ./$<; then\ + >&2 echo "ERROR k1c: $< failed";\ + else\ + echo "k1c: Test $< succeeded";\ + fi + .PHONY: check-x86: test-x86 @if ! ./$<; then\ -- cgit From 3997c0bc61ddbbceefd449a8007e7212add8ac4a Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 17 Apr 2018 16:30:26 +0200 Subject: MPPA - added all shifts --- test/mppa/.gitignore | 1 + test/mppa/general/.gitignore | 1 + test/mppa/lib/.gitignore | 2 ++ test/mppa/sort/.gitignore | 8 ++++++++ 4 files changed, 12 insertions(+) create mode 100644 test/mppa/.gitignore create mode 100644 test/mppa/general/.gitignore create mode 100644 test/mppa/lib/.gitignore create mode 100644 test/mppa/sort/.gitignore (limited to 'test') diff --git a/test/mppa/.gitignore b/test/mppa/.gitignore new file mode 100644 index 00000000..f03fc12c --- /dev/null +++ b/test/mppa/.gitignore @@ -0,0 +1 @@ +check diff --git a/test/mppa/general/.gitignore b/test/mppa/general/.gitignore new file mode 100644 index 00000000..ea1472ec --- /dev/null +++ b/test/mppa/general/.gitignore @@ -0,0 +1 @@ +output/ diff --git a/test/mppa/lib/.gitignore b/test/mppa/lib/.gitignore new file mode 100644 index 00000000..1879eaee --- /dev/null +++ b/test/mppa/lib/.gitignore @@ -0,0 +1,2 @@ +prng-test-k1c +prng-test-x86 diff --git a/test/mppa/sort/.gitignore b/test/mppa/sort/.gitignore new file mode 100644 index 00000000..e7dc9aa0 --- /dev/null +++ b/test/mppa/sort/.gitignore @@ -0,0 +1,8 @@ +insertion-test-k1c +insertion-test-x86 +merge-test-k1c +selection-test-k1c +test-k1c +merge-test-x86 +selection-test-x86 +test-x86 -- cgit From b17acc2e5f9c31a93164897c64c698fe8e490765 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 17 Apr 2018 16:33:11 +0200 Subject: MPPA - Forgot to uncomment debugging section of prng test --- test/mppa/lib/prng.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/mppa/lib/prng.c b/test/mppa/lib/prng.c index c902cc3e..dfa97834 100644 --- a/test/mppa/lib/prng.c +++ b/test/mppa/lib/prng.c @@ -9,13 +9,11 @@ static uint64_t current; void srand(uint64_t seed){ - //seed = current; - current=100; + seed = current; } uint64_t randlong(void){ - //return (current = MULTIPLIER * current + INCREMENT); - return current--; + return (current = MULTIPLIER * current + INCREMENT); } #ifdef __UNIT_TEST_PRNG__ -- cgit From b63085295d8495ff640f5eaff8b8ad52fc5c43d1 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 17 Apr 2018 17:03:52 +0200 Subject: MPPA - More shifts --- test/mppa/sort/merge.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/mppa/sort/merge.c b/test/mppa/sort/merge.c index 63f662ac..b2d41ce3 100644 --- a/test/mppa/sort/merge.c +++ b/test/mppa/sort/merge.c @@ -13,7 +13,7 @@ int min(int a, int b){ return (a < b)?a:b; } -void BottomUpMerge(const uint64_t *A, int iLeft, int iRight, int iEnd, int64_t *B) +void BottomUpMerge(const uint64_t *A, int iLeft, int iRight, int iEnd, uint64_t *B) { int i = iLeft, j = iRight; for (int k = iLeft; k < iEnd; k++) { @@ -59,6 +59,8 @@ int merge_sort(uint64_t *res, const uint64_t *T){ A[i] = T[i]; BottomUpMergeSort(A, B); + + return 0; } #ifdef __UNIT_TEST_MERGE__ -- cgit From eb3fd167668695c33f776cbb381c7664c3ec1858 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 17 Apr 2018 17:28:51 +0200 Subject: MPPA - Added Pmull -> now able to run the sort test --- test/mppa/Makefile | 6 +++++- test/mppa/sort/.gitignore | 1 + test/mppa/sort/Makefile | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 0e0b2eb2..3c1ab002 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -34,7 +34,11 @@ $(DIR)/output/%.bin.exp: $(DIR)/%.c FORCE: .PHONY: -check: $(TOK) +check: $(TOK) sort + +.PHONY: +sort: FORCE + (cd sort && make compc-check) .PHONY: clean: diff --git a/test/mppa/sort/.gitignore b/test/mppa/sort/.gitignore index e7dc9aa0..c8f4f4e5 100644 --- a/test/mppa/sort/.gitignore +++ b/test/mppa/sort/.gitignore @@ -6,3 +6,4 @@ test-k1c merge-test-x86 selection-test-x86 test-x86 +test-ccomp diff --git a/test/mppa/sort/Makefile b/test/mppa/sort/Makefile index 69dfca23..4a118875 100644 --- a/test/mppa/sort/Makefile +++ b/test/mppa/sort/Makefile @@ -35,9 +35,9 @@ check: check-x86 check-k1c .PHONY: compc-check: test-ccomp @if ! k1-cluster -- ./$<; then\ - >&2 echo "ERROR k1c: $< failed";\ + >&2 echo "ERROR k1c: sort $< failed";\ else\ - echo "k1c: Test $< succeeded";\ + echo "k1c: Test sort $< succeeded";\ fi .PHONY: -- cgit From 511acb8102b26ec0460f1d3c7ce21a9941f095ff Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 18 Apr 2018 14:03:48 +0200 Subject: MPPA - added a Matrix Multiply test --- test/mppa/mmult/Makefile | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ test/mppa/mmult/mmult.c | 54 +++++++++++++++++++++++++++++++++ test/mppa/mmult/mmult.h | 9 ++++++ 3 files changed, 140 insertions(+) create mode 100644 test/mppa/mmult/Makefile create mode 100644 test/mppa/mmult/mmult.c create mode 100644 test/mppa/mmult/mmult.h (limited to 'test') diff --git a/test/mppa/mmult/Makefile b/test/mppa/mmult/Makefile new file mode 100644 index 00000000..9cb5b9e7 --- /dev/null +++ b/test/mppa/mmult/Makefile @@ -0,0 +1,77 @@ +PRNG=../lib/prng.c + +ALL= mmult-test-x86 mmult-test-k1c\ + +all: $(ALL) + +%-test-x86: %.c $(PRNG) + gcc -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ + +%-test-k1c: %.c $(PRNG) + k1-gcc -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ + +#test-x86: selection.c merge.c insertion.c test.c $(PRNG) +# gcc -g -O2 -std=c99 $^ -o $@ +# +#test-k1c: selection.c merge.c insertion.c test.c $(PRNG) +# k1-gcc -g -O2 -std=c99 $^ -o $@ +# +#%.s: %.c +# ccomp -O2 -S $< -o $@ +# +#test-ccomp: selection.s merge.s insertion.s test.s $(subst .c,.s,$(PRNG)) +# k1-gcc $^ -o $@ + +.PHONY: +unittest: unittest-x86 unittest-k1c + +#.PHONY: +#check: check-x86 check-k1c + +#.PHONY: +#compc-check: test-ccomp +# @if ! k1-cluster -- ./$<; then\ +# >&2 echo "ERROR k1c: sort $< failed";\ +# else\ +# echo "k1c: Test sort $< succeeded";\ +# fi +# +#.PHONY: +#check-x86: test-x86 +# @if ! ./$<; then\ +# >&2 echo "ERROR x86: $< failed";\ +# else\ +# echo "x86: Test $< succeeded";\ +# fi +# +#.PHONY: +#check-k1c: test-k1c +# @if ! k1-cluster -- ./$<; then\ +# >&2 echo "ERROR k1c: $< failed";\ +# else\ +# echo "k1c: Test $< succeeded";\ +# fi + +.PHONY: +unittest-x86: mmult-test-x86 + @for test in $^; do\ + if ! ./$$test; then\ + >&2 echo "ERROR x86: $$test failed";\ + else\ + echo "x86: Test $$test Succeeded";\ + fi;\ + done + +.PHONY: +unittest-k1c: mmult-test-k1c + @for test in $^; do\ + if ! k1-cluster -- ./$$test; then\ + >&2 echo "ERROR k1c: $$test failed";\ + else\ + echo "k1c: Test $$test Succeeded";\ + fi;\ + done + +.PHONY: +clean: + rm -f $(ALL) diff --git a/test/mppa/mmult/mmult.c b/test/mppa/mmult/mmult.c new file mode 100644 index 00000000..04ac4605 --- /dev/null +++ b/test/mppa/mmult/mmult.c @@ -0,0 +1,54 @@ +#include "../lib/types.h" +#include "../lib/prng.h" + +#ifdef __UNIT_TEST_MMULT__ +#define SIZE 50 +#else +#include "test.h" +#endif + +void mmult_row(uint64_t C[][SIZE], uint64_t A[][SIZE], uint64_t B[][SIZE]){ + for (int i = 0 ; i < SIZE ; i++) + for (int j = 0 ; j < SIZE ; j++) + C[i][j] = 0; + + for (int i = 0 ; i < SIZE ; i++) + for (int j = 0 ; j < SIZE ; j++) + for (int 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]){ + for (int i = 0 ; i < SIZE ; i++) + for (int j = 0 ; j < SIZE ; j++) + C[i][j] = 0; + + for (int k = 0 ; k < SIZE ; k++) + for (int i = 0 ; i < SIZE ; i++) + for (int j = 0 ; j < SIZE ; j++) + C[i][j] += A[i][k] * B[k][j]; +} + +#ifdef __UNIT_TEST_MMULT__ +static uint64_t C1[SIZE][SIZE], C2[SIZE][SIZE], A[SIZE][SIZE], B[SIZE][SIZE]; + +int main(void){ + srand(42); + + for (int i = 0 ; i < SIZE ; i++) + for (int j = 0 ; j < SIZE ; j++){ + A[i][j] = randlong(); + B[i][j] = randlong(); + } + + mmult_row(C1, A, B); + mmult_col(C2, A, B); + + for (int i = 0 ; i < SIZE ; i++) + for (int j = 0 ; j < SIZE ; j++) + if (C1[i][j] != C2[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..50c04afd --- /dev/null +++ b/test/mppa/mmult/mmult.h @@ -0,0 +1,9 @@ +#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); + +#endif /* __MMULT_H__ */ -- cgit From b7021853e651ddde91450cc83d3c77c5377efc06 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 18 Apr 2018 14:27:44 +0200 Subject: MPPA - added Oaddrsymbol -> now able to run the matrix mult test --- test/mppa/mmult/.gitignore | 3 ++ test/mppa/mmult/Makefile | 74 +++++++++++++++++++++++----------------------- test/mppa/mmult/mmult.c | 2 ++ 3 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 test/mppa/mmult/.gitignore (limited to 'test') diff --git a/test/mppa/mmult/.gitignore b/test/mppa/mmult/.gitignore new file mode 100644 index 00000000..5883d367 --- /dev/null +++ b/test/mppa/mmult/.gitignore @@ -0,0 +1,3 @@ +mmult-test-k1c +mmult-test-x86 +test-ccomp diff --git a/test/mppa/mmult/Makefile b/test/mppa/mmult/Makefile index 9cb5b9e7..bb4506bf 100644 --- a/test/mppa/mmult/Makefile +++ b/test/mppa/mmult/Makefile @@ -10,47 +10,47 @@ all: $(ALL) %-test-k1c: %.c $(PRNG) k1-gcc -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ -#test-x86: selection.c merge.c insertion.c test.c $(PRNG) -# gcc -g -O2 -std=c99 $^ -o $@ -# -#test-k1c: selection.c merge.c insertion.c test.c $(PRNG) -# k1-gcc -g -O2 -std=c99 $^ -o $@ -# -#%.s: %.c -# ccomp -O2 -S $< -o $@ -# -#test-ccomp: selection.s merge.s insertion.s test.s $(subst .c,.s,$(PRNG)) -# k1-gcc $^ -o $@ +test-x86: mmult.c $(PRNG) + gcc -g -O2 -std=c99 $^ -o $@ + +test-k1c: mmult.c $(PRNG) + k1-gcc -g -O2 -std=c99 $^ -o $@ + +%.s: %.c + ccomp -O2 -S $< -o $@ + +test-ccomp: mmult.s $(subst .c,.s,$(PRNG)) + k1-gcc $^ -o $@ .PHONY: unittest: unittest-x86 unittest-k1c -#.PHONY: -#check: check-x86 check-k1c - -#.PHONY: -#compc-check: test-ccomp -# @if ! k1-cluster -- ./$<; then\ -# >&2 echo "ERROR k1c: sort $< failed";\ -# else\ -# echo "k1c: Test sort $< succeeded";\ -# fi -# -#.PHONY: -#check-x86: test-x86 -# @if ! ./$<; then\ -# >&2 echo "ERROR x86: $< failed";\ -# else\ -# echo "x86: Test $< succeeded";\ -# fi -# -#.PHONY: -#check-k1c: test-k1c -# @if ! k1-cluster -- ./$<; then\ -# >&2 echo "ERROR k1c: $< failed";\ -# else\ -# echo "k1c: Test $< succeeded";\ -# fi +.PHONY: +check: check-x86 check-k1c + +.PHONY: +compc-check: test-ccomp + @if ! k1-cluster -- ./$<; then\ + >&2 echo "ERROR k1c: sort $< failed";\ + else\ + echo "k1c: Test sort $< succeeded";\ + fi + +.PHONY: +check-x86: test-x86 + @if ! ./$<; then\ + >&2 echo "ERROR x86: $< failed";\ + else\ + echo "x86: Test $< succeeded";\ + fi + +.PHONY: +check-k1c: test-k1c + @if ! k1-cluster -- ./$<; then\ + >&2 echo "ERROR k1c: $< failed";\ + else\ + echo "k1c: Test $< succeeded";\ + fi .PHONY: unittest-x86: mmult-test-x86 diff --git a/test/mppa/mmult/mmult.c b/test/mppa/mmult/mmult.c index 04ac4605..16dcf34c 100644 --- a/test/mppa/mmult/mmult.c +++ b/test/mppa/mmult/mmult.c @@ -1,6 +1,8 @@ #include "../lib/types.h" #include "../lib/prng.h" +#define __UNIT_TEST_MMULT__ + #ifdef __UNIT_TEST_MMULT__ #define SIZE 50 #else -- cgit From 41a048fa4bb9ddefd4e4acff2207251bb3ddbf06 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 18 Apr 2018 16:44:43 +0200 Subject: MPPA - Added divide & conqueer test matmul --- test/mppa/mmult/mmult.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++-- test/mppa/mmult/mmult.h | 1 + 2 files changed, 87 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mppa/mmult/mmult.c b/test/mppa/mmult/mmult.c index 16dcf34c..c9e7ad5e 100644 --- a/test/mppa/mmult/mmult.c +++ b/test/mppa/mmult/mmult.c @@ -31,8 +31,91 @@ void mmult_col(uint64_t C[][SIZE], uint64_t A[][SIZE], uint64_t B[][SIZE]){ 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)) + +int strassen_mul(mblock *C, const mblock *A, const mblock *B){ + const int size = C->imax - C->imin; + + for (int i = 0 ; i < size ; i++) + for (int j = 0 ; j < size ; j++) + for (int 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;\ + } + +int strassen_part(mblock *C, const mblock *A, const mblock *B); + +void strassen_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); + + strassen_part(&Cb, &Ab, &Bb); +} + + +int strassen_part(mblock *C, const mblock *A, const mblock *B){ + const int size = C->imax - C->imin; + + if (size % 2 == 1) + strassen_mul(C, A, B); + else{ + /* C_00 = A_00 B_00 + A_01 B_10 */ + strassen_wrap(C, 0, 0, A, 0, 0, B, 0, 0); + strassen_wrap(C, 0, 0, A, 0, 1, B, 1, 0); + + /* C_10 = A_10 B_00 + A_11 B_10 */ + strassen_wrap(C, 1, 0, A, 1, 0, B, 0, 0); + strassen_wrap(C, 1, 0, A, 1, 1, B, 1, 0); + + /* C_01 = A_00 B_01 + A_01 B_11 */ + strassen_wrap(C, 0, 1, A, 0, 0, B, 0, 1); + strassen_wrap(C, 0, 1, A, 0, 1, B, 1, 1); + + /* C_11 = A_10 B_01 + A_11 B_11 */ + strassen_wrap(C, 1, 1, A, 1, 0, B, 0, 1); + strassen_wrap(C, 1, 1, A, 1, 1, B, 1, 1); + } + +} + +void mmult_strassen(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}; + + strassen_part(&Cb, &Ab, &Bb); +} + #ifdef __UNIT_TEST_MMULT__ -static uint64_t C1[SIZE][SIZE], C2[SIZE][SIZE], A[SIZE][SIZE], B[SIZE][SIZE]; +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); @@ -45,10 +128,11 @@ int main(void){ mmult_row(C1, A, B); mmult_col(C2, A, B); + mmult_strassen(C3, A, B); for (int i = 0 ; i < SIZE ; i++) for (int j = 0 ; j < SIZE ; j++) - if (C1[i][j] != C2[i][j]) + if (!(C1[i][j] == C2[i][j] && C1[i][j] == C3[i][j])) return -1; return 0; diff --git a/test/mppa/mmult/mmult.h b/test/mppa/mmult/mmult.h index 50c04afd..3721784a 100644 --- a/test/mppa/mmult/mmult.h +++ b/test/mppa/mmult/mmult.h @@ -5,5 +5,6 @@ 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__ */ -- cgit From aa25ec270b651186154523ec71a3888b50994d70 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Fri, 20 Apr 2018 10:31:56 +0200 Subject: MPPA - Oshrximm + Mgetparam + FP is GPR10 + bug Added Oshrximm and Mgetparam -> mmult.c divide & conqueer generates FP is now GPR10 instead of being a mix of GPR30 and GPR32 Corrected a bug where Pgoto and Pj_l were given the same interpretation, where in fact there's a fundamental difference : Pgoto is supposed to have a function name (symbol), while Pj_l is supposed to have a label name (print_label). This led to having undefinite labels in the code. --- test/mppa/mmult/mmult.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'test') diff --git a/test/mppa/mmult/mmult.c b/test/mppa/mmult/mmult.c index c9e7ad5e..dcbcfe17 100644 --- a/test/mppa/mmult/mmult.c +++ b/test/mppa/mmult/mmult.c @@ -39,7 +39,7 @@ typedef struct 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)) -int strassen_mul(mblock *C, const mblock *A, const mblock *B){ +void divac_mul(mblock *C, const mblock *A, const mblock *B){ const int size = C->imax - C->imin; for (int i = 0 ; i < size ; i++) @@ -67,50 +67,50 @@ int strassen_mul(mblock *C, const mblock *A, const mblock *B){ newb.jmax = (block)->jmax;\ } -int strassen_part(mblock *C, const mblock *A, const mblock *B); +void divac_part(mblock *C, const mblock *A, const mblock *B); -void strassen_wrap(mblock *C , char IC, char JC, +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); - strassen_part(&Cb, &Ab, &Bb); + divac_part(&Cb, &Ab, &Bb); } -int strassen_part(mblock *C, const mblock *A, const mblock *B){ +void divac_part(mblock *C, const mblock *A, const mblock *B){ const int size = C->imax - C->imin; if (size % 2 == 1) - strassen_mul(C, A, B); + divac_mul(C, A, B); else{ /* C_00 = A_00 B_00 + A_01 B_10 */ - strassen_wrap(C, 0, 0, A, 0, 0, B, 0, 0); - strassen_wrap(C, 0, 0, A, 0, 1, B, 1, 0); + 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 */ - strassen_wrap(C, 1, 0, A, 1, 0, B, 0, 0); - strassen_wrap(C, 1, 0, A, 1, 1, B, 1, 0); + 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 */ - strassen_wrap(C, 0, 1, A, 0, 0, B, 0, 1); - strassen_wrap(C, 0, 1, A, 0, 1, B, 1, 1); + 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 */ - strassen_wrap(C, 1, 1, A, 1, 0, B, 0, 1); - strassen_wrap(C, 1, 1, A, 1, 1, B, 1, 1); + divac_wrap(C, 1, 1, A, 1, 0, B, 0, 1); + divac_wrap(C, 1, 1, A, 1, 1, B, 1, 1); } } -void mmult_strassen(uint64_t C[][SIZE], uint64_t A[][SIZE], uint64_t B[][SIZE]){ +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}; - strassen_part(&Cb, &Ab, &Bb); + divac_part(&Cb, &Ab, &Bb); } #ifdef __UNIT_TEST_MMULT__ @@ -128,7 +128,7 @@ int main(void){ mmult_row(C1, A, B); mmult_col(C2, A, B); - mmult_strassen(C3, A, B); + mmult_divac(C3, A, B); for (int i = 0 ; i < SIZE ; i++) for (int j = 0 ; j < SIZE ; j++) -- cgit From b1ab210e798c911a5e4952ed244e581a18c86312 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 24 Apr 2018 10:48:24 +0200 Subject: MPPA - refined tests. Bug in mmult - need to generate O0 to debug easier --- test/mppa/Makefile | 6 +++++- test/mppa/generate.sh | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 3c1ab002..faeb7c62 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -34,12 +34,16 @@ $(DIR)/output/%.bin.exp: $(DIR)/%.c FORCE: .PHONY: -check: $(TOK) sort +check: $(TOK) sort mmult .PHONY: sort: FORCE (cd sort && make compc-check) +.PHONY: +mmult: FORCE + (cd mmult && make compc-check) + .PHONY: clean: rm -f $(DIR)/*.alloctrace diff --git a/test/mppa/generate.sh b/test/mppa/generate.sh index cfe6f7bb..cfb0a119 100644 --- a/test/mppa/generate.sh +++ b/test/mppa/generate.sh @@ -9,4 +9,6 @@ if [ ! -f $cfile ]; then shift; continue fi +mkdir -p $(dirname $writefile) + sed -n "s/^.*\/\*\s*RETURN VALUE:\s*\([0-9]*\)\s*\*\//\1/p" $1 > $2 -- cgit From 31d718c4b7fc81eced145de585b371bd01d3fabc Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 25 Apr 2018 13:37:15 +0200 Subject: MPPA - Corrected messages on test/mppa/mmult/Makefile --- test/mppa/mmult/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mppa/mmult/Makefile b/test/mppa/mmult/Makefile index bb4506bf..edea61ae 100644 --- a/test/mppa/mmult/Makefile +++ b/test/mppa/mmult/Makefile @@ -31,9 +31,9 @@ check: check-x86 check-k1c .PHONY: compc-check: test-ccomp @if ! k1-cluster -- ./$<; then\ - >&2 echo "ERROR k1c: sort $< failed";\ + >&2 echo "ERROR k1c: mmult $< failed";\ else\ - echo "k1c: Test sort $< succeeded";\ + echo "k1c: Test mmult $< succeeded";\ fi .PHONY: -- cgit From 28db3119a6fef8a6ef487b414f7851a065db0889 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 25 Apr 2018 13:37:53 +0200 Subject: MPPA - Added test for division int by 2 --- test/mppa/Makefile | 2 +- test/mppa/general/div2.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/mppa/general/div2.c (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index faeb7c62..b210efaf 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,7 +1,7 @@ DIR=general BINDIR=bin ASMDIR=asm -TESTNAMES=simple call branch for forvar forvarl branchz branchzu +TESTNAMES=simple call branch for forvar forvarl branchz branchzu div2 CCOMP=../../ccomp #TESTS=$(addprefix $(DIR)/,$(TESTNAMES)) diff --git a/test/mppa/general/div2.c b/test/mppa/general/div2.c new file mode 100644 index 00000000..ec73b32d --- /dev/null +++ b/test/mppa/general/div2.c @@ -0,0 +1,22 @@ +#define SIZE 10 + +int main(void){ + int a[SIZE], b[SIZE], c[SIZE]; + int i; + + for (i = 0 ; i < SIZE ; i++){ + a[i] = i-5; + b[i] = -i+2; + c[i] = (a[i] + b[i]) / 2; + } + /* a = {-5, -4, .., 5} + * b = { 2, 1, .., -8} + */ + + for (i = 0 ; i < SIZE ; i++) + if (c[i] != -1) + return c[i]; + + return 42; +} +/* RETURN VALUE: 42 */ -- cgit From aa26db13f4daedec371a17ee7f79ecce7f8fb60f Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 25 Apr 2018 15:26:28 +0200 Subject: MPPA - Added coverage test --- test/mppa/Makefile | 5 +++++ test/mppa/asm_coverage | 1 + test/mppa/coverage.sh | 17 +++++++++++++++++ test/mppa/coverage_helper.py | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 160000 test/mppa/asm_coverage create mode 100644 test/mppa/coverage.sh create mode 100644 test/mppa/coverage_helper.py (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index b210efaf..87315f6e 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -36,6 +36,11 @@ FORCE: .PHONY: check: $(TOK) sort mmult +.PHONY: +coverage: $(ASM) + bash coverage.sh $(DIR)/$(ASMDIR) + + .PHONY: sort: FORCE (cd sort && make compc-check) diff --git a/test/mppa/asm_coverage b/test/mppa/asm_coverage new file mode 160000 index 00000000..5bdb081b --- /dev/null +++ b/test/mppa/asm_coverage @@ -0,0 +1 @@ +Subproject commit 5bdb081bc5fd4962315e960af3c539f2ddd24477 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..f886264c --- /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", "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 -- cgit From 3cecb184dc53baf94ac1b98ec392f27576106d35 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 25 Apr 2018 15:56:51 +0200 Subject: MPPA - we now compare the results of our tests with k1-gcc --- test/mppa/Makefile | 11 ++++++----- test/mppa/asm_coverage | 2 +- test/mppa/generate.sh | 5 ++++- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 87315f6e..d1b732d8 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -10,6 +10,7 @@ TOK=$(addprefix $(DIR)/$(BINDIR)/,$(addsuffix .tok,$(TESTNAMES))) ASM=$(addprefix $(DIR)/$(ASMDIR)/,$(addsuffix .s,$(TESTNAMES))) DEBUG:=$(if $(DEBUG),"-dall",) +.PHONY: all all: $(ELF) nobin: $(ASM) @@ -33,23 +34,23 @@ $(DIR)/output/%.bin.exp: $(DIR)/%.c .PHONY: FORCE FORCE: -.PHONY: +.PHONY: check check: $(TOK) sort mmult -.PHONY: +.PHONY: coverage coverage: $(ASM) bash coverage.sh $(DIR)/$(ASMDIR) -.PHONY: +.PHONY: sort sort: FORCE (cd sort && make compc-check) -.PHONY: +.PHONY: mmult mmult: FORCE (cd mmult && make compc-check) -.PHONY: +.PHONY: clean clean: rm -f $(DIR)/*.alloctrace rm -f $(DIR)/*.cm diff --git a/test/mppa/asm_coverage b/test/mppa/asm_coverage index 5bdb081b..88898ab2 160000 --- a/test/mppa/asm_coverage +++ b/test/mppa/asm_coverage @@ -1 +1 @@ -Subproject commit 5bdb081bc5fd4962315e960af3c539f2ddd24477 +Subproject commit 88898ab230e813d5d03dc901ba4b906d2ef6bbb0 diff --git a/test/mppa/generate.sh b/test/mppa/generate.sh index cfb0a119..765128d4 100644 --- a/test/mppa/generate.sh +++ b/test/mppa/generate.sh @@ -11,4 +11,7 @@ fi mkdir -p $(dirname $writefile) -sed -n "s/^.*\/\*\s*RETURN VALUE:\s*\([0-9]*\)\s*\*\//\1/p" $1 > $2 +#sed -n "s/^.*\/\*\s*RETURN VALUE:\s*\([0-9]*\)\s*\*\//\1/p" $1 > $2 +tmpbin=/tmp/k1-$(basename $1)-bin +k1-gcc -O0 $1 -o $tmpbin +(k1-cluster -- $tmpbin; echo $? > $2) -- cgit From 432bff5418d4789ba4187ffdd6ce89a29d58962a Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Thu, 26 Apr 2018 11:36:02 +0200 Subject: MPPA - Added a lot more unit tests + refined coverage --- test/mppa/Makefile | 2 +- test/mppa/asm_coverage | 2 +- test/mppa/coverage_helper.py | 2 +- test/mppa/general/addw.c | 5 +++++ test/mppa/general/andd.c | 5 +++++ test/mppa/general/andw.c | 5 +++++ test/mppa/general/cb.deqz.c | 9 +++++++++ test/mppa/general/cb.dgez.c | 9 +++++++++ test/mppa/general/cb.dgtz.c | 9 +++++++++ test/mppa/general/cb.dlez.c | 9 +++++++++ test/mppa/general/cb.dltz.c | 9 +++++++++ test/mppa/general/cb.dnez.c | 9 +++++++++ test/mppa/general/cb.wgez.c | 9 +++++++++ test/mppa/general/cb.wgtz.c | 9 +++++++++ test/mppa/general/cb.wlez.c | 9 +++++++++ test/mppa/general/cb.wltz.c | 9 +++++++++ test/mppa/general/compd.eq.c | 4 ++++ test/mppa/general/compd.geu.c | 4 ++++ test/mppa/general/compd.gt.c | 4 ++++ test/mppa/general/compd.gtu.c | 4 ++++ test/mppa/general/compd.le.c | 4 ++++ test/mppa/general/compd.leu.c | 4 ++++ test/mppa/general/compd.lt.c | 4 ++++ test/mppa/general/compd.ltu.c | 4 ++++ test/mppa/general/compd.ne.c | 4 ++++ test/mppa/general/compw.eq.c | 4 ++++ test/mppa/general/compw.geu.c | 4 ++++ test/mppa/general/compw.gt.c | 4 ++++ test/mppa/general/compw.gtu.c | 4 ++++ test/mppa/general/compw.le.c | 4 ++++ test/mppa/general/compw.leu.c | 4 ++++ test/mppa/general/compw.lt.c | 4 ++++ test/mppa/general/compw.ltu.c | 4 ++++ test/mppa/general/compw.ne.c | 4 ++++ test/mppa/general/lbs.c | 5 +++++ test/mppa/general/lbz.c | 5 +++++ test/mppa/general/muld.c | 5 +++++ test/mppa/general/mulw.c | 5 +++++ test/mppa/general/negd.c | 6 ++++++ test/mppa/general/ord.c | 5 +++++ test/mppa/general/sbfd.c | 5 +++++ test/mppa/general/sbfw.c | 5 +++++ test/mppa/general/sllw.c | 5 +++++ test/mppa/general/srad.c | 5 +++++ test/mppa/general/srld.c | 5 +++++ test/mppa/general/xord.c | 5 +++++ 46 files changed, 241 insertions(+), 3 deletions(-) create mode 100644 test/mppa/general/addw.c create mode 100644 test/mppa/general/andd.c create mode 100644 test/mppa/general/andw.c create mode 100644 test/mppa/general/cb.deqz.c create mode 100644 test/mppa/general/cb.dgez.c create mode 100644 test/mppa/general/cb.dgtz.c create mode 100644 test/mppa/general/cb.dlez.c create mode 100644 test/mppa/general/cb.dltz.c create mode 100644 test/mppa/general/cb.dnez.c create mode 100644 test/mppa/general/cb.wgez.c create mode 100644 test/mppa/general/cb.wgtz.c create mode 100644 test/mppa/general/cb.wlez.c create mode 100644 test/mppa/general/cb.wltz.c create mode 100644 test/mppa/general/compd.eq.c create mode 100644 test/mppa/general/compd.geu.c create mode 100644 test/mppa/general/compd.gt.c create mode 100644 test/mppa/general/compd.gtu.c create mode 100644 test/mppa/general/compd.le.c create mode 100644 test/mppa/general/compd.leu.c create mode 100644 test/mppa/general/compd.lt.c create mode 100644 test/mppa/general/compd.ltu.c create mode 100644 test/mppa/general/compd.ne.c create mode 100644 test/mppa/general/compw.eq.c create mode 100644 test/mppa/general/compw.geu.c create mode 100644 test/mppa/general/compw.gt.c create mode 100644 test/mppa/general/compw.gtu.c create mode 100644 test/mppa/general/compw.le.c create mode 100644 test/mppa/general/compw.leu.c create mode 100644 test/mppa/general/compw.lt.c create mode 100644 test/mppa/general/compw.ltu.c create mode 100644 test/mppa/general/compw.ne.c create mode 100644 test/mppa/general/lbs.c create mode 100644 test/mppa/general/lbz.c create mode 100644 test/mppa/general/muld.c create mode 100644 test/mppa/general/mulw.c create mode 100644 test/mppa/general/negd.c create mode 100644 test/mppa/general/ord.c create mode 100644 test/mppa/general/sbfd.c create mode 100644 test/mppa/general/sbfw.c create mode 100644 test/mppa/general/sllw.c create mode 100644 test/mppa/general/srad.c create mode 100644 test/mppa/general/srld.c create mode 100644 test/mppa/general/xord.c (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index d1b732d8..ffea4c30 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,7 +1,7 @@ DIR=general BINDIR=bin ASMDIR=asm -TESTNAMES=simple call branch for forvar forvarl branchz branchzu div2 +TESTNAMES=$(notdir $(subst .c,,$(wildcard $(DIR)/*.c))) CCOMP=../../ccomp #TESTS=$(addprefix $(DIR)/,$(TESTNAMES)) diff --git a/test/mppa/asm_coverage b/test/mppa/asm_coverage index 88898ab2..63195a53 160000 --- a/test/mppa/asm_coverage +++ b/test/mppa/asm_coverage @@ -1 +1 @@ -Subproject commit 88898ab230e813d5d03dc901ba4b906d2ef6bbb0 +Subproject commit 63195a533f3a7f93e8e8ebad0683b176041e09d4 diff --git a/test/mppa/coverage_helper.py b/test/mppa/coverage_helper.py index f886264c..b086aca9 100644 --- a/test/mppa/coverage_helper.py +++ b/test/mppa/coverage_helper.py @@ -24,7 +24,7 @@ for inst in occurs: 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", "dnez", + for mod in ("wnez", "weqz", "wltz", "wgez", "wlez", "wgtz", "deqz", "dnez", "dltz", "dgez", "dlez", "dgtz"): pruned_occurs[inst_no_a + "." + mod] = 1 else: diff --git a/test/mppa/general/addw.c b/test/mppa/general/addw.c new file mode 100644 index 00000000..842b0de7 --- /dev/null +++ b/test/mppa/general/addw.c @@ -0,0 +1,5 @@ +int main(void){ + int a = 5; + int b = -3; + return a+b; +} diff --git a/test/mppa/general/andd.c b/test/mppa/general/andd.c new file mode 100644 index 00000000..57c23585 --- /dev/null +++ b/test/mppa/general/andd.c @@ -0,0 +1,5 @@ +int main(void){ + long long a = 5; + long long b = -3; + return a&b; +} diff --git a/test/mppa/general/andw.c b/test/mppa/general/andw.c new file mode 100644 index 00000000..a10f1203 --- /dev/null +++ b/test/mppa/general/andw.c @@ -0,0 +1,5 @@ +int main(void){ + int a = 5; + int b = -3; + return a&b; +} diff --git a/test/mppa/general/cb.deqz.c b/test/mppa/general/cb.deqz.c new file mode 100644 index 00000000..c4f639fd --- /dev/null +++ b/test/mppa/general/cb.deqz.c @@ -0,0 +1,9 @@ +#define TYPE long long + +int main(void){ + TYPE a = 6; + TYPE b = -4; + if (0 != a) + return 42; + return 0; +} diff --git a/test/mppa/general/cb.dgez.c b/test/mppa/general/cb.dgez.c new file mode 100644 index 00000000..3d1caf1e --- /dev/null +++ b/test/mppa/general/cb.dgez.c @@ -0,0 +1,9 @@ +#define TYPE long long + +int main(void){ + TYPE a = 6; + TYPE b = -4; + if (0 > a) + return 42; + return 0; +} diff --git a/test/mppa/general/cb.dgtz.c b/test/mppa/general/cb.dgtz.c new file mode 100644 index 00000000..9c0c9ea2 --- /dev/null +++ b/test/mppa/general/cb.dgtz.c @@ -0,0 +1,9 @@ +#define TYPE long long + +int main(void){ + TYPE a = 6; + TYPE b = -4; + if (0 >= a) + return 42; + return 0; +} diff --git a/test/mppa/general/cb.dlez.c b/test/mppa/general/cb.dlez.c new file mode 100644 index 00000000..021bb16d --- /dev/null +++ b/test/mppa/general/cb.dlez.c @@ -0,0 +1,9 @@ +#define TYPE long long + +int main(void){ + TYPE a = 6; + TYPE b = -4; + if (a > 0) + return 42; + return 0; +} diff --git a/test/mppa/general/cb.dltz.c b/test/mppa/general/cb.dltz.c new file mode 100644 index 00000000..d6c59d03 --- /dev/null +++ b/test/mppa/general/cb.dltz.c @@ -0,0 +1,9 @@ +#define TYPE long long + +int main(void){ + TYPE a = 6; + TYPE b = -4; + if (a >= 0) + return 42; + return 0; +} diff --git a/test/mppa/general/cb.dnez.c b/test/mppa/general/cb.dnez.c new file mode 100644 index 00000000..99ecf84e --- /dev/null +++ b/test/mppa/general/cb.dnez.c @@ -0,0 +1,9 @@ +#define TYPE long long + +int main(void){ + TYPE a = 6; + TYPE b = -4; + if (0 == a) + return 42; + return 0; +} diff --git a/test/mppa/general/cb.wgez.c b/test/mppa/general/cb.wgez.c new file mode 100644 index 00000000..8226c397 --- /dev/null +++ b/test/mppa/general/cb.wgez.c @@ -0,0 +1,9 @@ +#define TYPE int + +int main(void){ + TYPE a = 6; + TYPE b = -4; + if (0 > a) + return 42; + return 0; +} diff --git a/test/mppa/general/cb.wgtz.c b/test/mppa/general/cb.wgtz.c new file mode 100644 index 00000000..005e552b --- /dev/null +++ b/test/mppa/general/cb.wgtz.c @@ -0,0 +1,9 @@ +#define TYPE int + +int main(void){ + TYPE a = 6; + TYPE b = -4; + if (0 >= a) + return 42; + return 0; +} diff --git a/test/mppa/general/cb.wlez.c b/test/mppa/general/cb.wlez.c new file mode 100644 index 00000000..4393003b --- /dev/null +++ b/test/mppa/general/cb.wlez.c @@ -0,0 +1,9 @@ +#define TYPE int + +int main(void){ + TYPE a = 6; + TYPE b = -4; + if (a > 0) + return 42; + return 0; +} diff --git a/test/mppa/general/cb.wltz.c b/test/mppa/general/cb.wltz.c new file mode 100644 index 00000000..76d49f56 --- /dev/null +++ b/test/mppa/general/cb.wltz.c @@ -0,0 +1,9 @@ +#define TYPE int + +int main(void){ + TYPE a = 6; + TYPE b = -4; + if (a >= 0) + return 42; + return 0; +} diff --git a/test/mppa/general/compd.eq.c b/test/mppa/general/compd.eq.c new file mode 100644 index 00000000..9b3e3a0d --- /dev/null +++ b/test/mppa/general/compd.eq.c @@ -0,0 +1,4 @@ +int main(void){ + long long a = 5, b = -2; + return (a == b); +} diff --git a/test/mppa/general/compd.geu.c b/test/mppa/general/compd.geu.c new file mode 100644 index 00000000..d168a6a7 --- /dev/null +++ b/test/mppa/general/compd.geu.c @@ -0,0 +1,4 @@ +int main(void){ + unsigned long long a = 5, b = -2; + return (a >= b); +} diff --git a/test/mppa/general/compd.gt.c b/test/mppa/general/compd.gt.c new file mode 100644 index 00000000..768e57fc --- /dev/null +++ b/test/mppa/general/compd.gt.c @@ -0,0 +1,4 @@ +int main(void){ + long long a = 5, b = -2; + return (a > b); +} diff --git a/test/mppa/general/compd.gtu.c b/test/mppa/general/compd.gtu.c new file mode 100644 index 00000000..5ac1910a --- /dev/null +++ b/test/mppa/general/compd.gtu.c @@ -0,0 +1,4 @@ +int main(void){ + unsigned long long a = 5, b = -2; + return (a > b); +} diff --git a/test/mppa/general/compd.le.c b/test/mppa/general/compd.le.c new file mode 100644 index 00000000..b493f661 --- /dev/null +++ b/test/mppa/general/compd.le.c @@ -0,0 +1,4 @@ +int main(void){ + long long a = 5, b = -2; + return (a <= b); +} diff --git a/test/mppa/general/compd.leu.c b/test/mppa/general/compd.leu.c new file mode 100644 index 00000000..8bb640b1 --- /dev/null +++ b/test/mppa/general/compd.leu.c @@ -0,0 +1,4 @@ +int main(void){ + unsigned long long a = 5, b = -2; + return (a <= b); +} diff --git a/test/mppa/general/compd.lt.c b/test/mppa/general/compd.lt.c new file mode 100644 index 00000000..04a92556 --- /dev/null +++ b/test/mppa/general/compd.lt.c @@ -0,0 +1,4 @@ +int main(void){ + long long a = 5, b = -2; + return (a < b); +} diff --git a/test/mppa/general/compd.ltu.c b/test/mppa/general/compd.ltu.c new file mode 100644 index 00000000..bbd901f6 --- /dev/null +++ b/test/mppa/general/compd.ltu.c @@ -0,0 +1,4 @@ +int main(void){ + unsigned long long a = 5, b = -2; + return (a < b); +} diff --git a/test/mppa/general/compd.ne.c b/test/mppa/general/compd.ne.c new file mode 100644 index 00000000..01c52254 --- /dev/null +++ b/test/mppa/general/compd.ne.c @@ -0,0 +1,4 @@ +int main(void){ + unsigned long long a = 5, b = -2; + return (a != b); +} diff --git a/test/mppa/general/compw.eq.c b/test/mppa/general/compw.eq.c new file mode 100644 index 00000000..f030d86b --- /dev/null +++ b/test/mppa/general/compw.eq.c @@ -0,0 +1,4 @@ +int main(void){ + int a = 5, b = -2; + return (a == b); +} diff --git a/test/mppa/general/compw.geu.c b/test/mppa/general/compw.geu.c new file mode 100644 index 00000000..866f0b47 --- /dev/null +++ b/test/mppa/general/compw.geu.c @@ -0,0 +1,4 @@ +int main(void){ + unsigned int a = 5, b = -2; + return (a >= b); +} diff --git a/test/mppa/general/compw.gt.c b/test/mppa/general/compw.gt.c new file mode 100644 index 00000000..6cde8622 --- /dev/null +++ b/test/mppa/general/compw.gt.c @@ -0,0 +1,4 @@ +int main(void){ + int a = 5, b = -2; + return (a > b); +} diff --git a/test/mppa/general/compw.gtu.c b/test/mppa/general/compw.gtu.c new file mode 100644 index 00000000..b2e74594 --- /dev/null +++ b/test/mppa/general/compw.gtu.c @@ -0,0 +1,4 @@ +int main(void){ + unsigned int a = 5, b = -2; + return (a > b); +} diff --git a/test/mppa/general/compw.le.c b/test/mppa/general/compw.le.c new file mode 100644 index 00000000..8f33e064 --- /dev/null +++ b/test/mppa/general/compw.le.c @@ -0,0 +1,4 @@ +int main(void){ + int a = 5, b = -2; + return (a <= b); +} diff --git a/test/mppa/general/compw.leu.c b/test/mppa/general/compw.leu.c new file mode 100644 index 00000000..fde558eb --- /dev/null +++ b/test/mppa/general/compw.leu.c @@ -0,0 +1,4 @@ +int main(void){ + unsigned int a = 5, b = -2; + return (a <= b); +} diff --git a/test/mppa/general/compw.lt.c b/test/mppa/general/compw.lt.c new file mode 100644 index 00000000..f3bc5a65 --- /dev/null +++ b/test/mppa/general/compw.lt.c @@ -0,0 +1,4 @@ +int main(void){ + int a = 5, b = -2; + return (a < b); +} diff --git a/test/mppa/general/compw.ltu.c b/test/mppa/general/compw.ltu.c new file mode 100644 index 00000000..5e396085 --- /dev/null +++ b/test/mppa/general/compw.ltu.c @@ -0,0 +1,4 @@ +int main(void){ + unsigned int a = 5, b = -2; + return (a < b); +} diff --git a/test/mppa/general/compw.ne.c b/test/mppa/general/compw.ne.c new file mode 100644 index 00000000..28eb627e --- /dev/null +++ b/test/mppa/general/compw.ne.c @@ -0,0 +1,4 @@ +int main(void){ + unsigned int a = 5, b = -2; + return (a != b); +} diff --git a/test/mppa/general/lbs.c b/test/mppa/general/lbs.c new file mode 100644 index 00000000..17441fd2 --- /dev/null +++ b/test/mppa/general/lbs.c @@ -0,0 +1,5 @@ +int main(void){ + char s[] = "Tom and Jerry at the playa\n"; + int a = s[10]; + return a; +} diff --git a/test/mppa/general/lbz.c b/test/mppa/general/lbz.c new file mode 100644 index 00000000..ca4e076f --- /dev/null +++ b/test/mppa/general/lbz.c @@ -0,0 +1,5 @@ +int main(void){ + unsigned char s[] = "Tom and Jerry at the playa\n"; + int a = s[10]; + return a; +} diff --git a/test/mppa/general/muld.c b/test/mppa/general/muld.c new file mode 100644 index 00000000..7893f714 --- /dev/null +++ b/test/mppa/general/muld.c @@ -0,0 +1,5 @@ +int main(void){ + long long a = 3, b = -4; + long long c = a*b; + return c; +} diff --git a/test/mppa/general/mulw.c b/test/mppa/general/mulw.c new file mode 100644 index 00000000..36e3abb1 --- /dev/null +++ b/test/mppa/general/mulw.c @@ -0,0 +1,5 @@ +int main(void){ + int a = 3, b = -4; + int c = a*b; + return c; +} diff --git a/test/mppa/general/negd.c b/test/mppa/general/negd.c new file mode 100644 index 00000000..3a949389 --- /dev/null +++ b/test/mppa/general/negd.c @@ -0,0 +1,6 @@ +int main(void){ + long long a = 5; + long long b = -2; + long long c = -a; + return c; +} diff --git a/test/mppa/general/ord.c b/test/mppa/general/ord.c new file mode 100644 index 00000000..f87061dd --- /dev/null +++ b/test/mppa/general/ord.c @@ -0,0 +1,5 @@ +int main(void){ + long long a = 3, b = -4; + long long c = a|b; + return c; +} diff --git a/test/mppa/general/sbfd.c b/test/mppa/general/sbfd.c new file mode 100644 index 00000000..503c65c7 --- /dev/null +++ b/test/mppa/general/sbfd.c @@ -0,0 +1,5 @@ +int main(void){ + long long a = 3, b = -4; + long long c = a-b; + return c; +} diff --git a/test/mppa/general/sbfw.c b/test/mppa/general/sbfw.c new file mode 100644 index 00000000..2607159f --- /dev/null +++ b/test/mppa/general/sbfw.c @@ -0,0 +1,5 @@ +int main(void){ + int a = 3, b = -4; + int c = a-b; + return c; +} diff --git a/test/mppa/general/sllw.c b/test/mppa/general/sllw.c new file mode 100644 index 00000000..98ecde3a --- /dev/null +++ b/test/mppa/general/sllw.c @@ -0,0 +1,5 @@ +int main(void){ + int a = 3, b = -4; + int c = a << b; + return c; +} diff --git a/test/mppa/general/srad.c b/test/mppa/general/srad.c new file mode 100644 index 00000000..1c0ea20b --- /dev/null +++ b/test/mppa/general/srad.c @@ -0,0 +1,5 @@ +int main(void){ + long long a = 3, b = -4; + long long c = a >> b; + return c; +} diff --git a/test/mppa/general/srld.c b/test/mppa/general/srld.c new file mode 100644 index 00000000..78861790 --- /dev/null +++ b/test/mppa/general/srld.c @@ -0,0 +1,5 @@ +int main(void){ + unsigned long long a = 3, b = -4; + unsigned long long c = a >> b; + return c; +} diff --git a/test/mppa/general/xord.c b/test/mppa/general/xord.c new file mode 100644 index 00000000..ab0ba653 --- /dev/null +++ b/test/mppa/general/xord.c @@ -0,0 +1,5 @@ +int main(void){ + long long a = 3, b = -4; + long long c = a^b; + return c; +} -- cgit From 155745466c01ad9485027689409ab986f7ebb207 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Thu, 26 Apr 2018 16:44:37 +0200 Subject: MPPA - mmult and sort Makefile now check on ccomp version --- test/mppa/mmult/Makefile | 7 ++++--- test/mppa/mmult/mmult.c | 2 +- test/mppa/sort/Makefile | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/mppa/mmult/Makefile b/test/mppa/mmult/Makefile index edea61ae..3297dfe4 100644 --- a/test/mppa/mmult/Makefile +++ b/test/mppa/mmult/Makefile @@ -1,4 +1,5 @@ PRNG=../lib/prng.c +CCOMP=../../../ccomp ALL= mmult-test-x86 mmult-test-k1c\ @@ -16,11 +17,11 @@ test-x86: mmult.c $(PRNG) test-k1c: mmult.c $(PRNG) k1-gcc -g -O2 -std=c99 $^ -o $@ -%.s: %.c - ccomp -O2 -S $< -o $@ +%.s: %.c $(CCOMP) + ccomp -O0 -g -S $< -o $@ test-ccomp: mmult.s $(subst .c,.s,$(PRNG)) - k1-gcc $^ -o $@ + k1-gcc $^ -g -o $@ .PHONY: unittest: unittest-x86 unittest-k1c diff --git a/test/mppa/mmult/mmult.c b/test/mppa/mmult/mmult.c index dcbcfe17..b674ca80 100644 --- a/test/mppa/mmult/mmult.c +++ b/test/mppa/mmult/mmult.c @@ -4,7 +4,7 @@ #define __UNIT_TEST_MMULT__ #ifdef __UNIT_TEST_MMULT__ -#define SIZE 50 +#define SIZE 10 #else #include "test.h" #endif diff --git a/test/mppa/sort/Makefile b/test/mppa/sort/Makefile index 4a118875..f94fe6b8 100644 --- a/test/mppa/sort/Makefile +++ b/test/mppa/sort/Makefile @@ -1,4 +1,5 @@ PRNG=../lib/prng.c +CCOMP=../../../ccomp ALL= insertion-test-x86 insertion-test-k1c\ selection-test-x86 selection-test-k1c\ @@ -20,7 +21,7 @@ test-x86: selection.c merge.c insertion.c test.c $(PRNG) test-k1c: selection.c merge.c insertion.c test.c $(PRNG) k1-gcc -g -O2 -std=c99 $^ -o $@ -%.s: %.c +%.s: %.c $(CCOMP) ccomp -O2 -S $< -o $@ test-ccomp: selection.s merge.s insertion.s test.s $(subst .c,.s,$(PRNG)) -- cgit From 4f1b42bd2ec89d74f7156054e12edd5321c31337 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Thu, 26 Apr 2018 18:01:45 +0200 Subject: MPPA - Updated asm_coverage --- test/mppa/asm_coverage | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/mppa/asm_coverage b/test/mppa/asm_coverage index 63195a53..a9c62b61 160000 --- a/test/mppa/asm_coverage +++ b/test/mppa/asm_coverage @@ -1 +1 @@ -Subproject commit 63195a533f3a7f93e8e8ebad0683b176041e09d4 +Subproject commit a9c62b61552a9e9fd0ebf43df5ee0d5b88bb0944 -- cgit From a44f224bfa7c340188b54b3bd26a61e94567729b Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 9 May 2018 14:04:31 +0200 Subject: Code cleaning --- test/mppa/mmult/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/mppa/mmult/Makefile b/test/mppa/mmult/Makefile index 3297dfe4..23b31d49 100644 --- a/test/mppa/mmult/Makefile +++ b/test/mppa/mmult/Makefile @@ -12,16 +12,16 @@ all: $(ALL) k1-gcc -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ test-x86: mmult.c $(PRNG) - gcc -g -O2 -std=c99 $^ -o $@ + gcc -O2 -std=c99 $^ -o $@ test-k1c: mmult.c $(PRNG) - k1-gcc -g -O2 -std=c99 $^ -o $@ + k1-gcc -O2 -std=c99 $^ -o $@ %.s: %.c $(CCOMP) - ccomp -O0 -g -S $< -o $@ + ccomp -O2 -S $< -o $@ test-ccomp: mmult.s $(subst .c,.s,$(PRNG)) - k1-gcc $^ -g -o $@ + k1-gcc $^ -o $@ .PHONY: unittest: unittest-x86 unittest-k1c -- cgit From 479aacd0254605942a3f48c3b8053af4d07f0f6c Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Mon, 21 May 2018 16:34:36 +0200 Subject: MPPA - Added modulo and division 64 bits. Non certified 32 bits version are not yet there. Right now the code is directly from libgcc, compiled with k1-gcc because of builtins. --- test/mppa/Makefile | 2 +- test/mppa/general/udivd.c | 8 ++++++++ test/mppa/general/umodd.c | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/mppa/general/udivd.c create mode 100644 test/mppa/general/umodd.c (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index ffea4c30..5b312475 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -17,7 +17,7 @@ nobin: $(ASM) $(DIR)/$(BINDIR)/%.bin: $(DIR)/$(ASMDIR)/%.s @mkdir -p $(@D) - k1-gcc $< -o $@ + ccomp $< -o $@ .SECONDARY: $(DIR)/$(ASMDIR)/%.s: $(DIR)/%.c $(CCOMP) diff --git a/test/mppa/general/udivd.c b/test/mppa/general/udivd.c new file mode 100644 index 00000000..03e103a6 --- /dev/null +++ b/test/mppa/general/udivd.c @@ -0,0 +1,8 @@ +#define TYPE unsigned long long + +int main(void){ + TYPE a = 6; + TYPE b = -4; + + return a/b; +} diff --git a/test/mppa/general/umodd.c b/test/mppa/general/umodd.c new file mode 100644 index 00000000..96d2b564 --- /dev/null +++ b/test/mppa/general/umodd.c @@ -0,0 +1,8 @@ +#define TYPE unsigned long long + +int main(void){ + TYPE a = 6; + TYPE b = -4; + + return a%b; +} -- cgit From 48762e6309dc92ac7788a30c0ca1007715fce4db Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 5 Jun 2018 13:54:40 +0200 Subject: MPPA - Added Builtins support. Starting with clzll and stsud --- test/mppa/general/clzll.c | 4 ++++ test/mppa/general/stsud.c | 5 +++++ 2 files changed, 9 insertions(+) create mode 100644 test/mppa/general/clzll.c create mode 100644 test/mppa/general/stsud.c (limited to 'test') diff --git a/test/mppa/general/clzll.c b/test/mppa/general/clzll.c new file mode 100644 index 00000000..e3853ea8 --- /dev/null +++ b/test/mppa/general/clzll.c @@ -0,0 +1,4 @@ +int main(void){ + long long a = -5; + return __builtin_clzll(a); +} diff --git a/test/mppa/general/stsud.c b/test/mppa/general/stsud.c new file mode 100644 index 00000000..dc8769fe --- /dev/null +++ b/test/mppa/general/stsud.c @@ -0,0 +1,5 @@ +int main(void){ + unsigned long long a = 5; + long long b = -3; + return __builtin_k1_stsud(a, b); +} -- cgit From 7b5eb7e675ee0978e1b17b75f827dcd45df8c250 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 5 Jun 2018 17:48:22 +0200 Subject: WIP - Changed all the general tests to include PRNG (instead of small constants) --- test/mppa/Makefile | 6 ++++-- test/mppa/general/addw.c | 10 +++++----- test/mppa/general/andd.c | 8 ++++---- test/mppa/general/andw.c | 10 +++++----- test/mppa/general/branch.c | 19 ++++++++----------- test/mppa/general/branchz.c | 19 ++++++++----------- test/mppa/general/branchzu.c | 20 +++++++++----------- test/mppa/general/call.c | 20 +++++++++----------- test/mppa/general/cb.deqz.c | 15 ++++++++------- test/mppa/general/cb.dgez.c | 15 ++++++++------- test/mppa/general/cb.dgtz.c | 15 ++++++++------- test/mppa/general/cb.dlez.c | 15 ++++++++------- test/mppa/general/cb.dltz.c | 15 ++++++++------- test/mppa/general/cb.dnez.c | 15 ++++++++------- test/mppa/general/cb.wgez.c | 15 ++++++++------- test/mppa/general/cb.wgtz.c | 15 ++++++++------- test/mppa/general/cb.wlez.c | 15 ++++++++------- test/mppa/general/cb.wltz.c | 15 ++++++++------- test/mppa/general/clzll.c | 9 ++++++--- test/mppa/general/compd.eq.c | 9 ++++++--- test/mppa/general/compd.geu.c | 9 ++++++--- test/mppa/general/compd.gt.c | 9 ++++++--- test/mppa/general/compd.gtu.c | 9 ++++++--- test/mppa/general/compd.le.c | 9 ++++++--- test/mppa/general/compd.leu.c | 9 ++++++--- test/mppa/general/compd.lt.c | 9 ++++++--- test/mppa/general/compd.ltu.c | 9 ++++++--- test/mppa/general/compd.ne.c | 9 ++++++--- test/mppa/general/compw.eq.c | 9 ++++++--- test/mppa/general/compw.geu.c | 9 ++++++--- test/mppa/general/compw.gt.c | 9 ++++++--- test/mppa/general/compw.gtu.c | 9 ++++++--- test/mppa/general/compw.le.c | 9 ++++++--- test/mppa/general/compw.leu.c | 9 ++++++--- test/mppa/general/compw.lt.c | 9 ++++++--- test/mppa/general/compw.ltu.c | 9 ++++++--- test/mppa/general/compw.ne.c | 9 ++++++--- test/mppa/general/div2.c | 25 +++++-------------------- test/mppa/general/for.c | 16 +++++++--------- test/mppa/general/forvar.c | 17 +++++++---------- test/mppa/general/forvarl.c | 17 +++++++---------- test/mppa/general/framework.h | 24 ++++++++++++++++++++++++ test/mppa/general/lbs.c | 12 ++++++++---- test/mppa/general/lbz.c | 12 ++++++++---- test/mppa/general/muld.c | 10 ++++++---- test/mppa/general/mulw.c | 10 ++++++---- test/mppa/general/negd.c | 11 ++++++----- test/mppa/general/ord.c | 10 ++++++---- test/mppa/general/sbfd.c | 10 ++++++---- test/mppa/general/sbfw.c | 10 ++++++---- test/mppa/general/simple.c | 11 +++++------ test/mppa/general/sllw.c | 10 ++++++---- test/mppa/general/srad.c | 10 ++++++---- test/mppa/general/srld.c | 10 ++++++---- test/mppa/general/stsud.c | 10 ++++++---- test/mppa/general/udivd.c | 11 +++++------ test/mppa/general/umodd.c | 11 +++++------ test/mppa/general/xord.c | 10 ++++++---- test/mppa/lib/prng.c | 2 +- 59 files changed, 394 insertions(+), 308 deletions(-) create mode 100644 test/mppa/general/framework.h (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 5b312475..05223658 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,7 +1,8 @@ DIR=general BINDIR=bin ASMDIR=asm -TESTNAMES=$(notdir $(subst .c,,$(wildcard $(DIR)/*.c))) +#TESTNAMES=$(notdir $(subst .c,,$(wildcard $(DIR)/*.c))) +TESTNAMES=branch CCOMP=../../ccomp #TESTS=$(addprefix $(DIR)/,$(TESTNAMES)) @@ -35,7 +36,8 @@ $(DIR)/output/%.bin.exp: $(DIR)/%.c FORCE: .PHONY: check -check: $(TOK) sort mmult +check: $(TOK) +#check: $(TOK) sort mmult .PHONY: coverage coverage: $(ASM) diff --git a/test/mppa/general/addw.c b/test/mppa/general/addw.c index 842b0de7..be8afc67 100644 --- a/test/mppa/general/addw.c +++ b/test/mppa/general/addw.c @@ -1,5 +1,5 @@ -int main(void){ - int a = 5; - int b = -3; - return a+b; -} +#include "framework.h" + +BEGIN_TEST(int) + c = a+b; +END_TEST() diff --git a/test/mppa/general/andd.c b/test/mppa/general/andd.c index 57c23585..4f503764 100644 --- a/test/mppa/general/andd.c +++ b/test/mppa/general/andd.c @@ -1,5 +1,5 @@ -int main(void){ - long long a = 5; - long long b = -3; +#include "framework.h" + +BEGIN_TEST(long long) return a&b; -} +END_TEST() diff --git a/test/mppa/general/andw.c b/test/mppa/general/andw.c index a10f1203..99de0049 100644 --- a/test/mppa/general/andw.c +++ b/test/mppa/general/andw.c @@ -1,5 +1,5 @@ -int main(void){ - int a = 5; - int b = -3; - return a&b; -} +#include "framework.h" + +BEGIN_TEST(int) + c = a&b; +END_TEST() diff --git a/test/mppa/general/branch.c b/test/mppa/general/branch.c index c9bb3865..72e7e20e 100644 --- a/test/mppa/general/branch.c +++ b/test/mppa/general/branch.c @@ -1,13 +1,10 @@ -int main(void){ - int a=1; - int b; +#include "framework.h" - if(a){ - b = a+4; - } else { - b = a+2; - } - - return b; +BEGIN_TEST(int) +{ + if ((a & 0x1) == 1) + c = 0; + else + c = 1; } -/* RETURN VALUE: 5 */ +END_TEST() diff --git a/test/mppa/general/branchz.c b/test/mppa/general/branchz.c index 685d3961..fb86d357 100644 --- a/test/mppa/general/branchz.c +++ b/test/mppa/general/branchz.c @@ -1,13 +1,10 @@ -int main(void){ - int a=1; - int b; +#include "framework.h" - if(a==0){ - b = a+4; - } else { - b = a+2; - } - - return b; +BEGIN_TEST(int) +{ + if (a & 0x1 == 0) + c = 0; + else + c = 1; } -/* RETURN VALUE: 3 */ +END_TEST() diff --git a/test/mppa/general/branchzu.c b/test/mppa/general/branchzu.c index 16bbc4c1..97adb605 100644 --- a/test/mppa/general/branchzu.c +++ b/test/mppa/general/branchzu.c @@ -1,13 +1,11 @@ -int main(void){ - int a=1; - int b; +#include "framework.h" - if(!a){ - b = a+4; - } else { - b = a+2; - } - - return b; +BEGIN_TEST(int) +{ + b = !(a & 0x01); + if (!b) + c = 0; + else + c = 1; } -/* RETURN VALUE: 3 */ +END_TEST() diff --git a/test/mppa/general/call.c b/test/mppa/general/call.c index f35473b6..727cef63 100644 --- a/test/mppa/general/call.c +++ b/test/mppa/general/call.c @@ -1,18 +1,16 @@ -int sum(int a, int b){ - return a + b; -} +#include "framework.h" -int make_42(void){ - return 42; +int sum(int a, int b){ + return a+b; } -int make_18(void){ - return 18; +int make(int a){ + return a; } -int main(void){ - return sum(make_42(), make_18()); - //return make_42() + make_18(); +BEGIN_TEST(int) +{ + c = sum(make(a), make(b)); } - +END_TEST() /* RETURN VALUE: 60 */ diff --git a/test/mppa/general/cb.deqz.c b/test/mppa/general/cb.deqz.c index c4f639fd..c56733f0 100644 --- a/test/mppa/general/cb.deqz.c +++ b/test/mppa/general/cb.deqz.c @@ -1,9 +1,10 @@ -#define TYPE long long +#include "framework.h" -int main(void){ - TYPE a = 6; - TYPE b = -4; - if (0 != a) - return 42; - return 0; +BEGIN_TEST(long long) +{ + if (0 != (a & 0x1LL)) + c = 1; + else + c = 0; } +END_TEST() diff --git a/test/mppa/general/cb.dgez.c b/test/mppa/general/cb.dgez.c index 3d1caf1e..abb6ec57 100644 --- a/test/mppa/general/cb.dgez.c +++ b/test/mppa/general/cb.dgez.c @@ -1,9 +1,10 @@ -#define TYPE long long +#include "framework.h" -int main(void){ - TYPE a = 6; - TYPE b = -4; - if (0 > a) - return 42; - return 0; +BEGIN_TEST(long long) +{ + if (0 > (a & 0x1LL)) + c = 1; + else + c = 0; } +END_TEST() diff --git a/test/mppa/general/cb.dgtz.c b/test/mppa/general/cb.dgtz.c index 9c0c9ea2..d4271845 100644 --- a/test/mppa/general/cb.dgtz.c +++ b/test/mppa/general/cb.dgtz.c @@ -1,9 +1,10 @@ -#define TYPE long long +#include "framework.h" -int main(void){ - TYPE a = 6; - TYPE b = -4; - if (0 >= a) - return 42; - return 0; +BEGIN_TEST(long long) +{ + if (0 >= (a & 0x1LL) - 1) + c = 1; + else + c = 0; } +END_TEST() diff --git a/test/mppa/general/cb.dlez.c b/test/mppa/general/cb.dlez.c index 021bb16d..18e67f06 100644 --- a/test/mppa/general/cb.dlez.c +++ b/test/mppa/general/cb.dlez.c @@ -1,9 +1,10 @@ -#define TYPE long long +#include "framework.h" -int main(void){ - TYPE a = 6; - TYPE b = -4; - if (a > 0) - return 42; - return 0; +BEGIN_TEST(long long) +{ + if (a & 0x1LL > 0) + c = 1; + else + c = 0; } +END_TEST() diff --git a/test/mppa/general/cb.dltz.c b/test/mppa/general/cb.dltz.c index d6c59d03..366aea49 100644 --- a/test/mppa/general/cb.dltz.c +++ b/test/mppa/general/cb.dltz.c @@ -1,9 +1,10 @@ -#define TYPE long long +#include "framework.h" -int main(void){ - TYPE a = 6; - TYPE b = -4; - if (a >= 0) - return 42; - return 0; +BEGIN_TEST(long long) +{ + if ((a & 0x1LL) - 1 >= 0) + c = 1; + else + c = 0; } +END_TEST() diff --git a/test/mppa/general/cb.dnez.c b/test/mppa/general/cb.dnez.c index 99ecf84e..81c2cd29 100644 --- a/test/mppa/general/cb.dnez.c +++ b/test/mppa/general/cb.dnez.c @@ -1,9 +1,10 @@ -#define TYPE long long +#include "framework.h" -int main(void){ - TYPE a = 6; - TYPE b = -4; - if (0 == a) - return 42; - return 0; +BEGIN_TEST(long long) +{ + if (0 == (a & 0x1LL)) + c = 1; + else + c = 0; } +END_TEST() diff --git a/test/mppa/general/cb.wgez.c b/test/mppa/general/cb.wgez.c index 8226c397..477f4bc6 100644 --- a/test/mppa/general/cb.wgez.c +++ b/test/mppa/general/cb.wgez.c @@ -1,9 +1,10 @@ -#define TYPE int +#include "framework.h" -int main(void){ - TYPE a = 6; - TYPE b = -4; - if (0 > a) - return 42; - return 0; +BEGIN_TEST(int) +{ + if (0 > (a & 0x1) - 1) + c = 1; + else + c = 0; } +END_TEST() diff --git a/test/mppa/general/cb.wgtz.c b/test/mppa/general/cb.wgtz.c index 005e552b..c9ab9a06 100644 --- a/test/mppa/general/cb.wgtz.c +++ b/test/mppa/general/cb.wgtz.c @@ -1,9 +1,10 @@ -#define TYPE int +#include "framework.h" -int main(void){ - TYPE a = 6; - TYPE b = -4; - if (0 >= a) - return 42; - return 0; +BEGIN_TEST(int) +{ + if (0 >= (a & 0x1)) + c = 1; + else + c = 0; } +END_TEST() diff --git a/test/mppa/general/cb.wlez.c b/test/mppa/general/cb.wlez.c index 4393003b..c3069fda 100644 --- a/test/mppa/general/cb.wlez.c +++ b/test/mppa/general/cb.wlez.c @@ -1,9 +1,10 @@ -#define TYPE int +#include "framework.h" -int main(void){ - TYPE a = 6; - TYPE b = -4; - if (a > 0) - return 42; - return 0; +BEGIN_TEST(int) +{ + if ((a & 0x1) > 0) + c = 1; + else + c = 0; } +END_TEST() diff --git a/test/mppa/general/cb.wltz.c b/test/mppa/general/cb.wltz.c index 76d49f56..6cf5fcf0 100644 --- a/test/mppa/general/cb.wltz.c +++ b/test/mppa/general/cb.wltz.c @@ -1,9 +1,10 @@ -#define TYPE int +#include "framework.h" -int main(void){ - TYPE a = 6; - TYPE b = -4; - if (a >= 0) - return 42; - return 0; +BEGIN_TEST(int) +{ + if ((a & 0x1) - 1 >= 0) + c = 1; + else + c = 0; } +END_TEST() diff --git a/test/mppa/general/clzll.c b/test/mppa/general/clzll.c index e3853ea8..13905cba 100644 --- a/test/mppa/general/clzll.c +++ b/test/mppa/general/clzll.c @@ -1,4 +1,7 @@ -int main(void){ - long long a = -5; - return __builtin_clzll(a); +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = __builtin_clzll(a); } +END_TEST() diff --git a/test/mppa/general/compd.eq.c b/test/mppa/general/compd.eq.c index 9b3e3a0d..d19a4d20 100644 --- a/test/mppa/general/compd.eq.c +++ b/test/mppa/general/compd.eq.c @@ -1,4 +1,7 @@ -int main(void){ - long long a = 5, b = -2; - return (a == b); +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = ((a & 0x1LL) == (b & 0x1LL)); } +END_TEST() diff --git a/test/mppa/general/compd.geu.c b/test/mppa/general/compd.geu.c index d168a6a7..edc31183 100644 --- a/test/mppa/general/compd.geu.c +++ b/test/mppa/general/compd.geu.c @@ -1,4 +1,7 @@ -int main(void){ - unsigned long long a = 5, b = -2; - return (a >= b); +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = (a >= b); } +END_TEST() diff --git a/test/mppa/general/compd.gt.c b/test/mppa/general/compd.gt.c index 768e57fc..24147779 100644 --- a/test/mppa/general/compd.gt.c +++ b/test/mppa/general/compd.gt.c @@ -1,4 +1,7 @@ -int main(void){ - long long a = 5, b = -2; - return (a > b); +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = (a > b); } +END_TEST() diff --git a/test/mppa/general/compd.gtu.c b/test/mppa/general/compd.gtu.c index 5ac1910a..5ce82569 100644 --- a/test/mppa/general/compd.gtu.c +++ b/test/mppa/general/compd.gtu.c @@ -1,4 +1,7 @@ -int main(void){ - unsigned long long a = 5, b = -2; - return (a > b); +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = (a > b); } +END_TEST() diff --git a/test/mppa/general/compd.le.c b/test/mppa/general/compd.le.c index b493f661..a84aad97 100644 --- a/test/mppa/general/compd.le.c +++ b/test/mppa/general/compd.le.c @@ -1,4 +1,7 @@ -int main(void){ - long long a = 5, b = -2; - return (a <= b); +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = (a <= b); } +END_TEST() diff --git a/test/mppa/general/compd.leu.c b/test/mppa/general/compd.leu.c index 8bb640b1..e386bc27 100644 --- a/test/mppa/general/compd.leu.c +++ b/test/mppa/general/compd.leu.c @@ -1,4 +1,7 @@ -int main(void){ - unsigned long long a = 5, b = -2; - return (a <= b); +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = (a <= b); } +END_TEST() diff --git a/test/mppa/general/compd.lt.c b/test/mppa/general/compd.lt.c index 04a92556..df07a708 100644 --- a/test/mppa/general/compd.lt.c +++ b/test/mppa/general/compd.lt.c @@ -1,4 +1,7 @@ -int main(void){ - long long a = 5, b = -2; - return (a < b); +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = (a < b); } +END_TEST() diff --git a/test/mppa/general/compd.ltu.c b/test/mppa/general/compd.ltu.c index bbd901f6..dfaa8921 100644 --- a/test/mppa/general/compd.ltu.c +++ b/test/mppa/general/compd.ltu.c @@ -1,4 +1,7 @@ -int main(void){ - unsigned long long a = 5, b = -2; - return (a < b); +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = (a < b); } +END_TEST() diff --git a/test/mppa/general/compd.ne.c b/test/mppa/general/compd.ne.c index 01c52254..19ce0a69 100644 --- a/test/mppa/general/compd.ne.c +++ b/test/mppa/general/compd.ne.c @@ -1,4 +1,7 @@ -int main(void){ - unsigned long long a = 5, b = -2; - return (a != b); +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = ((a & 0x1ULL) != (b & 0x1ULL)); } +END_TEST() diff --git a/test/mppa/general/compw.eq.c b/test/mppa/general/compw.eq.c index f030d86b..dc7a3ab1 100644 --- a/test/mppa/general/compw.eq.c +++ b/test/mppa/general/compw.eq.c @@ -1,4 +1,7 @@ -int main(void){ - int a = 5, b = -2; - return (a == b); +#include "framework.h" + +BEGIN_TEST(int) +{ + c = ((a & 0x1) == (b & 0x1)); } +END_TEST() diff --git a/test/mppa/general/compw.geu.c b/test/mppa/general/compw.geu.c index 866f0b47..d72ca56c 100644 --- a/test/mppa/general/compw.geu.c +++ b/test/mppa/general/compw.geu.c @@ -1,4 +1,7 @@ -int main(void){ - unsigned int a = 5, b = -2; - return (a >= b); +#include "framework.h" + +BEGIN_TEST(unsigned int) +{ + c = (a >= b); } +END_TEST() diff --git a/test/mppa/general/compw.gt.c b/test/mppa/general/compw.gt.c index 6cde8622..9ad02610 100644 --- a/test/mppa/general/compw.gt.c +++ b/test/mppa/general/compw.gt.c @@ -1,4 +1,7 @@ -int main(void){ - int a = 5, b = -2; - return (a > b); +#include "framework.h" + +BEGIN_TEST(int) +{ + c = (a > b); } +END_TEST() diff --git a/test/mppa/general/compw.gtu.c b/test/mppa/general/compw.gtu.c index b2e74594..77f04989 100644 --- a/test/mppa/general/compw.gtu.c +++ b/test/mppa/general/compw.gtu.c @@ -1,4 +1,7 @@ -int main(void){ - unsigned int a = 5, b = -2; - return (a > b); +#include "framework.h" + +BEGIN_TEST(unsigned int) +{ + c = (a > b); } +END_TEST() diff --git a/test/mppa/general/compw.le.c b/test/mppa/general/compw.le.c index 8f33e064..b7a7a432 100644 --- a/test/mppa/general/compw.le.c +++ b/test/mppa/general/compw.le.c @@ -1,4 +1,7 @@ -int main(void){ - int a = 5, b = -2; - return (a <= b); +#include "framework.h" + +BEGIN_TEST(int) +{ + c = (a <= b); } +END_TEST() diff --git a/test/mppa/general/compw.leu.c b/test/mppa/general/compw.leu.c index fde558eb..4892f06c 100644 --- a/test/mppa/general/compw.leu.c +++ b/test/mppa/general/compw.leu.c @@ -1,4 +1,7 @@ -int main(void){ - unsigned int a = 5, b = -2; - return (a <= b); +#include "framework.h" + +BEGIN_TEST(unsigned int) +{ + c = (a <= b); } +END_TEST() diff --git a/test/mppa/general/compw.lt.c b/test/mppa/general/compw.lt.c index f3bc5a65..2cc151bf 100644 --- a/test/mppa/general/compw.lt.c +++ b/test/mppa/general/compw.lt.c @@ -1,4 +1,7 @@ -int main(void){ - int a = 5, b = -2; - return (a < b); +#include "framework.h" + +BEGIN_TEST(int) +{ + c = (a < b); } +END_TEST() diff --git a/test/mppa/general/compw.ltu.c b/test/mppa/general/compw.ltu.c index 5e396085..b524127f 100644 --- a/test/mppa/general/compw.ltu.c +++ b/test/mppa/general/compw.ltu.c @@ -1,4 +1,7 @@ -int main(void){ - unsigned int a = 5, b = -2; - return (a < b); +#include "framework.h" + +BEGIN_TEST(unsigned int) +{ + c = (a < b); } +END_TEST() diff --git a/test/mppa/general/compw.ne.c b/test/mppa/general/compw.ne.c index 28eb627e..433b0b86 100644 --- a/test/mppa/general/compw.ne.c +++ b/test/mppa/general/compw.ne.c @@ -1,4 +1,7 @@ -int main(void){ - unsigned int a = 5, b = -2; - return (a != b); +#include "framework.h" + +BEGIN_TEST(unsigned int) +{ + c = ((a & 0x1U) != (b & 0x1U)); } +END_TEST() diff --git a/test/mppa/general/div2.c b/test/mppa/general/div2.c index ec73b32d..01a4b575 100644 --- a/test/mppa/general/div2.c +++ b/test/mppa/general/div2.c @@ -1,22 +1,7 @@ -#define SIZE 10 +#include "framework.h" -int main(void){ - int a[SIZE], b[SIZE], c[SIZE]; - int i; - - for (i = 0 ; i < SIZE ; i++){ - a[i] = i-5; - b[i] = -i+2; - c[i] = (a[i] + b[i]) / 2; - } - /* a = {-5, -4, .., 5} - * b = { 2, 1, .., -8} - */ - - for (i = 0 ; i < SIZE ; i++) - if (c[i] != -1) - return c[i]; - - return 42; +BEGIN_TEST(int) +{ + c = (a + b) / 2; } -/* RETURN VALUE: 42 */ +END_TEST() diff --git a/test/mppa/general/for.c b/test/mppa/general/for.c index 41669146..d6870afb 100644 --- a/test/mppa/general/for.c +++ b/test/mppa/general/for.c @@ -1,11 +1,9 @@ -int main(void){ - int a = 4; - int i; +#include "framework.h" - for (i = 0 ; i < 12 ; i++) - a++; - - return a; +BEGIN_TEST(int) +{ + int j; + for (j = 0 ; j < 10 ; j++) + c += a; } - -/* RETURN VALUE: 16 */ +END_TEST() diff --git a/test/mppa/general/forvar.c b/test/mppa/general/forvar.c index 5ada4357..57548274 100644 --- a/test/mppa/general/forvar.c +++ b/test/mppa/general/forvar.c @@ -1,12 +1,9 @@ -int main(void){ - int i; - int a = 4; - int b = 12; +#include "framework.h" - for (i = 0 ; i < b ; i++) - a++; - - return a; +BEGIN_TEST(int) +{ + int j; + for (j = 0 ; j < (b & 0x8) ; j++) + c += a; } - -/* RETURN VALUE: 16 */ +END_TEST() diff --git a/test/mppa/general/forvarl.c b/test/mppa/general/forvarl.c index 0ab31998..30717a51 100644 --- a/test/mppa/general/forvarl.c +++ b/test/mppa/general/forvarl.c @@ -1,13 +1,10 @@ -int main(void) -{ - long long int a = 42; - long long int b = 84; - long long int i; +#include "framework.h" - for (i = 0 ; i < a ; i++) - b++; +BEGIN_TEST(long long int) +{ + int j; - return 0; + for (j = 0 ; j < (b & 0x8LL) ; j++) + c += a; } - -/* RETURN VALUE: 0 */ +END_TEST() diff --git a/test/mppa/general/framework.h b/test/mppa/general/framework.h new file mode 100644 index 00000000..8321a9a9 --- /dev/null +++ b/test/mppa/general/framework.h @@ -0,0 +1,24 @@ +#ifndef __FRAMEWORK_H__ +#define __FRAMEWORK_H__ + +#include "../lib/prng.c" + +#define BEGIN_TEST(type)\ + int main(void){\ + type a, b, c, i, S;\ + srand(0);\ + for (i = 0 ; i < 100 ; i++){\ + 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/general/lbs.c b/test/mppa/general/lbs.c index 17441fd2..f104d62b 100644 --- a/test/mppa/general/lbs.c +++ b/test/mppa/general/lbs.c @@ -1,5 +1,9 @@ -int main(void){ - char s[] = "Tom and Jerry at the playa\n"; - int a = s[10]; - return a; +#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/general/lbz.c b/test/mppa/general/lbz.c index ca4e076f..2deeaebe 100644 --- a/test/mppa/general/lbz.c +++ b/test/mppa/general/lbz.c @@ -1,5 +1,9 @@ -int main(void){ - unsigned char s[] = "Tom and Jerry at the playa\n"; - int a = s[10]; - return a; +#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/general/muld.c b/test/mppa/general/muld.c index 7893f714..9a40f389 100644 --- a/test/mppa/general/muld.c +++ b/test/mppa/general/muld.c @@ -1,5 +1,7 @@ -int main(void){ - long long a = 3, b = -4; - long long c = a*b; - return c; +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = a*b; } +END_TEST() diff --git a/test/mppa/general/mulw.c b/test/mppa/general/mulw.c index 36e3abb1..bf517ce8 100644 --- a/test/mppa/general/mulw.c +++ b/test/mppa/general/mulw.c @@ -1,5 +1,7 @@ -int main(void){ - int a = 3, b = -4; - int c = a*b; - return c; +#include "framework.h" + +BEGIN_TEST(int) +{ + c = a * b; } +END_TEST() diff --git a/test/mppa/general/negd.c b/test/mppa/general/negd.c index 3a949389..a8e8ff45 100644 --- a/test/mppa/general/negd.c +++ b/test/mppa/general/negd.c @@ -1,6 +1,7 @@ -int main(void){ - long long a = 5; - long long b = -2; - long long c = -a; - return c; +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = -a; } +END_TEST() diff --git a/test/mppa/general/ord.c b/test/mppa/general/ord.c index f87061dd..eaedcb28 100644 --- a/test/mppa/general/ord.c +++ b/test/mppa/general/ord.c @@ -1,5 +1,7 @@ -int main(void){ - long long a = 3, b = -4; - long long c = a|b; - return c; +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = a | b; } +END_TEST() diff --git a/test/mppa/general/sbfd.c b/test/mppa/general/sbfd.c index 503c65c7..912f1fdb 100644 --- a/test/mppa/general/sbfd.c +++ b/test/mppa/general/sbfd.c @@ -1,5 +1,7 @@ -int main(void){ - long long a = 3, b = -4; - long long c = a-b; - return c; +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = a-b; } +END_TEST() diff --git a/test/mppa/general/sbfw.c b/test/mppa/general/sbfw.c index 2607159f..feffd497 100644 --- a/test/mppa/general/sbfw.c +++ b/test/mppa/general/sbfw.c @@ -1,5 +1,7 @@ -int main(void){ - int a = 3, b = -4; - int c = a-b; - return c; +#include "framework.h" + +BEGIN_TEST(int) +{ + c = a-b; } +END_TEST() diff --git a/test/mppa/general/simple.c b/test/mppa/general/simple.c index 451522fc..89bba27e 100644 --- a/test/mppa/general/simple.c +++ b/test/mppa/general/simple.c @@ -1,8 +1,7 @@ -int main(void){ - int a = 4; - int b = 3; +#include "framework.h" - return (a+b); +BEGIN_TEST(int) +{ + c = a+b; } - -/* RETURN VALUE: 7 */ +END_TEST() diff --git a/test/mppa/general/sllw.c b/test/mppa/general/sllw.c index 98ecde3a..df55c9e8 100644 --- a/test/mppa/general/sllw.c +++ b/test/mppa/general/sllw.c @@ -1,5 +1,7 @@ -int main(void){ - int a = 3, b = -4; - int c = a << b; - return c; +#include "framework.h" + +BEGIN_TEST(int) +{ + c = a << (b & 0x8); } +END_TEST() diff --git a/test/mppa/general/srad.c b/test/mppa/general/srad.c index 1c0ea20b..b4047bc7 100644 --- a/test/mppa/general/srad.c +++ b/test/mppa/general/srad.c @@ -1,5 +1,7 @@ -int main(void){ - long long a = 3, b = -4; - long long c = a >> b; - return c; +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = a >> (b & 0x8LL); } +END_TEST() diff --git a/test/mppa/general/srld.c b/test/mppa/general/srld.c index 78861790..71e82b2a 100644 --- a/test/mppa/general/srld.c +++ b/test/mppa/general/srld.c @@ -1,5 +1,7 @@ -int main(void){ - unsigned long long a = 3, b = -4; - unsigned long long c = a >> b; - return c; +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = a >> (b & 0x8ULL); } +END_TEST() diff --git a/test/mppa/general/stsud.c b/test/mppa/general/stsud.c index dc8769fe..81fb6e6d 100644 --- a/test/mppa/general/stsud.c +++ b/test/mppa/general/stsud.c @@ -1,5 +1,7 @@ -int main(void){ - unsigned long long a = 5; - long long b = -3; - return __builtin_k1_stsud(a, b); +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = __builtin_k1_stsud(a, b); } +END_TEST() diff --git a/test/mppa/general/udivd.c b/test/mppa/general/udivd.c index 03e103a6..52e0d412 100644 --- a/test/mppa/general/udivd.c +++ b/test/mppa/general/udivd.c @@ -1,8 +1,7 @@ -#define TYPE unsigned long long +#include "framework.h" -int main(void){ - TYPE a = 6; - TYPE b = -4; - - return a/b; +BEGIN_TEST(unsigned long long) +{ + c = a/b; } +END_TEST() diff --git a/test/mppa/general/umodd.c b/test/mppa/general/umodd.c index 96d2b564..e7dd506f 100644 --- a/test/mppa/general/umodd.c +++ b/test/mppa/general/umodd.c @@ -1,8 +1,7 @@ -#define TYPE unsigned long long +#include "framework.h" -int main(void){ - TYPE a = 6; - TYPE b = -4; - - return a%b; +BEGIN_TEST(unsigned long long) +{ + c = a%b; } +END_TEST() diff --git a/test/mppa/general/xord.c b/test/mppa/general/xord.c index ab0ba653..b9d86f06 100644 --- a/test/mppa/general/xord.c +++ b/test/mppa/general/xord.c @@ -1,5 +1,7 @@ -int main(void){ - long long a = 3, b = -4; - long long c = a^b; - return c; +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = a^b; } +END_TEST() diff --git a/test/mppa/lib/prng.c b/test/mppa/lib/prng.c index dfa97834..59ec7ca6 100644 --- a/test/mppa/lib/prng.c +++ b/test/mppa/lib/prng.c @@ -9,7 +9,7 @@ static uint64_t current; void srand(uint64_t seed){ - seed = current; + current = seed; } uint64_t randlong(void){ -- cgit From 408ae8c4451b49277e8b97bbb7cedd2fb905bcdb Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 6 Jun 2018 17:30:28 +0200 Subject: MPPA - Forgot to initialize variables in the tests Warning : the division and modulo currently do not pass the tests --- test/mppa/Makefile | 3 +-- test/mppa/general/framework.h | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 05223658..fddaad37 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,8 +1,7 @@ DIR=general BINDIR=bin ASMDIR=asm -#TESTNAMES=$(notdir $(subst .c,,$(wildcard $(DIR)/*.c))) -TESTNAMES=branch +TESTNAMES=$(notdir $(subst .c,,$(wildcard $(DIR)/*.c))) CCOMP=../../ccomp #TESTS=$(addprefix $(DIR)/,$(TESTNAMES)) diff --git a/test/mppa/general/framework.h b/test/mppa/general/framework.h index 8321a9a9..78f2617e 100644 --- a/test/mppa/general/framework.h +++ b/test/mppa/general/framework.h @@ -7,7 +7,9 @@ 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 */ -- cgit From 265fdd4f703b0310fbcf5ad448c29dc34f7ff33a Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 26 Jun 2018 16:24:34 +0200 Subject: Fixed CompCert library inclusion. Indirect fix for udivd and umodd --- test/mppa/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index fddaad37..5b312475 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -35,8 +35,7 @@ $(DIR)/output/%.bin.exp: $(DIR)/%.c FORCE: .PHONY: check -check: $(TOK) -#check: $(TOK) sort mmult +check: $(TOK) sort mmult .PHONY: coverage coverage: $(ASM) -- cgit From 080875012a740b9fbe9ad9e1d147543ce538a955 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 1 Aug 2018 17:23:31 +0200 Subject: Added all the working builtins for ALU. Added BCU and LSU without testing --- test/mppa/general/clzd.c | 7 +++++++ test/mppa/general/clzll.c | 7 ------- test/mppa/general/clzw.c | 7 +++++++ test/mppa/general/ctzd.c | 7 +++++++ test/mppa/general/ctzw.c | 7 +++++++ test/mppa/general/framework.h | 11 +++++++++++ test/mppa/general/satd.c | 7 +++++++ test/mppa/general/sbmm8.c | 7 +++++++ test/mppa/general/sbmmt8.c | 7 +++++++ test/mppa/general/stsud.c | 4 ++-- test/mppa/generate.sh | 8 ++++++-- 11 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 test/mppa/general/clzd.c delete mode 100644 test/mppa/general/clzll.c create mode 100644 test/mppa/general/clzw.c create mode 100644 test/mppa/general/ctzd.c create mode 100644 test/mppa/general/ctzw.c create mode 100644 test/mppa/general/satd.c create mode 100644 test/mppa/general/sbmm8.c create mode 100644 test/mppa/general/sbmmt8.c (limited to 'test') 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/clzll.c b/test/mppa/general/clzll.c deleted file mode 100644 index 13905cba..00000000 --- a/test/mppa/general/clzll.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - c = __builtin_clzll(a); -} -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/framework.h b/test/mppa/general/framework.h index 78f2617e..b7dc4933 100644 --- a/test/mppa/general/framework.h +++ b/test/mppa/general/framework.h @@ -3,6 +3,17 @@ #include "../lib/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;\ 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/general/stsud.c b/test/mppa/general/stsud.c index 81fb6e6d..fb07b94f 100644 --- a/test/mppa/general/stsud.c +++ b/test/mppa/general/stsud.c @@ -1,7 +1,7 @@ #include "framework.h" -BEGIN_TEST(unsigned long long) +BEGIN_TEST_N(unsigned long long, 2) { - c = __builtin_k1_stsud(a, b); + c = __builtin_k1_stsud(t[0], t[1]); } END_TEST() diff --git a/test/mppa/generate.sh b/test/mppa/generate.sh index 765128d4..ea633724 100644 --- a/test/mppa/generate.sh +++ b/test/mppa/generate.sh @@ -4,14 +4,18 @@ cfile="$1" writefile="$2" +dirwritefile=$(dirname $writefile) +asmdir=$dirwritefile/../asm/gcc + if [ ! -f $cfile ]; then >&2 echo "ERROR: $cfile not found" shift; continue fi -mkdir -p $(dirname $writefile) +mkdir -p $dirwritefile +mkdir -p $asmdir -#sed -n "s/^.*\/\*\s*RETURN VALUE:\s*\([0-9]*\)\s*\*\//\1/p" $1 > $2 tmpbin=/tmp/k1-$(basename $1)-bin +k1-gcc -O0 $1 -S -o $asmdir/$(basename $1).s k1-gcc -O0 $1 -o $tmpbin (k1-cluster -- $tmpbin; echo $? > $2) -- cgit From 0b86431038c1e874d7d7030ab41a8f56b0a9991f Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 14 Aug 2018 10:33:40 +0200 Subject: Added some comments on the Makefile --- test/mppa/Makefile | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 5b312475..22f22945 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -4,7 +4,6 @@ ASMDIR=asm TESTNAMES=$(notdir $(subst .c,,$(wildcard $(DIR)/*.c))) CCOMP=../../ccomp -#TESTS=$(addprefix $(DIR)/,$(TESTNAMES)) ELF=$(addprefix $(DIR)/$(BINDIR)/,$(addsuffix .bin,$(TESTNAMES))) TOK=$(addprefix $(DIR)/$(BINDIR)/,$(addsuffix .tok,$(TESTNAMES))) ASM=$(addprefix $(DIR)/$(ASMDIR)/,$(addsuffix .s,$(TESTNAMES))) @@ -15,19 +14,32 @@ all: $(ELF) nobin: $(ASM) +## +# Assembling CompCert's assembly file +## $(DIR)/$(BINDIR)/%.bin: $(DIR)/$(ASMDIR)/%.s @mkdir -p $(@D) ccomp $< -o $@ +## +# Compiling the C file with CompCert +## .SECONDARY: $(DIR)/$(ASMDIR)/%.s: $(DIR)/%.c $(CCOMP) @mkdir -p $(@D) ccomp $(DEBUG) -O0 -v -S $< -o $@ +## +# A token (.tok) is created if the .bin (created by CompCert) yields the same +# result as the .bin.exp (created by executing the binary compiled with gcc) +## $(DIR)/$(BINDIR)/%.tok: $(DIR)/$(BINDIR)/%.bin $(DIR)/output/%.bin.exp @mkdir -p $(@D) @bash check.sh $< $@ +## +# Generate .bin.exp : compile with gcc, execute, store the result in .bin.exp +## $(DIR)/output/%.bin.exp: $(DIR)/%.c @bash generate.sh $< $@ @@ -37,15 +49,23 @@ FORCE: .PHONY: check check: $(TOK) sort mmult +## +# A utility displaying which of the pseudo-instructions are covered in the tests +## .PHONY: coverage coverage: $(ASM) bash coverage.sh $(DIR)/$(ASMDIR) - +## +# Different versions of a sorting algorithm +## .PHONY: sort sort: FORCE (cd sort && make compc-check) +## +# Different versions of a matrix multiply +## .PHONY: mmult mmult: FORCE (cd mmult && make compc-check) -- cgit From 4f5ec2ec310a78940b29f18e51dd598a9dfe401d Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Fri, 9 Nov 2018 15:17:52 +0100 Subject: Fixing k1-gcc becoming k1-mbr-gcc --- test/mppa/generate.sh | 2 +- test/mppa/lib/Makefile | 2 +- test/mppa/mmult/Makefile | 6 +++--- test/mppa/sort/Makefile | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/mppa/generate.sh b/test/mppa/generate.sh index 765128d4..a883b8f5 100644 --- a/test/mppa/generate.sh +++ b/test/mppa/generate.sh @@ -13,5 +13,5 @@ mkdir -p $(dirname $writefile) #sed -n "s/^.*\/\*\s*RETURN VALUE:\s*\([0-9]*\)\s*\*\//\1/p" $1 > $2 tmpbin=/tmp/k1-$(basename $1)-bin -k1-gcc -O0 $1 -o $tmpbin +k1-mbr-gcc -O0 $1 -o $tmpbin (k1-cluster -- $tmpbin; echo $? > $2) diff --git a/test/mppa/lib/Makefile b/test/mppa/lib/Makefile index 7aeab9f3..74e7ca8b 100644 --- a/test/mppa/lib/Makefile +++ b/test/mppa/lib/Makefile @@ -2,7 +2,7 @@ prng-test-x86: prng.c gcc -D__UNIT_TEST_PRNG__ -O2 -std=c99 $< -o $@ prng-test-k1c: prng.c - k1-gcc -D__UNIT_TEST_PRNG__ -O2 -std=c99 $< -o $@ + k1-mbr-gcc -D__UNIT_TEST_PRNG__ -O2 -std=c99 $< -o $@ .PHONY: test: test-x86 test-k1c diff --git a/test/mppa/mmult/Makefile b/test/mppa/mmult/Makefile index 23b31d49..9c00f8b0 100644 --- a/test/mppa/mmult/Makefile +++ b/test/mppa/mmult/Makefile @@ -9,19 +9,19 @@ all: $(ALL) gcc -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ %-test-k1c: %.c $(PRNG) - k1-gcc -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ + k1-mbr-gcc -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ test-x86: mmult.c $(PRNG) gcc -O2 -std=c99 $^ -o $@ test-k1c: mmult.c $(PRNG) - k1-gcc -O2 -std=c99 $^ -o $@ + k1-mbr-gcc -O2 -std=c99 $^ -o $@ %.s: %.c $(CCOMP) ccomp -O2 -S $< -o $@ test-ccomp: mmult.s $(subst .c,.s,$(PRNG)) - k1-gcc $^ -o $@ + k1-mbr-gcc $^ -o $@ .PHONY: unittest: unittest-x86 unittest-k1c diff --git a/test/mppa/sort/Makefile b/test/mppa/sort/Makefile index f94fe6b8..26c597be 100644 --- a/test/mppa/sort/Makefile +++ b/test/mppa/sort/Makefile @@ -13,19 +13,19 @@ all: $(ALL) gcc -g -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ %-test-k1c: %.c $(PRNG) - k1-gcc -g -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ + k1-mbr-gcc -g -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ test-x86: selection.c merge.c insertion.c test.c $(PRNG) gcc -g -O2 -std=c99 $^ -o $@ test-k1c: selection.c merge.c insertion.c test.c $(PRNG) - k1-gcc -g -O2 -std=c99 $^ -o $@ + k1-mbr-gcc -g -O2 -std=c99 $^ -o $@ %.s: %.c $(CCOMP) ccomp -O2 -S $< -o $@ test-ccomp: selection.s merge.s insertion.s test.s $(subst .c,.s,$(PRNG)) - k1-gcc $^ -o $@ + k1-mbr-gcc $^ -o $@ .PHONY: unittest: unittest-x86 unittest-k1c -- cgit From 622a211d4ebd47feb4d2c7dfe590d10c6d6ae834 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Fri, 9 Nov 2018 15:19:04 +0100 Subject: Fixing PRNG test --- test/mppa/lib/prng.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'test') diff --git a/test/mppa/lib/prng.c b/test/mppa/lib/prng.c index 59ec7ca6..af3903d6 100644 --- a/test/mppa/lib/prng.c +++ b/test/mppa/lib/prng.c @@ -29,14 +29,11 @@ char bytewise_sum(uint64_t to_check){ int main(void){ srand(42); - if (bytewise_sum(0xdeadbeefb00b1355ULL) != 91) - return 1; - for (int i = 0 ; i < 1000 ; i++) randlong(); uint64_t last = randlong(); - return !((unsigned char)bytewise_sum(last) == 251); + return !((unsigned char)bytewise_sum(last) == 155); } #endif // __UNIT_TEST_PRNG__ -- cgit From f24d303df6cb125ca19b953bb364955cc6e8c246 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Fri, 9 Nov 2018 17:07:13 +0100 Subject: Fixed consistency between the different tests mmult, prng and sort --- test/mppa/lib/.gitignore | 2 -- test/mppa/lib/Makefile | 30 ---------------- test/mppa/lib/prng.c | 39 --------------------- test/mppa/lib/prng.h | 10 ------ test/mppa/lib/types.h | 7 ---- test/mppa/mmult/Makefile | 72 ++++++++++++-------------------------- test/mppa/mmult/README.md | 17 +++++++++ test/mppa/mmult/mmult.c | 44 +++++++++++++---------- test/mppa/prng/.gitignore | 2 ++ test/mppa/prng/Makefile | 49 ++++++++++++++++++++++++++ test/mppa/prng/README.md | 17 +++++++++ test/mppa/prng/prng.c | 41 ++++++++++++++++++++++ test/mppa/prng/prng.h | 10 ++++++ test/mppa/prng/types.h | 7 ++++ test/mppa/sort/Makefile | 87 ++++++++++++++++++++-------------------------- test/mppa/sort/README.md | 17 +++++++++ test/mppa/sort/insertion.c | 17 +++++---- test/mppa/sort/main.c | 34 ++++++++++++++++++ test/mppa/sort/merge.c | 25 +++++++------ test/mppa/sort/selection.c | 21 ++++++----- test/mppa/sort/test.c | 33 ------------------ 21 files changed, 315 insertions(+), 266 deletions(-) delete mode 100644 test/mppa/lib/.gitignore delete mode 100644 test/mppa/lib/Makefile delete mode 100644 test/mppa/lib/prng.c delete mode 100644 test/mppa/lib/prng.h delete mode 100644 test/mppa/lib/types.h create mode 100644 test/mppa/mmult/README.md create mode 100644 test/mppa/prng/.gitignore create mode 100644 test/mppa/prng/Makefile create mode 100644 test/mppa/prng/README.md create mode 100644 test/mppa/prng/prng.c create mode 100644 test/mppa/prng/prng.h create mode 100644 test/mppa/prng/types.h create mode 100644 test/mppa/sort/README.md create mode 100644 test/mppa/sort/main.c delete mode 100644 test/mppa/sort/test.c (limited to 'test') diff --git a/test/mppa/lib/.gitignore b/test/mppa/lib/.gitignore deleted file mode 100644 index 1879eaee..00000000 --- a/test/mppa/lib/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -prng-test-k1c -prng-test-x86 diff --git a/test/mppa/lib/Makefile b/test/mppa/lib/Makefile deleted file mode 100644 index 74e7ca8b..00000000 --- a/test/mppa/lib/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -prng-test-x86: prng.c - gcc -D__UNIT_TEST_PRNG__ -O2 -std=c99 $< -o $@ - -prng-test-k1c: prng.c - k1-mbr-gcc -D__UNIT_TEST_PRNG__ -O2 -std=c99 $< -o $@ - -.PHONY: -test: test-x86 test-k1c - -.PHONY: -test-x86: prng-test-x86 - @if ! ./$<; then\ - >&2 echo "ERROR: $< failed";\ - exit;\ - else\ - echo "x86: Test Succeeded";\ - fi - -.PHONY: -test-k1c: prng-test-k1c - @if ! k1-cluster -- ./$<; then\ - >&2 echo "ERROR: $< failed";\ - exit;\ - else\ - echo "k1c: Test Succeeded";\ - fi - -.PHONY: -clean: - rm -f prng-test-x86 prng-test-k1c diff --git a/test/mppa/lib/prng.c b/test/mppa/lib/prng.c deleted file mode 100644 index af3903d6..00000000 --- a/test/mppa/lib/prng.c +++ /dev/null @@ -1,39 +0,0 @@ -// 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; - - for (int i = 0 ; i < 8 ; i++) - sum += (to_check & (uint64_t)(0xFFULL << i*8)) >> i*8; - - return sum; -} - -int main(void){ - srand(42); - - for (int 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/lib/prng.h b/test/mppa/lib/prng.h deleted file mode 100644 index 6abdb45a..00000000 --- a/test/mppa/lib/prng.h +++ /dev/null @@ -1,10 +0,0 @@ -#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/lib/types.h b/test/mppa/lib/types.h deleted file mode 100644 index 584023e3..00000000 --- a/test/mppa/lib/types.h +++ /dev/null @@ -1,7 +0,0 @@ -#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/mmult/Makefile b/test/mppa/mmult/Makefile index 9c00f8b0..2e077f5e 100644 --- a/test/mppa/mmult/Makefile +++ b/test/mppa/mmult/Makefile @@ -1,44 +1,28 @@ -PRNG=../lib/prng.c -CCOMP=../../../ccomp +K1CC ?= k1-mbr-gcc +CC ?= gcc +CCOMP ?= ccomp +CFLAGS ?= -O2 -ALL= mmult-test-x86 mmult-test-k1c\ +PRNG=../prng/prng.c -all: $(ALL) - -%-test-x86: %.c $(PRNG) - gcc -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ - -%-test-k1c: %.c $(PRNG) - k1-mbr-gcc -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ - -test-x86: mmult.c $(PRNG) - gcc -O2 -std=c99 $^ -o $@ - -test-k1c: mmult.c $(PRNG) - k1-mbr-gcc -O2 -std=c99 $^ -o $@ +ALL= mmult-test-gcc-x86 mmult-test-gcc-k1c mmult-test-ccomp-k1c\ -%.s: %.c $(CCOMP) - ccomp -O2 -S $< -o $@ +all: $(ALL) -test-ccomp: mmult.s $(subst .c,.s,$(PRNG)) - k1-mbr-gcc $^ -o $@ +mmult-test-gcc-x86: mmult.c $(PRNG) + $(CC) $(CFLAGS) $^ -o $@ -.PHONY: -unittest: unittest-x86 unittest-k1c +mmult-test-gcc-k1c: mmult.c $(PRNG) + $(K1CC) $(CFLAGS) $^ -o $@ -.PHONY: -check: check-x86 check-k1c +mmult-test-ccomp-k1c: mmult.c $(PRNG) + $(CCOMP) $(CFLAGS) $^ -o $@ .PHONY: -compc-check: test-ccomp - @if ! k1-cluster -- ./$<; then\ - >&2 echo "ERROR k1c: mmult $< failed";\ - else\ - echo "k1c: Test mmult $< succeeded";\ - fi +test: test-x86 test-k1c .PHONY: -check-x86: test-x86 +test-x86: mmult-test-gcc-x86 @if ! ./$<; then\ >&2 echo "ERROR x86: $< failed";\ else\ @@ -46,7 +30,7 @@ check-x86: test-x86 fi .PHONY: -check-k1c: test-k1c +test-k1c: mmult-test-gcc-k1c @if ! k1-cluster -- ./$<; then\ >&2 echo "ERROR k1c: $< failed";\ else\ @@ -54,24 +38,12 @@ check-k1c: test-k1c fi .PHONY: -unittest-x86: mmult-test-x86 - @for test in $^; do\ - if ! ./$$test; then\ - >&2 echo "ERROR x86: $$test failed";\ - else\ - echo "x86: Test $$test Succeeded";\ - fi;\ - done - -.PHONY: -unittest-k1c: mmult-test-k1c - @for test in $^; do\ - if ! k1-cluster -- ./$$test; then\ - >&2 echo "ERROR k1c: $$test failed";\ - else\ - echo "k1c: Test $$test Succeeded";\ - fi;\ - done +check: mmult-test-ccomp-k1c + @if ! k1-cluster -- ./$<; then\ + >&2 echo "ERROR k1c: mmult $< failed";\ + else\ + echo "k1c: Test mmult $< succeeded";\ + fi .PHONY: clean: 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 index b674ca80..aeb91d48 100644 --- a/test/mppa/mmult/mmult.c +++ b/test/mppa/mmult/mmult.c @@ -1,5 +1,5 @@ -#include "../lib/types.h" -#include "../lib/prng.h" +#include "../prng/types.h" +#include "../prng/prng.h" #define __UNIT_TEST_MMULT__ @@ -10,24 +10,28 @@ #endif void mmult_row(uint64_t C[][SIZE], uint64_t A[][SIZE], uint64_t B[][SIZE]){ - for (int i = 0 ; i < SIZE ; i++) - for (int j = 0 ; j < SIZE ; j++) + int i, j, k; + + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++) C[i][j] = 0; - for (int i = 0 ; i < SIZE ; i++) - for (int j = 0 ; j < SIZE ; j++) - for (int k = 0 ; k < SIZE ; k++) + 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]){ - for (int i = 0 ; i < SIZE ; i++) - for (int j = 0 ; j < SIZE ; j++) + int i, j, k; + + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++) C[i][j] = 0; - for (int k = 0 ; k < SIZE ; k++) - for (int i = 0 ; i < SIZE ; i++) - for (int j = 0 ; j < SIZE ; j++) + 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]; } @@ -41,10 +45,11 @@ typedef struct mblock { void divac_mul(mblock *C, const mblock *A, const mblock *B){ const int size = C->imax - C->imin; + int i, j, k; - for (int i = 0 ; i < size ; i++) - for (int j = 0 ; j < size ; j++) - for (int k = 0 ; k < size ; 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); } @@ -119,9 +124,10 @@ static uint64_t A[SIZE][SIZE], B[SIZE][SIZE]; int main(void){ srand(42); + int i, j; - for (int i = 0 ; i < SIZE ; i++) - for (int j = 0 ; j < SIZE ; j++){ + for (i = 0 ; i < SIZE ; i++) + for (j = 0 ; j < SIZE ; j++){ A[i][j] = randlong(); B[i][j] = randlong(); } @@ -130,8 +136,8 @@ int main(void){ mmult_col(C2, A, B); mmult_divac(C3, A, B); - for (int i = 0 ; i < SIZE ; i++) - for (int j = 0 ; j < SIZE ; j++) + 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; diff --git a/test/mppa/prng/.gitignore b/test/mppa/prng/.gitignore new file mode 100644 index 00000000..1879eaee --- /dev/null +++ b/test/mppa/prng/.gitignore @@ -0,0 +1,2 @@ +prng-test-k1c +prng-test-x86 diff --git a/test/mppa/prng/Makefile b/test/mppa/prng/Makefile new file mode 100644 index 00000000..481a3fca --- /dev/null +++ b/test/mppa/prng/Makefile @@ -0,0 +1,49 @@ +K1CC ?= k1-mbr-gcc +CC ?= gcc +CCOMP ?= ccomp +CFLAGS ?= -O2 + +all: prng-test-gcc-x86 prng-test-gcc-k1c prng-test-ccomp-k1c + +prng-test-gcc-x86: prng.c + $(CC) -D__UNIT_TEST_PRNG__ $(CFLAGS) $< -o $@ + +prng-test-gcc-k1c: prng.c + $(K1CC) -D__UNIT_TEST_PRNG__ $(CFLAGS) $< -o $@ + +prng-test-ccomp-k1c: prng.c + $(CCOMP) -D__UNIT_TEST_PRNG__ $(CFLAGS) $< -o $@ + +.PHONY: +test: test-x86 test-k1c + +.PHONY: +test-x86: prng-test-gcc-x86 + @if ! ./$<; then\ + >&2 echo "ERROR: $< failed";\ + exit;\ + else\ + echo "$< Succeeded";\ + fi + +.PHONY: +test-k1c: prng-test-gcc-k1c + @if ! k1-cluster -- ./$<; then\ + >&2 echo "ERROR: $< failed";\ + exit;\ + else\ + echo "$< Succeeded";\ + fi + +.PHONY: +check: prng-test-ccomp-k1c + @if ! k1-cluster -- ./$<; then\ + >&2 echo "ERROR: $< failed";\ + exit;\ + else\ + echo "$< 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/Makefile b/test/mppa/sort/Makefile index 26c597be..c0c9347d 100644 --- a/test/mppa/sort/Makefile +++ b/test/mppa/sort/Makefile @@ -1,64 +1,40 @@ -PRNG=../lib/prng.c -CCOMP=../../../ccomp +K1CC ?= k1-mbr-gcc +CC ?= gcc +CCOMP ?= ccomp +CFLAGS ?= -O2 -ALL= insertion-test-x86 insertion-test-k1c\ - selection-test-x86 selection-test-k1c\ - merge-test-x86 merge-test-k1c\ - test-x86 test-k1c\ - test-ccomp +PRNG=../prng/prng.c -all: $(ALL) - -%-test-x86: %.c $(PRNG) - gcc -g -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ +CFILES=insertion.c merge.c selection.c main.c -%-test-k1c: %.c $(PRNG) - k1-mbr-gcc -g -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ -O2 -std=c99 $^ -o $@ +ALL= insertion-test-gcc-x86 insertion-test-gcc-k1c\ + selection-test-gcc-x86 selection-test-gcc-k1c\ + merge-test-gcc-x86 merge-test-gcc-k1c\ + main-test-gcc-x86 main-test-gcc-k1c\ + main-test-ccomp-k1c -test-x86: selection.c merge.c insertion.c test.c $(PRNG) - gcc -g -O2 -std=c99 $^ -o $@ +all: $(ALL) -test-k1c: selection.c merge.c insertion.c test.c $(PRNG) - k1-mbr-gcc -g -O2 -std=c99 $^ -o $@ +main-test-gcc-x86: $(CFILES) $(PRNG) + $(CC) $(CFLAGS) $^ -o $@ -%.s: %.c $(CCOMP) - ccomp -O2 -S $< -o $@ +%-test-gcc-x86: %.c $(PRNG) + $(CC) -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ $(CFLAGS) $^ -o $@ -test-ccomp: selection.s merge.s insertion.s test.s $(subst .c,.s,$(PRNG)) - k1-mbr-gcc $^ -o $@ +main-test-gcc-k1c: $(CFILES) $(PRNG) + $(K1CC) $(CFLAGS) $^ -o $@ -.PHONY: -unittest: unittest-x86 unittest-k1c +%-test-gcc-k1c: %.c $(PRNG) + $(K1CC) -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ $(CFLAGS) $^ -o $@ -.PHONY: -check: check-x86 check-k1c +main-test-ccomp-k1c: $(CFILES) $(PRNG) + $(CCOMP) $(CFLAGS) $^ -o $@ -.PHONY: -compc-check: test-ccomp - @if ! k1-cluster -- ./$<; then\ - >&2 echo "ERROR k1c: sort $< failed";\ - else\ - echo "k1c: Test sort $< succeeded";\ - fi - -.PHONY: -check-x86: test-x86 - @if ! ./$<; then\ - >&2 echo "ERROR x86: $< failed";\ - else\ - echo "x86: Test $< succeeded";\ - fi +%-test-ccomp-k1c: %.c $(PRNG) + $(CCOMP) -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ $(CFLAGS) $^ -o $@ .PHONY: -check-k1c: test-k1c - @if ! k1-cluster -- ./$<; then\ - >&2 echo "ERROR k1c: $< failed";\ - else\ - echo "k1c: Test $< succeeded";\ - fi - -.PHONY: -unittest-x86: insertion-test-x86 selection-test-x86 merge-test-x86 +test-x86: insertion-test-gcc-x86 selection-test-gcc-x86 merge-test-gcc-x86 main-test-gcc-x86 @for test in $^; do\ if ! ./$$test; then\ >&2 echo "ERROR x86: $$test failed";\ @@ -68,7 +44,7 @@ unittest-x86: insertion-test-x86 selection-test-x86 merge-test-x86 done .PHONY: -unittest-k1c: insertion-test-k1c selection-test-k1c merge-test-k1c +test-k1c: insertion-test-gcc-k1c selection-test-gcc-k1c merge-test-gcc-k1c main-test-gcc-k1c @for test in $^; do\ if ! k1-cluster -- ./$$test; then\ >&2 echo "ERROR k1c: $$test failed";\ @@ -77,6 +53,17 @@ unittest-k1c: insertion-test-k1c selection-test-k1c merge-test-k1c fi;\ done +.PHONY: +test: test-x86 test-k1c + +.PHONY: +check: main-test-ccomp-k1c + @if ! k1-cluster -- ./$<; then\ + >&2 echo "ERROR k1c: sort $< failed";\ + else\ + echo "k1c: Test sort $< succeeded";\ + fi + .PHONY: clean: rm -f $(ALL) 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 index 88093b64..bca09599 100644 --- a/test/mppa/sort/insertion.c +++ b/test/mppa/sort/insertion.c @@ -1,5 +1,5 @@ -#include "../lib/prng.h" -#include "../lib/types.h" +#include "../prng/prng.h" +#include "../prng/types.h" #ifdef __UNIT_TEST_INSERTION__ #define SIZE 100 @@ -14,16 +14,18 @@ void swap_ins(uint64_t *a, uint64_t *b){ } int insert_sort(uint64_t *res, const uint64_t *T){ + int i, j; + if (SIZE <= 0) return -1; - for (int i = 0 ; i < SIZE ; i++) + for (i = 0 ; i < SIZE ; i++) res[i] = T[i]; - for (int i = 0 ; i < SIZE-1 ; i++){ + for (i = 0 ; i < SIZE-1 ; i++){ if (res[i] > res[i+1]){ swap_ins(&res[i], &res[i+1]); - for (int j = i ; j > 0 ; j--) + for (j = i ; j > 0 ; j--) if (res[j-1] > res[j]) swap_ins(&res[j-1], &res[j]); } @@ -36,9 +38,10 @@ int insert_sort(uint64_t *res, const uint64_t *T){ int main(void){ uint64_t T[SIZE]; uint64_t res[SIZE]; + int i; srand(42); - for (int i = 0 ; i < SIZE ; i++) + for (i = 0 ; i < SIZE ; i++) T[i] = randlong(); /* Sorting the table */ @@ -46,7 +49,7 @@ int main(void){ /* Computing max(T) */ uint64_t max = T[0]; - for (int i = 1 ; i < SIZE ; i++) + for (i = 1 ; i < SIZE ; i++) if (T[i] > max) max = T[i]; 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 index b2d41ce3..99f8ba85 100644 --- a/test/mppa/sort/merge.c +++ b/test/mppa/sort/merge.c @@ -1,5 +1,5 @@ -#include "../lib/prng.h" -#include "../lib/types.h" +#include "../prng/prng.h" +#include "../prng/types.h" //https://en.wikipedia.org/wiki/Merge_sort @@ -15,8 +15,8 @@ int min(int a, int b){ void BottomUpMerge(const uint64_t *A, int iLeft, int iRight, int iEnd, uint64_t *B) { - int i = iLeft, j = iRight; - for (int k = iLeft; k < iEnd; k++) { + 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; @@ -30,18 +30,20 @@ void BottomUpMerge(const uint64_t *A, int iLeft, int iRight, int iEnd, uint64_t void CopyArray(uint64_t *to, const uint64_t *from) { const int n = SIZE; + int i; - for(int i = 0; i < n; 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 (int width = 1; width < n; width = 2 * width) + for (width = 1; width < n; width = 2 * width) { - for (int i = 0; i < n; i = i + 2 * width) + for (i = 0; i < n; i = i + 2 * width) { BottomUpMerge(A, i, min(i+width, n), min(i+2*width, n), B); } @@ -50,12 +52,14 @@ void BottomUpMergeSort(uint64_t *A, uint64_t *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 (int i = 0 ; i < SIZE ; i++) + for (i = 0 ; i < SIZE ; i++) A[i] = T[i]; BottomUpMergeSort(A, B); @@ -67,9 +71,10 @@ int merge_sort(uint64_t *res, const uint64_t *T){ int main(void){ uint64_t T[SIZE]; uint64_t res[SIZE]; + int i; srand(42); - for (int i = 0 ; i < SIZE ; i++) + for (i = 0 ; i < SIZE ; i++) T[i] = randlong(); /* Sorting the table */ @@ -77,7 +82,7 @@ int main(void){ /* Computing max(T) */ uint64_t max = T[0]; - for (int i = 1 ; i < SIZE ; i++) + for (i = 1 ; i < SIZE ; i++) if (T[i] > max) max = T[i]; diff --git a/test/mppa/sort/selection.c b/test/mppa/sort/selection.c index 89bc2c65..df4be04f 100644 --- a/test/mppa/sort/selection.c +++ b/test/mppa/sort/selection.c @@ -1,5 +1,5 @@ -#include "../lib/prng.h" -#include "../lib/types.h" +#include "../prng/prng.h" +#include "../prng/types.h" #ifdef __UNIT_TEST_SELECTION__ #define SIZE 100 @@ -14,15 +14,16 @@ void swap_sel(uint64_t *a, uint64_t *b){ } int select_sort(uint64_t *res, const uint64_t *T){ + int i, j, iMin; + if (SIZE <= 0) return -1; - for (int i = 0 ; i < SIZE ; i++) + for (i = 0 ; i < SIZE ; i++) res[i] = T[i]; - for (int j = 0 ; j < SIZE ; j++){ - int i; - int iMin = j; + for (j = 0 ; j < SIZE ; j++){ + iMin = j; for (i = j+1 ; i < SIZE ; i++) if (res[i] < res[iMin]) iMin = i; @@ -38,17 +39,19 @@ int select_sort(uint64_t *res, const uint64_t *T){ int main(void){ uint64_t T[SIZE]; uint64_t res[SIZE]; + uint64_t max; + int i; srand(42); - for (int i = 0 ; i < SIZE ; i++) + for (i = 0 ; i < SIZE ; i++) T[i] = randlong(); /* Sorting the table */ if (select_sort(res, T) < 0) return -1; /* Computing max(T) */ - uint64_t max = T[0]; - for (int i = 1 ; i < SIZE ; i++) + max = T[0]; + for (i = 1 ; i < SIZE ; i++) if (T[i] > max) max = T[i]; diff --git a/test/mppa/sort/test.c b/test/mppa/sort/test.c deleted file mode 100644 index e5e14fef..00000000 --- a/test/mppa/sort/test.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "../lib/prng.h" -#include "../lib/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]; - srand(42); - - for (int 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 (int i = 0 ; i < SIZE ; i++){ - if (!(res1[i] == res2[i] && res2[i] == res3[i])) - return -4; - } - - return 0; -} -- cgit From d15b2c014daf547e10504278ae42d4651dc71319 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 13 Nov 2018 11:44:56 +0100 Subject: Revamped the instruction testsuite (all instructions work except umodd and udivd) --- test/mppa/Makefile | 161 ++++++++++++++++++++++++++---------------- test/mppa/builtins/clzll.c | 7 ++ test/mppa/builtins/stsud.c | 7 ++ test/mppa/check.sh | 32 --------- test/mppa/general/.gitignore | 1 - test/mppa/general/addw.c | 5 -- test/mppa/general/andd.c | 5 -- test/mppa/general/andw.c | 5 -- test/mppa/general/branch.c | 10 --- test/mppa/general/branchz.c | 10 --- test/mppa/general/branchzu.c | 11 --- test/mppa/general/call.c | 16 ----- test/mppa/general/cb.deqz.c | 10 --- test/mppa/general/cb.dgez.c | 10 --- test/mppa/general/cb.dgtz.c | 10 --- test/mppa/general/cb.dlez.c | 10 --- test/mppa/general/cb.dltz.c | 10 --- test/mppa/general/cb.dnez.c | 10 --- test/mppa/general/cb.wgez.c | 10 --- test/mppa/general/cb.wgtz.c | 10 --- test/mppa/general/cb.wlez.c | 10 --- test/mppa/general/cb.wltz.c | 10 --- test/mppa/general/clzll.c | 7 -- test/mppa/general/compd.eq.c | 7 -- test/mppa/general/compd.geu.c | 7 -- test/mppa/general/compd.gt.c | 7 -- test/mppa/general/compd.gtu.c | 7 -- test/mppa/general/compd.le.c | 7 -- test/mppa/general/compd.leu.c | 7 -- test/mppa/general/compd.lt.c | 7 -- test/mppa/general/compd.ltu.c | 7 -- test/mppa/general/compd.ne.c | 7 -- test/mppa/general/compw.eq.c | 7 -- test/mppa/general/compw.geu.c | 7 -- test/mppa/general/compw.gt.c | 7 -- test/mppa/general/compw.gtu.c | 7 -- test/mppa/general/compw.le.c | 7 -- test/mppa/general/compw.leu.c | 7 -- test/mppa/general/compw.lt.c | 7 -- test/mppa/general/compw.ltu.c | 7 -- test/mppa/general/compw.ne.c | 7 -- test/mppa/general/div2.c | 7 -- test/mppa/general/for.c | 9 --- test/mppa/general/forvar.c | 9 --- test/mppa/general/forvarl.c | 10 --- test/mppa/general/framework.h | 26 ------- test/mppa/general/lbs.c | 9 --- test/mppa/general/lbz.c | 9 --- test/mppa/general/muld.c | 7 -- test/mppa/general/mulw.c | 7 -- test/mppa/general/negd.c | 7 -- test/mppa/general/ord.c | 7 -- test/mppa/general/sbfd.c | 7 -- test/mppa/general/sbfw.c | 7 -- test/mppa/general/simple.c | 7 -- test/mppa/general/sllw.c | 7 -- test/mppa/general/srad.c | 7 -- test/mppa/general/srld.c | 7 -- test/mppa/general/stsud.c | 7 -- test/mppa/general/udivd.c | 7 -- test/mppa/general/umodd.c | 7 -- test/mppa/general/xord.c | 7 -- test/mppa/generate.sh | 17 ----- test/mppa/instr/.gitignore | 1 + test/mppa/instr/addw.c | 5 ++ test/mppa/instr/andd.c | 5 ++ test/mppa/instr/andw.c | 5 ++ test/mppa/instr/branch.c | 10 +++ test/mppa/instr/branchz.c | 10 +++ test/mppa/instr/branchzu.c | 11 +++ test/mppa/instr/call.c | 16 +++++ test/mppa/instr/cb.deqz.c | 10 +++ test/mppa/instr/cb.dgez.c | 10 +++ test/mppa/instr/cb.dgtz.c | 10 +++ test/mppa/instr/cb.dlez.c | 10 +++ test/mppa/instr/cb.dltz.c | 10 +++ test/mppa/instr/cb.dnez.c | 10 +++ test/mppa/instr/cb.wgez.c | 10 +++ test/mppa/instr/cb.wgtz.c | 10 +++ test/mppa/instr/cb.wlez.c | 10 +++ test/mppa/instr/cb.wltz.c | 10 +++ test/mppa/instr/compd.eq.c | 7 ++ test/mppa/instr/compd.geu.c | 7 ++ test/mppa/instr/compd.gt.c | 7 ++ test/mppa/instr/compd.gtu.c | 7 ++ test/mppa/instr/compd.le.c | 7 ++ test/mppa/instr/compd.leu.c | 7 ++ test/mppa/instr/compd.lt.c | 7 ++ test/mppa/instr/compd.ltu.c | 7 ++ test/mppa/instr/compd.ne.c | 7 ++ test/mppa/instr/compw.eq.c | 7 ++ test/mppa/instr/compw.geu.c | 7 ++ test/mppa/instr/compw.gt.c | 7 ++ test/mppa/instr/compw.gtu.c | 7 ++ test/mppa/instr/compw.le.c | 7 ++ test/mppa/instr/compw.leu.c | 7 ++ test/mppa/instr/compw.lt.c | 7 ++ test/mppa/instr/compw.ltu.c | 7 ++ test/mppa/instr/compw.ne.c | 7 ++ test/mppa/instr/div2.c | 7 ++ test/mppa/instr/for.c | 9 +++ test/mppa/instr/forvar.c | 9 +++ test/mppa/instr/forvarl.c | 10 +++ test/mppa/instr/framework.h | 26 +++++++ test/mppa/instr/lbs.c | 9 +++ test/mppa/instr/lbz.c | 9 +++ test/mppa/instr/muld.c | 7 ++ test/mppa/instr/mulw.c | 7 ++ test/mppa/instr/negd.c | 7 ++ test/mppa/instr/ord.c | 7 ++ test/mppa/instr/sbfd.c | 7 ++ test/mppa/instr/sbfw.c | 7 ++ test/mppa/instr/simple.c | 7 ++ test/mppa/instr/sllw.c | 7 ++ test/mppa/instr/srad.c | 7 ++ test/mppa/instr/srld.c | 7 ++ test/mppa/instr/udivd.c | 7 ++ test/mppa/instr/umodd.c | 7 ++ test/mppa/instr/xord.c | 7 ++ 119 files changed, 574 insertions(+), 582 deletions(-) create mode 100644 test/mppa/builtins/clzll.c create mode 100644 test/mppa/builtins/stsud.c delete mode 100644 test/mppa/check.sh delete mode 100644 test/mppa/general/.gitignore delete mode 100644 test/mppa/general/addw.c delete mode 100644 test/mppa/general/andd.c delete mode 100644 test/mppa/general/andw.c delete mode 100644 test/mppa/general/branch.c delete mode 100644 test/mppa/general/branchz.c delete mode 100644 test/mppa/general/branchzu.c delete mode 100644 test/mppa/general/call.c delete mode 100644 test/mppa/general/cb.deqz.c delete mode 100644 test/mppa/general/cb.dgez.c delete mode 100644 test/mppa/general/cb.dgtz.c delete mode 100644 test/mppa/general/cb.dlez.c delete mode 100644 test/mppa/general/cb.dltz.c delete mode 100644 test/mppa/general/cb.dnez.c delete mode 100644 test/mppa/general/cb.wgez.c delete mode 100644 test/mppa/general/cb.wgtz.c delete mode 100644 test/mppa/general/cb.wlez.c delete mode 100644 test/mppa/general/cb.wltz.c delete mode 100644 test/mppa/general/clzll.c delete mode 100644 test/mppa/general/compd.eq.c delete mode 100644 test/mppa/general/compd.geu.c delete mode 100644 test/mppa/general/compd.gt.c delete mode 100644 test/mppa/general/compd.gtu.c delete mode 100644 test/mppa/general/compd.le.c delete mode 100644 test/mppa/general/compd.leu.c delete mode 100644 test/mppa/general/compd.lt.c delete mode 100644 test/mppa/general/compd.ltu.c delete mode 100644 test/mppa/general/compd.ne.c delete mode 100644 test/mppa/general/compw.eq.c delete mode 100644 test/mppa/general/compw.geu.c delete mode 100644 test/mppa/general/compw.gt.c delete mode 100644 test/mppa/general/compw.gtu.c delete mode 100644 test/mppa/general/compw.le.c delete mode 100644 test/mppa/general/compw.leu.c delete mode 100644 test/mppa/general/compw.lt.c delete mode 100644 test/mppa/general/compw.ltu.c delete mode 100644 test/mppa/general/compw.ne.c delete mode 100644 test/mppa/general/div2.c delete mode 100644 test/mppa/general/for.c delete mode 100644 test/mppa/general/forvar.c delete mode 100644 test/mppa/general/forvarl.c delete mode 100644 test/mppa/general/framework.h delete mode 100644 test/mppa/general/lbs.c delete mode 100644 test/mppa/general/lbz.c delete mode 100644 test/mppa/general/muld.c delete mode 100644 test/mppa/general/mulw.c delete mode 100644 test/mppa/general/negd.c delete mode 100644 test/mppa/general/ord.c delete mode 100644 test/mppa/general/sbfd.c delete mode 100644 test/mppa/general/sbfw.c delete mode 100644 test/mppa/general/simple.c delete mode 100644 test/mppa/general/sllw.c delete mode 100644 test/mppa/general/srad.c delete mode 100644 test/mppa/general/srld.c delete mode 100644 test/mppa/general/stsud.c delete mode 100644 test/mppa/general/udivd.c delete mode 100644 test/mppa/general/umodd.c delete mode 100644 test/mppa/general/xord.c delete mode 100644 test/mppa/generate.sh create mode 100644 test/mppa/instr/.gitignore create mode 100644 test/mppa/instr/addw.c create mode 100644 test/mppa/instr/andd.c create mode 100644 test/mppa/instr/andw.c create mode 100644 test/mppa/instr/branch.c create mode 100644 test/mppa/instr/branchz.c create mode 100644 test/mppa/instr/branchzu.c create mode 100644 test/mppa/instr/call.c create mode 100644 test/mppa/instr/cb.deqz.c create mode 100644 test/mppa/instr/cb.dgez.c create mode 100644 test/mppa/instr/cb.dgtz.c create mode 100644 test/mppa/instr/cb.dlez.c create mode 100644 test/mppa/instr/cb.dltz.c create mode 100644 test/mppa/instr/cb.dnez.c create mode 100644 test/mppa/instr/cb.wgez.c create mode 100644 test/mppa/instr/cb.wgtz.c create mode 100644 test/mppa/instr/cb.wlez.c create mode 100644 test/mppa/instr/cb.wltz.c create mode 100644 test/mppa/instr/compd.eq.c create mode 100644 test/mppa/instr/compd.geu.c create mode 100644 test/mppa/instr/compd.gt.c create mode 100644 test/mppa/instr/compd.gtu.c create mode 100644 test/mppa/instr/compd.le.c create mode 100644 test/mppa/instr/compd.leu.c create mode 100644 test/mppa/instr/compd.lt.c create mode 100644 test/mppa/instr/compd.ltu.c create mode 100644 test/mppa/instr/compd.ne.c create mode 100644 test/mppa/instr/compw.eq.c create mode 100644 test/mppa/instr/compw.geu.c create mode 100644 test/mppa/instr/compw.gt.c create mode 100644 test/mppa/instr/compw.gtu.c create mode 100644 test/mppa/instr/compw.le.c create mode 100644 test/mppa/instr/compw.leu.c create mode 100644 test/mppa/instr/compw.lt.c create mode 100644 test/mppa/instr/compw.ltu.c create mode 100644 test/mppa/instr/compw.ne.c create mode 100644 test/mppa/instr/div2.c create mode 100644 test/mppa/instr/for.c create mode 100644 test/mppa/instr/forvar.c create mode 100644 test/mppa/instr/forvarl.c create mode 100644 test/mppa/instr/framework.h create mode 100644 test/mppa/instr/lbs.c create mode 100644 test/mppa/instr/lbz.c create mode 100644 test/mppa/instr/muld.c create mode 100644 test/mppa/instr/mulw.c create mode 100644 test/mppa/instr/negd.c create mode 100644 test/mppa/instr/ord.c create mode 100644 test/mppa/instr/sbfd.c create mode 100644 test/mppa/instr/sbfw.c create mode 100644 test/mppa/instr/simple.c create mode 100644 test/mppa/instr/sllw.c create mode 100644 test/mppa/instr/srad.c create mode 100644 test/mppa/instr/srld.c create mode 100644 test/mppa/instr/udivd.c create mode 100644 test/mppa/instr/umodd.c create mode 100644 test/mppa/instr/xord.c (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile index 5b312475..148b16b3 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -1,70 +1,111 @@ -DIR=general -BINDIR=bin -ASMDIR=asm +K1CC ?= k1-mbr-gcc +CC ?= gcc +CCOMP ?= ccomp +CFLAGS ?= -O2 +SIMU ?= k1-cluster +TIMEOUT ?= 10s + +DIR=instr +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))) -CCOMP=../../ccomp -#TESTS=$(addprefix $(DIR)/,$(TESTNAMES)) -ELF=$(addprefix $(DIR)/$(BINDIR)/,$(addsuffix .bin,$(TESTNAMES))) -TOK=$(addprefix $(DIR)/$(BINDIR)/,$(addsuffix .tok,$(TESTNAMES))) -ASM=$(addprefix $(DIR)/$(ASMDIR)/,$(addsuffix .s,$(TESTNAMES))) -DEBUG:=$(if $(DEBUG),"-dall",) +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))) -.PHONY: all -all: $(ELF) +## +# Targets +## -nobin: $(ASM) +all: $(BIN) -$(DIR)/$(BINDIR)/%.bin: $(DIR)/$(ASMDIR)/%.s - @mkdir -p $(@D) - ccomp $< -o $@ +.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: -$(DIR)/$(ASMDIR)/%.s: $(DIR)/%.c $(CCOMP) +# Generating output + +$(OUTDIR)/%.x86-gcc.out: $(BINDIR)/%.x86-gcc.bin + @mkdir -p $(@D) + timeout $(TIMEOUT) ./$< || { ret=$$?; } > $@; echo $$ret >> $@ + +$(OUTDIR)/%.gcc.out: $(BINDIR)/%.gcc.bin $(SIMUPATH) + @mkdir -p $(@D) + timeout $(TIMEOUT) $(SIMU) -- $< || { ret=$$?; } > $@; echo $$ret >> $@ + +$(OUTDIR)/%.ccomp.out: $(BINDIR)/%.ccomp.bin $(SIMUPATH) + @mkdir -p $(@D) + 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) - ccomp $(DEBUG) -O0 -v -S $< -o $@ + $(K1CC) $(CFLAGS) -S $< -o $@ -$(DIR)/$(BINDIR)/%.tok: $(DIR)/$(BINDIR)/%.bin $(DIR)/output/%.bin.exp +$(ASMDIR)/%.ccomp.s: $(SRCDIR)/%.c $(CCOMPPATH) @mkdir -p $(@D) - @bash check.sh $< $@ - -$(DIR)/output/%.bin.exp: $(DIR)/%.c - @bash generate.sh $< $@ - -.PHONY: FORCE -FORCE: - -.PHONY: check -check: $(TOK) sort mmult - -.PHONY: coverage -coverage: $(ASM) - bash coverage.sh $(DIR)/$(ASMDIR) - - -.PHONY: sort -sort: FORCE - (cd sort && make compc-check) - -.PHONY: mmult -mmult: FORCE - (cd mmult && make compc-check) - -.PHONY: clean -clean: - rm -f $(DIR)/*.alloctrace - rm -f $(DIR)/*.cm - rm -f $(DIR)/*.compcert.c - rm -f $(DIR)/*.i - rm -f $(DIR)/*.light.c - rm -f $(DIR)/*.ltl - rm -f $(DIR)/*.mach - rm -f $(DIR)/*.parsed.c - rm -f $(DIR)/*.rtl.? - rm -f $(DIR)/$(ASMDIR)/*.s - rm -f $(DIR)/$(BINDIR)/*.bin - rm -f $(DIR)/$(BINDIR)/*.tok - rm -f $(DIR)/output/*.out - rm -f $(DIR)/output/*.exp - rm -rf $(DIR)/profile/ - rm -f $(ELF) + $(CCOMP) $(CFLAGS) -S $< -o $@ 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..81fb6e6d --- /dev/null +++ b/test/mppa/builtins/stsud.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned long long) +{ + c = __builtin_k1_stsud(a, b); +} +END_TEST() diff --git a/test/mppa/check.sh b/test/mppa/check.sh deleted file mode 100644 index dd9691be..00000000 --- a/test/mppa/check.sh +++ /dev/null @@ -1,32 +0,0 @@ -# $1: binary file to check -# $2: output check token - -elffile="$1" -token="$2" - -if [ ! -f $elffile ]; then - >&2 echo "ERROR: $elffile not found" - shift; continue -fi - -dir="$(dirname $elffile)" -elf="$(basename $elffile)" - -exp="$dir/../output/$elf.exp" -out="$dir/../output/$elf.out" -if [ ! -f $exp ]; then - >&2 echo "ERROR: $exp not found" - exit -fi - -k1-cluster -- $elffile > $out -echo $? >> $out - -if ! diff $exp $out; then - >&2 echo "ERROR: $exp and $out differ" - exit -fi - -echo "PASSED: $elf" -touch $token -#shift diff --git a/test/mppa/general/.gitignore b/test/mppa/general/.gitignore deleted file mode 100644 index ea1472ec..00000000 --- a/test/mppa/general/.gitignore +++ /dev/null @@ -1 +0,0 @@ -output/ diff --git a/test/mppa/general/addw.c b/test/mppa/general/addw.c deleted file mode 100644 index be8afc67..00000000 --- a/test/mppa/general/addw.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) - c = a+b; -END_TEST() diff --git a/test/mppa/general/andd.c b/test/mppa/general/andd.c deleted file mode 100644 index 4f503764..00000000 --- a/test/mppa/general/andd.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) - return a&b; -END_TEST() diff --git a/test/mppa/general/andw.c b/test/mppa/general/andw.c deleted file mode 100644 index 99de0049..00000000 --- a/test/mppa/general/andw.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) - c = a&b; -END_TEST() diff --git a/test/mppa/general/branch.c b/test/mppa/general/branch.c deleted file mode 100644 index 72e7e20e..00000000 --- a/test/mppa/general/branch.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - if ((a & 0x1) == 1) - c = 0; - else - c = 1; -} -END_TEST() diff --git a/test/mppa/general/branchz.c b/test/mppa/general/branchz.c deleted file mode 100644 index fb86d357..00000000 --- a/test/mppa/general/branchz.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - if (a & 0x1 == 0) - c = 0; - else - c = 1; -} -END_TEST() diff --git a/test/mppa/general/branchzu.c b/test/mppa/general/branchzu.c deleted file mode 100644 index 97adb605..00000000 --- a/test/mppa/general/branchzu.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - b = !(a & 0x01); - if (!b) - c = 0; - else - c = 1; -} -END_TEST() diff --git a/test/mppa/general/call.c b/test/mppa/general/call.c deleted file mode 100644 index 727cef63..00000000 --- a/test/mppa/general/call.c +++ /dev/null @@ -1,16 +0,0 @@ -#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/general/cb.deqz.c b/test/mppa/general/cb.deqz.c deleted file mode 100644 index c56733f0..00000000 --- a/test/mppa/general/cb.deqz.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - if (0 != (a & 0x1LL)) - c = 1; - else - c = 0; -} -END_TEST() diff --git a/test/mppa/general/cb.dgez.c b/test/mppa/general/cb.dgez.c deleted file mode 100644 index abb6ec57..00000000 --- a/test/mppa/general/cb.dgez.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - if (0 > (a & 0x1LL)) - c = 1; - else - c = 0; -} -END_TEST() diff --git a/test/mppa/general/cb.dgtz.c b/test/mppa/general/cb.dgtz.c deleted file mode 100644 index d4271845..00000000 --- a/test/mppa/general/cb.dgtz.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - if (0 >= (a & 0x1LL) - 1) - c = 1; - else - c = 0; -} -END_TEST() diff --git a/test/mppa/general/cb.dlez.c b/test/mppa/general/cb.dlez.c deleted file mode 100644 index 18e67f06..00000000 --- a/test/mppa/general/cb.dlez.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - if (a & 0x1LL > 0) - c = 1; - else - c = 0; -} -END_TEST() diff --git a/test/mppa/general/cb.dltz.c b/test/mppa/general/cb.dltz.c deleted file mode 100644 index 366aea49..00000000 --- a/test/mppa/general/cb.dltz.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - if ((a & 0x1LL) - 1 >= 0) - c = 1; - else - c = 0; -} -END_TEST() diff --git a/test/mppa/general/cb.dnez.c b/test/mppa/general/cb.dnez.c deleted file mode 100644 index 81c2cd29..00000000 --- a/test/mppa/general/cb.dnez.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - if (0 == (a & 0x1LL)) - c = 1; - else - c = 0; -} -END_TEST() diff --git a/test/mppa/general/cb.wgez.c b/test/mppa/general/cb.wgez.c deleted file mode 100644 index 477f4bc6..00000000 --- a/test/mppa/general/cb.wgez.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - if (0 > (a & 0x1) - 1) - c = 1; - else - c = 0; -} -END_TEST() diff --git a/test/mppa/general/cb.wgtz.c b/test/mppa/general/cb.wgtz.c deleted file mode 100644 index c9ab9a06..00000000 --- a/test/mppa/general/cb.wgtz.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - if (0 >= (a & 0x1)) - c = 1; - else - c = 0; -} -END_TEST() diff --git a/test/mppa/general/cb.wlez.c b/test/mppa/general/cb.wlez.c deleted file mode 100644 index c3069fda..00000000 --- a/test/mppa/general/cb.wlez.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - if ((a & 0x1) > 0) - c = 1; - else - c = 0; -} -END_TEST() diff --git a/test/mppa/general/cb.wltz.c b/test/mppa/general/cb.wltz.c deleted file mode 100644 index 6cf5fcf0..00000000 --- a/test/mppa/general/cb.wltz.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - if ((a & 0x1) - 1 >= 0) - c = 1; - else - c = 0; -} -END_TEST() diff --git a/test/mppa/general/clzll.c b/test/mppa/general/clzll.c deleted file mode 100644 index 13905cba..00000000 --- a/test/mppa/general/clzll.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - c = __builtin_clzll(a); -} -END_TEST() diff --git a/test/mppa/general/compd.eq.c b/test/mppa/general/compd.eq.c deleted file mode 100644 index d19a4d20..00000000 --- a/test/mppa/general/compd.eq.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - c = ((a & 0x1LL) == (b & 0x1LL)); -} -END_TEST() diff --git a/test/mppa/general/compd.geu.c b/test/mppa/general/compd.geu.c deleted file mode 100644 index edc31183..00000000 --- a/test/mppa/general/compd.geu.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned long long) -{ - c = (a >= b); -} -END_TEST() diff --git a/test/mppa/general/compd.gt.c b/test/mppa/general/compd.gt.c deleted file mode 100644 index 24147779..00000000 --- a/test/mppa/general/compd.gt.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - c = (a > b); -} -END_TEST() diff --git a/test/mppa/general/compd.gtu.c b/test/mppa/general/compd.gtu.c deleted file mode 100644 index 5ce82569..00000000 --- a/test/mppa/general/compd.gtu.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned long long) -{ - c = (a > b); -} -END_TEST() diff --git a/test/mppa/general/compd.le.c b/test/mppa/general/compd.le.c deleted file mode 100644 index a84aad97..00000000 --- a/test/mppa/general/compd.le.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - c = (a <= b); -} -END_TEST() diff --git a/test/mppa/general/compd.leu.c b/test/mppa/general/compd.leu.c deleted file mode 100644 index e386bc27..00000000 --- a/test/mppa/general/compd.leu.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned long long) -{ - c = (a <= b); -} -END_TEST() diff --git a/test/mppa/general/compd.lt.c b/test/mppa/general/compd.lt.c deleted file mode 100644 index df07a708..00000000 --- a/test/mppa/general/compd.lt.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - c = (a < b); -} -END_TEST() diff --git a/test/mppa/general/compd.ltu.c b/test/mppa/general/compd.ltu.c deleted file mode 100644 index dfaa8921..00000000 --- a/test/mppa/general/compd.ltu.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned long long) -{ - c = (a < b); -} -END_TEST() diff --git a/test/mppa/general/compd.ne.c b/test/mppa/general/compd.ne.c deleted file mode 100644 index 19ce0a69..00000000 --- a/test/mppa/general/compd.ne.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned long long) -{ - c = ((a & 0x1ULL) != (b & 0x1ULL)); -} -END_TEST() diff --git a/test/mppa/general/compw.eq.c b/test/mppa/general/compw.eq.c deleted file mode 100644 index dc7a3ab1..00000000 --- a/test/mppa/general/compw.eq.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - c = ((a & 0x1) == (b & 0x1)); -} -END_TEST() diff --git a/test/mppa/general/compw.geu.c b/test/mppa/general/compw.geu.c deleted file mode 100644 index d72ca56c..00000000 --- a/test/mppa/general/compw.geu.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned int) -{ - c = (a >= b); -} -END_TEST() diff --git a/test/mppa/general/compw.gt.c b/test/mppa/general/compw.gt.c deleted file mode 100644 index 9ad02610..00000000 --- a/test/mppa/general/compw.gt.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - c = (a > b); -} -END_TEST() diff --git a/test/mppa/general/compw.gtu.c b/test/mppa/general/compw.gtu.c deleted file mode 100644 index 77f04989..00000000 --- a/test/mppa/general/compw.gtu.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned int) -{ - c = (a > b); -} -END_TEST() diff --git a/test/mppa/general/compw.le.c b/test/mppa/general/compw.le.c deleted file mode 100644 index b7a7a432..00000000 --- a/test/mppa/general/compw.le.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - c = (a <= b); -} -END_TEST() diff --git a/test/mppa/general/compw.leu.c b/test/mppa/general/compw.leu.c deleted file mode 100644 index 4892f06c..00000000 --- a/test/mppa/general/compw.leu.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned int) -{ - c = (a <= b); -} -END_TEST() diff --git a/test/mppa/general/compw.lt.c b/test/mppa/general/compw.lt.c deleted file mode 100644 index 2cc151bf..00000000 --- a/test/mppa/general/compw.lt.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - c = (a < b); -} -END_TEST() diff --git a/test/mppa/general/compw.ltu.c b/test/mppa/general/compw.ltu.c deleted file mode 100644 index b524127f..00000000 --- a/test/mppa/general/compw.ltu.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned int) -{ - c = (a < b); -} -END_TEST() diff --git a/test/mppa/general/compw.ne.c b/test/mppa/general/compw.ne.c deleted file mode 100644 index 433b0b86..00000000 --- a/test/mppa/general/compw.ne.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned int) -{ - c = ((a & 0x1U) != (b & 0x1U)); -} -END_TEST() diff --git a/test/mppa/general/div2.c b/test/mppa/general/div2.c deleted file mode 100644 index 01a4b575..00000000 --- a/test/mppa/general/div2.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - c = (a + b) / 2; -} -END_TEST() diff --git a/test/mppa/general/for.c b/test/mppa/general/for.c deleted file mode 100644 index d6870afb..00000000 --- a/test/mppa/general/for.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - int j; - for (j = 0 ; j < 10 ; j++) - c += a; -} -END_TEST() diff --git a/test/mppa/general/forvar.c b/test/mppa/general/forvar.c deleted file mode 100644 index 57548274..00000000 --- a/test/mppa/general/forvar.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - int j; - for (j = 0 ; j < (b & 0x8) ; j++) - c += a; -} -END_TEST() diff --git a/test/mppa/general/forvarl.c b/test/mppa/general/forvarl.c deleted file mode 100644 index 30717a51..00000000 --- a/test/mppa/general/forvarl.c +++ /dev/null @@ -1,10 +0,0 @@ -#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/general/framework.h b/test/mppa/general/framework.h deleted file mode 100644 index 78f2617e..00000000 --- a/test/mppa/general/framework.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef __FRAMEWORK_H__ -#define __FRAMEWORK_H__ - -#include "../lib/prng.c" - -#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/general/lbs.c b/test/mppa/general/lbs.c deleted file mode 100644 index f104d62b..00000000 --- a/test/mppa/general/lbs.c +++ /dev/null @@ -1,9 +0,0 @@ -#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/general/lbz.c b/test/mppa/general/lbz.c deleted file mode 100644 index 2deeaebe..00000000 --- a/test/mppa/general/lbz.c +++ /dev/null @@ -1,9 +0,0 @@ -#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/general/muld.c b/test/mppa/general/muld.c deleted file mode 100644 index 9a40f389..00000000 --- a/test/mppa/general/muld.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - c = a*b; -} -END_TEST() diff --git a/test/mppa/general/mulw.c b/test/mppa/general/mulw.c deleted file mode 100644 index bf517ce8..00000000 --- a/test/mppa/general/mulw.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - c = a * b; -} -END_TEST() diff --git a/test/mppa/general/negd.c b/test/mppa/general/negd.c deleted file mode 100644 index a8e8ff45..00000000 --- a/test/mppa/general/negd.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - c = -a; -} -END_TEST() diff --git a/test/mppa/general/ord.c b/test/mppa/general/ord.c deleted file mode 100644 index eaedcb28..00000000 --- a/test/mppa/general/ord.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - c = a | b; -} -END_TEST() diff --git a/test/mppa/general/sbfd.c b/test/mppa/general/sbfd.c deleted file mode 100644 index 912f1fdb..00000000 --- a/test/mppa/general/sbfd.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - c = a-b; -} -END_TEST() diff --git a/test/mppa/general/sbfw.c b/test/mppa/general/sbfw.c deleted file mode 100644 index feffd497..00000000 --- a/test/mppa/general/sbfw.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - c = a-b; -} -END_TEST() diff --git a/test/mppa/general/simple.c b/test/mppa/general/simple.c deleted file mode 100644 index 89bba27e..00000000 --- a/test/mppa/general/simple.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - c = a+b; -} -END_TEST() diff --git a/test/mppa/general/sllw.c b/test/mppa/general/sllw.c deleted file mode 100644 index df55c9e8..00000000 --- a/test/mppa/general/sllw.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(int) -{ - c = a << (b & 0x8); -} -END_TEST() diff --git a/test/mppa/general/srad.c b/test/mppa/general/srad.c deleted file mode 100644 index b4047bc7..00000000 --- a/test/mppa/general/srad.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - c = a >> (b & 0x8LL); -} -END_TEST() diff --git a/test/mppa/general/srld.c b/test/mppa/general/srld.c deleted file mode 100644 index 71e82b2a..00000000 --- a/test/mppa/general/srld.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned long long) -{ - c = a >> (b & 0x8ULL); -} -END_TEST() diff --git a/test/mppa/general/stsud.c b/test/mppa/general/stsud.c deleted file mode 100644 index 81fb6e6d..00000000 --- a/test/mppa/general/stsud.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned long long) -{ - c = __builtin_k1_stsud(a, b); -} -END_TEST() diff --git a/test/mppa/general/udivd.c b/test/mppa/general/udivd.c deleted file mode 100644 index 52e0d412..00000000 --- a/test/mppa/general/udivd.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned long long) -{ - c = a/b; -} -END_TEST() diff --git a/test/mppa/general/umodd.c b/test/mppa/general/umodd.c deleted file mode 100644 index e7dd506f..00000000 --- a/test/mppa/general/umodd.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(unsigned long long) -{ - c = a%b; -} -END_TEST() diff --git a/test/mppa/general/xord.c b/test/mppa/general/xord.c deleted file mode 100644 index b9d86f06..00000000 --- a/test/mppa/general/xord.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "framework.h" - -BEGIN_TEST(long long) -{ - c = a^b; -} -END_TEST() diff --git a/test/mppa/generate.sh b/test/mppa/generate.sh deleted file mode 100644 index a883b8f5..00000000 --- a/test/mppa/generate.sh +++ /dev/null @@ -1,17 +0,0 @@ -# $1: c file to examine -# $2: write file - -cfile="$1" -writefile="$2" - -if [ ! -f $cfile ]; then - >&2 echo "ERROR: $cfile not found" - shift; continue -fi - -mkdir -p $(dirname $writefile) - -#sed -n "s/^.*\/\*\s*RETURN VALUE:\s*\([0-9]*\)\s*\*\//\1/p" $1 > $2 -tmpbin=/tmp/k1-$(basename $1)-bin -k1-mbr-gcc -O0 $1 -o $tmpbin -(k1-cluster -- $tmpbin; echo $? > $2) 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/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..f6077c46 --- /dev/null +++ b/test/mppa/instr/framework.h @@ -0,0 +1,26 @@ +#ifndef __FRAMEWORK_H__ +#define __FRAMEWORK_H__ + +#include "../prng/prng.c" + +#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() -- cgit From 0c28f0900dae418d5beed6a82f7c72f88de83567 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 13 Nov 2018 13:44:55 +0100 Subject: Lancement des tests à partir d'un même script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/mppa/Makefile | 111 --------------------------------------------- test/mppa/check.sh | 6 +++ test/mppa/do_test.sh | 33 ++++++++++++++ test/mppa/instr/Makefile | 111 +++++++++++++++++++++++++++++++++++++++++++++ test/mppa/mmult/.gitignore | 6 +-- test/mppa/prng/.gitignore | 5 +- test/mppa/sort/.gitignore | 18 ++++---- test/mppa/test.sh | 6 +++ 8 files changed, 171 insertions(+), 125 deletions(-) delete mode 100644 test/mppa/Makefile create mode 100755 test/mppa/check.sh create mode 100644 test/mppa/do_test.sh create mode 100644 test/mppa/instr/Makefile create mode 100755 test/mppa/test.sh (limited to 'test') diff --git a/test/mppa/Makefile b/test/mppa/Makefile deleted file mode 100644 index 148b16b3..00000000 --- a/test/mppa/Makefile +++ /dev/null @@ -1,111 +0,0 @@ -K1CC ?= k1-mbr-gcc -CC ?= gcc -CCOMP ?= ccomp -CFLAGS ?= -O2 -SIMU ?= k1-cluster -TIMEOUT ?= 10s - -DIR=instr -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) - timeout $(TIMEOUT) ./$< || { ret=$$?; } > $@; echo $$ret >> $@ - -$(OUTDIR)/%.gcc.out: $(BINDIR)/%.gcc.bin $(SIMUPATH) - @mkdir -p $(@D) - timeout $(TIMEOUT) $(SIMU) -- $< || { ret=$$?; } > $@; echo $$ret >> $@ - -$(OUTDIR)/%.ccomp.out: $(BINDIR)/%.ccomp.bin $(SIMUPATH) - @mkdir -p $(@D) - 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/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/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/instr/Makefile b/test/mppa/instr/Makefile new file mode 100644 index 00000000..4744ba23 --- /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) + timeout $(TIMEOUT) ./$< || { ret=$$?; } > $@; echo $$ret >> $@ + +$(OUTDIR)/%.gcc.out: $(BINDIR)/%.gcc.bin $(SIMUPATH) + @mkdir -p $(@D) + timeout $(TIMEOUT) $(SIMU) -- $< || { ret=$$?; } > $@; echo $$ret >> $@ + +$(OUTDIR)/%.ccomp.out: $(BINDIR)/%.ccomp.bin $(SIMUPATH) + @mkdir -p $(@D) + 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/mmult/.gitignore b/test/mppa/mmult/.gitignore index 5883d367..4d68861b 100644 --- a/test/mppa/mmult/.gitignore +++ b/test/mppa/mmult/.gitignore @@ -1,3 +1,3 @@ -mmult-test-k1c -mmult-test-x86 -test-ccomp +mmult-test-ccomp-k1c +mmult-test-gcc-k1c +mmult-test-gcc-x86 diff --git a/test/mppa/prng/.gitignore b/test/mppa/prng/.gitignore index 1879eaee..0792a78b 100644 --- a/test/mppa/prng/.gitignore +++ b/test/mppa/prng/.gitignore @@ -1,2 +1,3 @@ -prng-test-k1c -prng-test-x86 +prng-test-ccomp-k1c +prng-test-gcc-x86 +prng-test-gcc-k1c diff --git a/test/mppa/sort/.gitignore b/test/mppa/sort/.gitignore index c8f4f4e5..a8d6921c 100644 --- a/test/mppa/sort/.gitignore +++ b/test/mppa/sort/.gitignore @@ -1,9 +1,9 @@ -insertion-test-k1c -insertion-test-x86 -merge-test-k1c -selection-test-k1c -test-k1c -merge-test-x86 -selection-test-x86 -test-x86 -test-ccomp +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/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 -- cgit From 6e1ff91536ce40e16e0f6af7f2d032ffda2f752c Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 13 Nov 2018 18:15:42 +0100 Subject: Changed mmult to avoid recomputing + fixed potential source of bug in instr --- test/mppa/instr/Makefile | 6 +++--- test/mppa/mmult/.gitignore | 1 + test/mppa/mmult/Makefile | 53 ++++++++++++++++++++++++++++++---------------- 3 files changed, 39 insertions(+), 21 deletions(-) (limited to 'test') diff --git a/test/mppa/instr/Makefile b/test/mppa/instr/Makefile index 4744ba23..2be69db2 100644 --- a/test/mppa/instr/Makefile +++ b/test/mppa/instr/Makefile @@ -72,15 +72,15 @@ check: $(GCC_OUT) $(CCOMP_OUT) $(OUTDIR)/%.x86-gcc.out: $(BINDIR)/%.x86-gcc.bin @mkdir -p $(@D) - timeout $(TIMEOUT) ./$< || { ret=$$?; } > $@; echo $$ret >> $@ + ret=0; timeout $(TIMEOUT) ./$< || { ret=$$?; } > $@; echo $$ret >> $@ $(OUTDIR)/%.gcc.out: $(BINDIR)/%.gcc.bin $(SIMUPATH) @mkdir -p $(@D) - timeout $(TIMEOUT) $(SIMU) -- $< || { ret=$$?; } > $@; echo $$ret >> $@ + ret=0; timeout $(TIMEOUT) $(SIMU) -- $< || { ret=$$?; } > $@; echo $$ret >> $@ $(OUTDIR)/%.ccomp.out: $(BINDIR)/%.ccomp.bin $(SIMUPATH) @mkdir -p $(@D) - timeout $(TIMEOUT) $(SIMU) -- $< || { ret=$$?; } > $@; echo $$ret >> $@ + ret=0; timeout $(TIMEOUT) $(SIMU) -- $< || { ret=$$?; } > $@; echo $$ret >> $@ # Assembly to binary diff --git a/test/mppa/mmult/.gitignore b/test/mppa/mmult/.gitignore index 4d68861b..c9cd4c65 100644 --- a/test/mppa/mmult/.gitignore +++ b/test/mppa/mmult/.gitignore @@ -1,3 +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 index 2e077f5e..263ed276 100644 --- a/test/mppa/mmult/Makefile +++ b/test/mppa/mmult/Makefile @@ -2,49 +2,66 @@ 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\ +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) +mmult-test-gcc-x86: mmult.c $(PRNG) $(CCPATH) $(CC) $(CFLAGS) $^ -o $@ -mmult-test-gcc-k1c: mmult.c $(PRNG) +mmult-test-gcc-k1c: mmult.c $(PRNG) $(K1CCPATH) $(K1CC) $(CFLAGS) $^ -o $@ -mmult-test-ccomp-k1c: mmult.c $(PRNG) +mmult-test-ccomp-k1c: mmult.c $(PRNG) $(CCOMPPATH) $(CCOMP) $(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: mmult-test-gcc-x86 - @if ! ./$<; then\ +test-x86: $(X86_GCC_OUT) $(STUB_OUT) + @if ! diff $< $(STUB_OUT); then\ >&2 echo "ERROR x86: $< failed";\ else\ - echo "x86: Test $< succeeded";\ + echo "GOOD x86: $< succeeded";\ fi .PHONY: -test-k1c: mmult-test-gcc-k1c - @if ! k1-cluster -- ./$<; then\ +test-k1c: $(GCC_OUT) $(STUB_OUT) + @if ! diff $< $(STUB_OUT); then\ >&2 echo "ERROR k1c: $< failed";\ else\ - echo "k1c: Test $< succeeded";\ + echo "GOOD k1c: $< succeeded";\ fi .PHONY: -check: mmult-test-ccomp-k1c - @if ! k1-cluster -- ./$<; then\ - >&2 echo "ERROR k1c: mmult $< failed";\ +check: $(CCOMP_OUT) $(STUB_OUT) + @if ! diff $< $(STUB_OUT); then\ + >&2 echo "ERROR k1c: $< failed";\ else\ - echo "k1c: Test mmult $< succeeded";\ + echo "GOOD k1c: $< succeeded";\ fi - -.PHONY: -clean: - rm -f $(ALL) -- cgit From 154230f3d9cad4f8de59e8fcaa9d0fe4ae151a98 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 14 Nov 2018 11:18:45 +0100 Subject: Updated Sort Makefile + fixed compilation command bug --- test/mppa/.gitignore | 19 ++++++++++ test/mppa/instr/Makefile | 6 ++-- test/mppa/mmult/Makefile | 10 +++--- test/mppa/prng/Makefile | 58 ++++++++++++++++++++---------- test/mppa/sort/Makefile | 92 ++++++++++++++++++++++++++++++------------------ 5 files changed, 123 insertions(+), 62 deletions(-) (limited to 'test') diff --git a/test/mppa/.gitignore b/test/mppa/.gitignore index f03fc12c..e8ebeff8 100644 --- a/test/mppa/.gitignore +++ b/test/mppa/.gitignore @@ -1 +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/instr/Makefile b/test/mppa/instr/Makefile index 2be69db2..89ff9a73 100644 --- a/test/mppa/instr/Makefile +++ b/test/mppa/instr/Makefile @@ -72,15 +72,15 @@ check: $(GCC_OUT) $(CCOMP_OUT) $(OUTDIR)/%.x86-gcc.out: $(BINDIR)/%.x86-gcc.bin @mkdir -p $(@D) - ret=0; timeout $(TIMEOUT) ./$< || { ret=$$?; } > $@; echo $$ret >> $@ + 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 >> $@ + 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 >> $@ + ret=0; timeout $(TIMEOUT) $(SIMU) -- $< > $@ || { ret=$$?; }; echo $$ret >> $@ # Assembly to binary diff --git a/test/mppa/mmult/Makefile b/test/mppa/mmult/Makefile index 263ed276..cf82e359 100644 --- a/test/mppa/mmult/Makefile +++ b/test/mppa/mmult/Makefile @@ -21,20 +21,20 @@ STUB_OUT=.zero all: $(ALL) mmult-test-gcc-x86: mmult.c $(PRNG) $(CCPATH) - $(CC) $(CFLAGS) $^ -o $@ + $(CC) $(CFLAGS) $(filter-out $(CCPATH),$^) -o $@ mmult-test-gcc-k1c: mmult.c $(PRNG) $(K1CCPATH) - $(K1CC) $(CFLAGS) $^ -o $@ + $(K1CC) $(CFLAGS) $(filter-out $(K1CCPATH),$^) -o $@ mmult-test-ccomp-k1c: mmult.c $(PRNG) $(CCOMPPATH) - $(CCOMP) $(CFLAGS) $^ -o $@ + $(CCOMP) $(CFLAGS) $(filter-out $(CCOMPPATH),$^) -o $@ .SECONDARY: %k1c.out: %k1c $(SIMUPATH) - ret=0; timeout $(TIMEOUT) $(SIMU) -- $< || { ret=$$?; } > $@; echo $$ret >> $@ + ret=0; timeout $(TIMEOUT) $(SIMU) -- $< > $@ || { ret=$$?; }; echo $$ret >> $@ %x86.out: %x86 - ret=0; timeout $(TIMEOUT) ./$< || { ret=$$?; } > $@; echo $$ret >> $@ + ret=0; timeout $(TIMEOUT) ./$< > $@ || { ret=$$?; }; echo $$ret >> $@ .zero: @echo "0" > $@ diff --git a/test/mppa/prng/Makefile b/test/mppa/prng/Makefile index 481a3fca..5580cd8e 100644 --- a/test/mppa/prng/Makefile +++ b/test/mppa/prng/Makefile @@ -2,46 +2,66 @@ K1CC ?= k1-mbr-gcc CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 +SIMU ?= k1-cluster +TIMEOUT ?= 10s -all: prng-test-gcc-x86 prng-test-gcc-k1c prng-test-ccomp-k1c +K1CCPATH=$(shell which $(K1CC)) +CCPATH=$(shell which $(CC)) +CCOMPPATH=$(shell which $(CCOMP)) +SIMUPATH=$(shell which $(SIMU)) -prng-test-gcc-x86: prng.c +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 +prng-test-gcc-k1c: prng.c $(K1CCPATH) $(K1CC) -D__UNIT_TEST_PRNG__ $(CFLAGS) $< -o $@ -prng-test-ccomp-k1c: prng.c +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: prng-test-gcc-x86 - @if ! ./$<; then\ - >&2 echo "ERROR: $< failed";\ - exit;\ +test-x86: $(X86_GCC_OUT) $(STUB_OUT) + @if ! diff $< $(STUB_OUT); then\ + >&2 echo "ERROR x86: $< failed";\ else\ - echo "$< Succeeded";\ + echo "GOOD x86: $< succeeded";\ fi .PHONY: -test-k1c: prng-test-gcc-k1c - @if ! k1-cluster -- ./$<; then\ - >&2 echo "ERROR: $< failed";\ - exit;\ +test-k1c: $(GCC_OUT) $(STUB_OUT) + @if ! diff $< $(STUB_OUT); then\ + >&2 echo "ERROR k1c: $< failed";\ else\ - echo "$< Succeeded";\ + echo "GOOD k1c: $< succeeded";\ fi .PHONY: -check: prng-test-ccomp-k1c - @if ! k1-cluster -- ./$<; then\ - >&2 echo "ERROR: $< failed";\ - exit;\ +check: $(CCOMP_OUT) $(STUB_OUT) + @if ! diff $< $(STUB_OUT); then\ + >&2 echo "ERROR k1c: $< failed";\ else\ - echo "$< Succeeded";\ + echo "GOOD k1c: $< succeeded";\ fi .PHONY: diff --git a/test/mppa/sort/Makefile b/test/mppa/sort/Makefile index c0c9347d..ebbad5b5 100644 --- a/test/mppa/sort/Makefile +++ b/test/mppa/sort/Makefile @@ -2,54 +2,78 @@ 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-test-gcc-x86 insertion-test-gcc-k1c\ - selection-test-gcc-x86 selection-test-gcc-k1c\ - merge-test-gcc-x86 merge-test-gcc-k1c\ - main-test-gcc-x86 main-test-gcc-k1c\ - main-test-ccomp-k1c +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-test-gcc-x86: $(CFILES) $(PRNG) - $(CC) $(CFLAGS) $^ -o $@ +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 $@ -%-test-gcc-x86: %.c $(PRNG) - $(CC) -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ $(CFLAGS) $^ -o $@ +main-gcc-k1c: $(CFILES) $(PRNG) $(CCPATH) + $(K1CC) $(CFLAGS) $(filter-out $(CCPATH),$^) -o $@ -main-test-gcc-k1c: $(CFILES) $(PRNG) - $(K1CC) $(CFLAGS) $^ -o $@ +%-gcc-k1c: %.c $(PRNG) $(K1CCPATH) + $(K1CC) -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ $(CFLAGS) $(filter-out $(K1CCPATH),$^) -o $@ -%-test-gcc-k1c: %.c $(PRNG) - $(K1CC) -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ $(CFLAGS) $^ -o $@ +main-ccomp-k1c: $(CFILES) $(PRNG) $(CCOMPPATH) + $(CCOMP) $(CFLAGS) $(filter-out $(CCOMPPATH),$^) -o $@ -main-test-ccomp-k1c: $(CFILES) $(PRNG) - $(CCOMP) $(CFLAGS) $^ -o $@ +%-ccomp-k1c: %.c $(PRNG) $(CCOMPPATH) + $(CCOMP) -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ $(CFLAGS) $(filter-out $(CCOMPPATH),$^) -o $@ -%-test-ccomp-k1c: %.c $(PRNG) - $(CCOMP) -D__UNIT_TEST_$$(echo $(basename $<) | tr a-z A-Z)__ $(CFLAGS) $^ -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: insertion-test-gcc-x86 selection-test-gcc-x86 merge-test-gcc-x86 main-test-gcc-x86 - @for test in $^; do\ - if ! ./$$test; then\ +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 "x86: Test $$test Succeeded";\ + echo "GOOD x86: $$test succeeded";\ fi;\ done .PHONY: -test-k1c: insertion-test-gcc-k1c selection-test-gcc-k1c merge-test-gcc-k1c main-test-gcc-k1c - @for test in $^; do\ - if ! k1-cluster -- ./$$test; then\ +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 "k1c: Test $$test Succeeded";\ + echo "GOOD k1c: $$test succeeded";\ fi;\ done @@ -57,13 +81,11 @@ test-k1c: insertion-test-gcc-k1c selection-test-gcc-k1c merge-test-gcc-k1c main- test: test-x86 test-k1c .PHONY: -check: main-test-ccomp-k1c - @if ! k1-cluster -- ./$<; then\ - >&2 echo "ERROR k1c: sort $< failed";\ - else\ - echo "k1c: Test sort $< succeeded";\ - fi - -.PHONY: -clean: - rm -f $(ALL) +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 -- cgit From bdaa3eb0ad6486186519ba1ba574e8ac92505cf0 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 21 Nov 2018 17:03:24 +0100 Subject: Mise à jour vis à vis de CompCert 3.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/mppa/instr/Makefile | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mppa/instr/Makefile b/test/mppa/instr/Makefile index 89ff9a73..34b5e9ec 100644 --- a/test/mppa/instr/Makefile +++ b/test/mppa/instr/Makefile @@ -3,7 +3,7 @@ CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 SIMU ?= k1-cluster -TIMEOUT ?= 10s +TIMEOUT ?= --signal=SIGTERM 20s DIR=./ SRCDIR=$(DIR) @@ -37,7 +37,7 @@ BIN=$(addprefix $(BINDIR)/,$(addsuffix .x86-gcc.bin,$(TESTNAMES)))\ all: $(BIN) -.PHONY: +.PHONY: test: $(X86_GCC_OUT) $(GCC_OUT) @echo "Comparing x86 gcc output to k1 gcc.." @for test in $(TESTNAMES); do\ @@ -70,6 +70,20 @@ check: $(GCC_OUT) $(CCOMP_OUT) .SECONDARY: # Generating output +## Version sans les timeout +#$(OUTDIR)/%.x86-gcc.out: $(BINDIR)/%.x86-gcc.bin +# @mkdir -p $(@D) +# ./$< > $@; echo $$? >> $@ +# +#$(OUTDIR)/%.gcc.out: $(BINDIR)/%.gcc.bin $(SIMUPATH) +# @mkdir -p $(@D) +# $(SIMU) -- $< > $@ ; echo $$? >> $@ +# +#$(OUTDIR)/%.ccomp.out: $(BINDIR)/%.ccomp.bin $(SIMUPATH) +# @mkdir -p $(@D) +# $(SIMU) -- $< > $@ ; echo $$? >> $@ + +## Version avec timeout $(OUTDIR)/%.x86-gcc.out: $(BINDIR)/%.x86-gcc.bin @mkdir -p $(@D) ret=0; timeout $(TIMEOUT) ./$< > $@ || { ret=$$?; }; echo $$ret >> $@ -- cgit From 0b9d1deb832dc93ce381f15f8e9774973f45e56e Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Fri, 23 Nov 2018 18:05:06 +0100 Subject: Fixed andd test not consistent with the rest --- test/mppa/instr/andd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/mppa/instr/andd.c b/test/mppa/instr/andd.c index 4f503764..5a2c7863 100644 --- a/test/mppa/instr/andd.c +++ b/test/mppa/instr/andd.c @@ -1,5 +1,5 @@ #include "framework.h" BEGIN_TEST(long long) - return a&b; + c = a&b; END_TEST() -- cgit From f17faa9e318cb6e6c75b3c22387f13e57a9828f7 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Fri, 23 Nov 2018 18:06:26 +0100 Subject: Interoperability tests passed (no va_arg yet) --- test/mppa/do_test.sh | 8 ++ test/mppa/interop/.gitignore | 1 + test/mppa/interop/Makefile | 166 +++++++++++++++++++++++++++++++++++++ test/mppa/interop/common.c | 62 ++++++++++++++ test/mppa/interop/common.h | 24 ++++++ test/mppa/interop/framework.h | 37 +++++++++ test/mppa/interop/i_manyiargs.c | 9 ++ test/mppa/interop/i_multiiargs.c | 6 ++ test/mppa/interop/i_oneiarg.c | 6 ++ test/mppa/interop/ll_manyllargs.c | 8 ++ test/mppa/interop/ll_multillargs.c | 7 ++ test/mppa/interop/ll_onellarg.c | 7 ++ test/mppa/interop/ll_void.c | 7 ++ test/mppa/interop/void_void.c | 7 ++ 14 files changed, 355 insertions(+) create mode 100644 test/mppa/interop/.gitignore create mode 100644 test/mppa/interop/Makefile create mode 100644 test/mppa/interop/common.c create mode 100644 test/mppa/interop/common.h create mode 100644 test/mppa/interop/framework.h create mode 100644 test/mppa/interop/i_manyiargs.c create mode 100644 test/mppa/interop/i_multiiargs.c create mode 100644 test/mppa/interop/i_oneiarg.c create mode 100644 test/mppa/interop/ll_manyllargs.c create mode 100644 test/mppa/interop/ll_multillargs.c create mode 100644 test/mppa/interop/ll_onellarg.c create mode 100644 test/mppa/interop/ll_void.c create mode 100644 test/mppa/interop/void_void.c (limited to 'test') diff --git a/test/mppa/do_test.sh b/test/mppa/do_test.sh index ee7cbcf7..add87b66 100644 --- a/test/mppa/do_test.sh +++ b/test/mppa/do_test.sh @@ -30,4 +30,12 @@ cat << EOF ## EOF (cd instr && make $1 -j8) + +cat << EOF + +## +# Interoperability with GCC +## +EOF +(cd interop && make $1 -j8) } diff --git a/test/mppa/interop/.gitignore b/test/mppa/interop/.gitignore new file mode 100644 index 00000000..ea1472ec --- /dev/null +++ b/test/mppa/interop/.gitignore @@ -0,0 +1 @@ +output/ diff --git a/test/mppa/interop/Makefile b/test/mppa/interop/Makefile new file mode 100644 index 00000000..18efaa24 --- /dev/null +++ b/test/mppa/interop/Makefile @@ -0,0 +1,166 @@ +K1CC ?= k1-mbr-gcc +CC ?= gcc +CCOMP ?= ccomp +CFLAGS ?= -O2 +SIMU ?= k1-cluster +TIMEOUT ?= --signal=SIGTERM 20s + +DIR=./ +SRCDIR=$(DIR) +OUTDIR=$(DIR)/out +BINDIR=$(DIR)/bin +ASMDIR=$(DIR)/asm +OBJDIR=$(DIR)/obj +COMMON=common + +## +# Intended flow : .c -> .gcc.s -> .gcc.o -> .gcc.bin -> .gcc.out +# -> .ccomp.s -> .ccomp.o -> .ccomp.bin -> .ccomp.out +# -> .x86-gcc.s -> .x86-gcc.o -> .x86-gcc.bin -> .x86-gcc.out +# +# The .o -> .bin part uses $(COMMON).gcc.o or $(COMMON).x86-gcc.o depending on the architecture +## + +K1CCPATH=$(shell which $(K1CC)) +CCPATH=$(shell which $(CC)) +CCOMPPATH=$(shell which $(CCOMP)) +SIMUPATH=$(shell which $(SIMU)) + +TESTNAMES=$(filter-out $(COMMON),$(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 +## + +## Version sans les timeout +#$(OUTDIR)/%.x86-gcc.out: $(BINDIR)/%.x86-gcc.bin +# @mkdir -p $(@D) +# ./$< > $@; echo $$? >> $@ +# +#$(OUTDIR)/%.gcc.out: $(BINDIR)/%.gcc.bin $(SIMUPATH) +# @mkdir -p $(@D) +# $(SIMU) -- $< > $@ ; echo $$? >> $@ +# +#$(OUTDIR)/%.ccomp.out: $(BINDIR)/%.ccomp.bin $(SIMUPATH) +# @mkdir -p $(@D) +# $(SIMU) -- $< > $@ ; echo $$? >> $@ + +## Version avec timeout +$(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 >> $@ + +## +# Object to binary +## + +$(BINDIR)/$(COMMON).x86-gcc.bin: $(OBJDIR)/$(COMMON).x86-gcc.o $(CCPATH) + @mkdir -p $(@D) + $(CC) $(CFLAGS) $< -o $@ + +$(BINDIR)/$(COMMON).gcc.bin: $(OBJDIR)/$(COMMON).gcc.o $(K1CCPATH) + @mkdir -p $(@D) + $(K1CC) $(CFLAGS) $< -o $@ + +$(BINDIR)/$(COMMON).ccomp.bin: $(OBJDIR)/$(COMMON).ccomp.o $(CCOMPPATH) + @mkdir -p $(@D) + $(CCOMP) $(CFLAGS) $< -o $@ + +$(BINDIR)/%.x86-gcc.bin: $(OBJDIR)/%.x86-gcc.o $(OBJDIR)/$(COMMON).x86-gcc.o $(CCPATH) + @mkdir -p $(@D) + $(CC) $(CFLAGS) $(wordlist 1,2,$^) -o $@ + +$(BINDIR)/%.gcc.bin: $(OBJDIR)/%.gcc.o $(OBJDIR)/$(COMMON).gcc.o $(K1CCPATH) + @mkdir -p $(@D) + $(K1CC) $(CFLAGS) $(wordlist 1,2,$^) -o $@ + +$(BINDIR)/%.ccomp.bin: $(OBJDIR)/%.ccomp.o $(OBJDIR)/$(COMMON).ccomp.o $(CCOMPPATH) + @mkdir -p $(@D) + $(CCOMP) $(CFLAGS) $(wordlist 1,2,$^) -o $@ + +## +# Assembly to object +## + +$(OBJDIR)/%.x86-gcc.o: $(ASMDIR)/%.x86-gcc.s $(CCPATH) + @mkdir -p $(@D) + $(CC) -c $(CFLAGS) $< -o $@ + +$(OBJDIR)/%.gcc.o: $(ASMDIR)/%.gcc.s $(K1CCPATH) + @mkdir -p $(@D) + $(K1CC) -c $(CFLAGS) $< -o $@ + +$(OBJDIR)/%.ccomp.o: $(ASMDIR)/%.ccomp.s $(CCOMPPATH) + @mkdir -p $(@D) + $(CCOMP) -c $(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/interop/common.c b/test/mppa/interop/common.c new file mode 100644 index 00000000..e3eea128 --- /dev/null +++ b/test/mppa/interop/common.c @@ -0,0 +1,62 @@ +#define STACK int a[100];\ + a[42] = 42; + +#define ONEARG_OP(arg) (3*arg+2) + +#define MULTIARG_OP(arg1, arg2, arg3, arg4) (arg1 ^ arg2 << arg3 - arg4) + +#define MANYARG_OP(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9,\ + a10, a11, a12, a13, a14, a15, a16, a17, a18, a19,\ + a20, a21, a22, a23, a24, a25, a26, a27, a28, a29)\ + (a0 + a1 * a2 + a3 * a4 + a5 + a6 + a7 - a8 + a9 +\ + a10 + a11 - a12 ^ a13 + a14 - a15 + a16 ^ a17 + a18 + a19 +\ + a20 + a21 + a22 * a23 + a24 + a25 << a26 & a27 + a28 + a29) + +void void_void(){ + STACK; +} + +long long ll_void(){ + STACK; + return 0xdeadbeefdeadbeefULL; +} + +int i_oneiarg(int arg){ + STACK; + return ONEARG_OP(arg); +} + +int i_multiiargs(int arg1, char arg2, char arg3, int arg4){ + STACK; + return MULTIARG_OP(arg1, arg2, arg3, arg4); +} + +int i_manyiargs(char a0, int a1, char a2, int a3, char a4, char a5, int a6, int a7, char a8, int a9, + char a10, int a11, char a12, int a13, char a14, char a15, int a16, int a17, char a18, int a19, + char a20, int a21, char a22, int a23, char a24, char a25, int a26, int a27, char a28, int a29) +{ + STACK; + return MANYARG_OP(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, + a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, + a20, a21, a22, a23, a24, a25, a26, a27, a28, a29); +} + +int ll_onellarg(long long arg){ + STACK; + return ONEARG_OP(arg); +} + +long long ll_multillargs(long long arg1, char arg2, char arg3, long long arg4){ + STACK; + return MULTIARG_OP(arg1, arg2, arg3, arg4); +} + +long long ll_manyllargs(char a0, long long a1, char a2, long long a3, char a4, char a5, long long a6, long long a7, char a8, long long a9, + char a10, long long a11, char a12, long long a13, char a14, char a15, long long a16, long long a17, char a18, long long a19, + char a20, long long a21, char a22, long long a23, char a24, char a25, long long a26, long long a27, char a28, long long a29) +{ + STACK; + return MANYARG_OP(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, + a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, + a20, a21, a22, a23, a24, a25, a26, a27, a28, a29); +} diff --git a/test/mppa/interop/common.h b/test/mppa/interop/common.h new file mode 100644 index 00000000..7b381671 --- /dev/null +++ b/test/mppa/interop/common.h @@ -0,0 +1,24 @@ +#ifndef __COMMON_H__ +#define __COMMON_H__ + +void void_void(void); + +long long ll_void(void); + +int i_oneiarg(int arg); + +int i_multiiargs(int arg1, char arg2, char arg3, int arg4); + +int i_manyiargs(char a0, int a1, char a2, int a3, char a4, char a5, int a6, int a7, char a8, int a9, + char a10, int a11, char a12, int a13, char a14, char a15, int a16, int a17, char a18, int a19, + char a20, int a21, char a22, int a23, char a24, char a25, int a26, int a27, char a28, int a29); + +int ll_onellarg(long long arg); + +long long ll_multillargs(long long arg1, char arg2, char arg3, long long arg4); + +long long ll_manyllargs(char a0, long long a1, char a2, long long a3, char a4, char a5, long long a6, long long a7, char a8, long long a9, + char a10, long long a11, char a12, long long a13, char a14, char a15, long long a16, long long a17, char a18, long long a19, + char a20, long long a21, char a22, long long a23, char a24, char a25, long long a26, long long a27, char a28, long long a29); + +#endif diff --git a/test/mppa/interop/framework.h b/test/mppa/interop/framework.h new file mode 100644 index 00000000..52ba97bc --- /dev/null +++ b/test/mppa/interop/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/interop/i_manyiargs.c b/test/mppa/interop/i_manyiargs.c new file mode 100644 index 00000000..d674c26f --- /dev/null +++ b/test/mppa/interop/i_manyiargs.c @@ -0,0 +1,9 @@ +#include "framework.h" +#include "common.h" + +BEGIN_TEST(int) + c = i_manyiargs(a, b, a-b, a+b, a*2, b*2, a*2-b, a+b*2, (a-b)*2, (a+b)*2, + -2*a, -2*b, a-b, a+b, a*3, b*3, a*3-b, a+b*3, (a-b)*3, (a+b)*3, + -3*a, -3*b, a-b, a+b, a*4, b*4, a*4-b, a+b*4, (a-b)*4, (a+b)*4); +END_TEST() + diff --git a/test/mppa/interop/i_multiiargs.c b/test/mppa/interop/i_multiiargs.c new file mode 100644 index 00000000..0e8c8936 --- /dev/null +++ b/test/mppa/interop/i_multiiargs.c @@ -0,0 +1,6 @@ +#include "framework.h" +#include "common.h" + +BEGIN_TEST(int) + c = i_multiiargs(a, b, a-b, a+b); +END_TEST() diff --git a/test/mppa/interop/i_oneiarg.c b/test/mppa/interop/i_oneiarg.c new file mode 100644 index 00000000..42cd1540 --- /dev/null +++ b/test/mppa/interop/i_oneiarg.c @@ -0,0 +1,6 @@ +#include "framework.h" +#include "common.h" + +BEGIN_TEST(int) + c = i_oneiarg(a); +END_TEST() diff --git a/test/mppa/interop/ll_manyllargs.c b/test/mppa/interop/ll_manyllargs.c new file mode 100644 index 00000000..6e0b3b36 --- /dev/null +++ b/test/mppa/interop/ll_manyllargs.c @@ -0,0 +1,8 @@ +#include "framework.h" +#include "common.h" + +BEGIN_TEST(long long) + c = ll_manyllargs(a, b, a-b, a+b, a*2, b*2, a*2-b, a+b*2, (a-b)*2, (a+b)*2, + -2*a, -2*b, a-b, a+b, a*3, b*3, a*3-b, a+b*3, (a-b)*3, (a+b)*3, + -3*a, -3*b, a-b, a+b, a*4, b*4, a*4-b, a+b*4, (a-b)*4, (a+b)*4); +END_TEST() diff --git a/test/mppa/interop/ll_multillargs.c b/test/mppa/interop/ll_multillargs.c new file mode 100644 index 00000000..edb03b12 --- /dev/null +++ b/test/mppa/interop/ll_multillargs.c @@ -0,0 +1,7 @@ +#include "framework.h" +#include "common.h" + +BEGIN_TEST(long long) + c = ll_multillargs(a, b, a-b, a+b); +END_TEST() + diff --git a/test/mppa/interop/ll_onellarg.c b/test/mppa/interop/ll_onellarg.c new file mode 100644 index 00000000..0d182166 --- /dev/null +++ b/test/mppa/interop/ll_onellarg.c @@ -0,0 +1,7 @@ +#include "framework.h" +#include "common.h" + +BEGIN_TEST(long long) + c = ll_onellarg(a); +END_TEST() + diff --git a/test/mppa/interop/ll_void.c b/test/mppa/interop/ll_void.c new file mode 100644 index 00000000..fa350c9b --- /dev/null +++ b/test/mppa/interop/ll_void.c @@ -0,0 +1,7 @@ +#include "framework.h" +#include "common.h" + +BEGIN_TEST(long long) + c = ll_void(); + c += a; +END_TEST() diff --git a/test/mppa/interop/void_void.c b/test/mppa/interop/void_void.c new file mode 100644 index 00000000..e729edb2 --- /dev/null +++ b/test/mppa/interop/void_void.c @@ -0,0 +1,7 @@ +#include "framework.h" +#include "common.h" + +BEGIN_TEST(long long) + void_void(); + c = a; +END_TEST() -- cgit From 309db6bc63539f2ba10c0cd4088ef3ac2e237551 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 27 Nov 2018 17:17:47 +0100 Subject: Added tests where GCC calls CompCert functions --- test/mppa/instr/Makefile | 2 +- test/mppa/interop/Makefile | 27 ++++++++++++++++++++++----- test/mppa/mmult/Makefile | 2 +- test/mppa/prng/Makefile | 2 +- test/mppa/sort/Makefile | 2 +- 5 files changed, 26 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/mppa/instr/Makefile b/test/mppa/instr/Makefile index 34b5e9ec..27449e88 100644 --- a/test/mppa/instr/Makefile +++ b/test/mppa/instr/Makefile @@ -2,7 +2,7 @@ K1CC ?= k1-mbr-gcc CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 -SIMU ?= k1-cluster +SIMU ?= k1-mppa TIMEOUT ?= --signal=SIGTERM 20s DIR=./ diff --git a/test/mppa/interop/Makefile b/test/mppa/interop/Makefile index 18efaa24..ed3bd23f 100644 --- a/test/mppa/interop/Makefile +++ b/test/mppa/interop/Makefile @@ -2,7 +2,7 @@ K1CC ?= k1-mbr-gcc CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 -SIMU ?= k1-cluster +SIMU ?= k1-mppa TIMEOUT ?= --signal=SIGTERM 20s DIR=./ @@ -29,12 +29,14 @@ SIMUPATH=$(shell which $(SIMU)) TESTNAMES=$(filter-out $(COMMON),$(notdir $(subst .c,,$(wildcard $(DIR)/*.c)))) X86_GCC_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .x86-gcc.out,$(TESTNAMES))) GCC_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .gcc.out,$(TESTNAMES))) +GCC_REV_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .gcc.rev.out,$(TESTNAMES))) CCOMP_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .ccomp.out,$(TESTNAMES))) -OUT=$(X86_GCC_OUT) $(GCC_OUT) $(CCOMP_OUT) +OUT=$(X86_GCC_OUT) $(GCC_OUT) $(CCOMP_OUT) $(GCC_REV_OUT) BIN=$(addprefix $(BINDIR)/,$(addsuffix .x86-gcc.bin,$(TESTNAMES)))\ $(addprefix $(BINDIR)/,$(addsuffix .gcc.bin,$(TESTNAMES)))\ - $(addprefix $(BINDIR)/,$(addsuffix .ccomp.bin,$(TESTNAMES))) + $(addprefix $(BINDIR)/,$(addsuffix .ccomp.bin,$(TESTNAMES)))\ + $(addprefix $(BINDIR)/,$(addsuffix .gcc.rev.bin,$(TESTNAMES))) ## # Targets @@ -56,16 +58,22 @@ test: $(X86_GCC_OUT) $(GCC_OUT) done .PHONY: -check: $(GCC_OUT) $(CCOMP_OUT) +check: $(GCC_OUT) $(CCOMP_OUT) $(GCC_REV_OUT) @echo "Comparing k1 gcc output to ccomp.." @for test in $(TESTNAMES); do\ gccout=$(OUTDIR)/$$test.gcc.out;\ ccompout=$(OUTDIR)/$$test.ccomp.out;\ + gccrevout=$(OUTDIR)/$$test.gcc.rev.out;\ if ! diff $$ccompout $$gccout; then\ >&2 echo "ERROR: $$ccompout and $$gccout differ";\ else\ echo "GOOD: $$ccompout and $$gccout concur";\ fi;\ + if ! diff $$gccrevout $$gccout; then\ + >&2 echo "ERROR: $$gccrevout and $$gccout differ";\ + else\ + echo "GOOD: $$gccrevout and $$gccout concur";\ + fi;\ done ## @@ -100,6 +108,10 @@ $(OUTDIR)/%.gcc.out: $(BINDIR)/%.gcc.bin $(SIMUPATH) @mkdir -p $(@D) ret=0; timeout $(TIMEOUT) $(SIMU) -- $< > $@ || { ret=$$?; }; echo $$ret >> $@ +$(OUTDIR)/%.gcc.rev.out: $(BINDIR)/%.gcc.rev.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 >> $@ @@ -128,10 +140,15 @@ $(BINDIR)/%.gcc.bin: $(OBJDIR)/%.gcc.o $(OBJDIR)/$(COMMON).gcc.o $(K1CCPATH) @mkdir -p $(@D) $(K1CC) $(CFLAGS) $(wordlist 1,2,$^) -o $@ -$(BINDIR)/%.ccomp.bin: $(OBJDIR)/%.ccomp.o $(OBJDIR)/$(COMMON).ccomp.o $(CCOMPPATH) +$(BINDIR)/%.gcc.rev.bin: $(OBJDIR)/%.gcc.o $(OBJDIR)/$(COMMON).ccomp.o $(K1CCPATH) + @mkdir -p $(@D) + $(K1CC) $(CFLAGS) $(wordlist 1,2,$^) -o $@ + +$(BINDIR)/%.ccomp.bin: $(OBJDIR)/%.ccomp.o $(OBJDIR)/$(COMMON).gcc.o $(CCOMPPATH) @mkdir -p $(@D) $(CCOMP) $(CFLAGS) $(wordlist 1,2,$^) -o $@ + ## # Assembly to object ## diff --git a/test/mppa/mmult/Makefile b/test/mppa/mmult/Makefile index cf82e359..5895ce3d 100644 --- a/test/mppa/mmult/Makefile +++ b/test/mppa/mmult/Makefile @@ -2,7 +2,7 @@ K1CC ?= k1-mbr-gcc CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 -SIMU ?= k1-cluster +SIMU ?= k1-mppa TIMEOUT ?= 10s K1CCPATH=$(shell which $(K1CC)) diff --git a/test/mppa/prng/Makefile b/test/mppa/prng/Makefile index 5580cd8e..4770c901 100644 --- a/test/mppa/prng/Makefile +++ b/test/mppa/prng/Makefile @@ -2,7 +2,7 @@ K1CC ?= k1-mbr-gcc CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 -SIMU ?= k1-cluster +SIMU ?= k1-mppa TIMEOUT ?= 10s K1CCPATH=$(shell which $(K1CC)) diff --git a/test/mppa/sort/Makefile b/test/mppa/sort/Makefile index ebbad5b5..5173528c 100644 --- a/test/mppa/sort/Makefile +++ b/test/mppa/sort/Makefile @@ -2,7 +2,7 @@ K1CC ?= k1-mbr-gcc CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 -SIMU ?= k1-cluster +SIMU ?= k1-mppa TIMEOUT ?= 10s K1CCPATH=$(shell which $(K1CC)) -- cgit From 5a26a29335042b2b7d841f04d74de3151ca8cc8d Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 28 Nov 2018 12:09:41 +0100 Subject: Added GCC-compcert call test with a very high register pressure --- test/mppa/do_test.sh | 10 +-- test/mppa/interop/Makefile | 2 +- test/mppa/interop/common.c | 197 +++++++++++++++++++++++++++++++++++++++++- test/mppa/interop/common.h | 4 + test/mppa/interop/stackhell.c | 8 ++ 5 files changed, 212 insertions(+), 9 deletions(-) create mode 100644 test/mppa/interop/stackhell.c (limited to 'test') diff --git a/test/mppa/do_test.sh b/test/mppa/do_test.sh index add87b66..41302116 100644 --- a/test/mppa/do_test.sh +++ b/test/mppa/do_test.sh @@ -5,7 +5,7 @@ cat << EOF # PRNG tests ## EOF -(cd prng && make $1 -j8) +(cd prng && make $1 -j4) cat << EOF @@ -13,7 +13,7 @@ cat << EOF # Matrix Multiplication tests ## EOF -(cd mmult && make $1 -j8) +(cd mmult && make $1 -j4) cat << EOF @@ -21,7 +21,7 @@ cat << EOF # List sort tests ## EOF -(cd sort && make $1 -j8) +(cd sort && make $1 -j4) cat << EOF @@ -29,7 +29,7 @@ cat << EOF # Instruction unit tests ## EOF -(cd instr && make $1 -j8) +(cd instr && make $1 -j4) cat << EOF @@ -37,5 +37,5 @@ cat << EOF # Interoperability with GCC ## EOF -(cd interop && make $1 -j8) +(cd interop && make $1 -j4) } diff --git a/test/mppa/interop/Makefile b/test/mppa/interop/Makefile index ed3bd23f..5800ce9d 100644 --- a/test/mppa/interop/Makefile +++ b/test/mppa/interop/Makefile @@ -3,7 +3,7 @@ CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 SIMU ?= k1-mppa -TIMEOUT ?= --signal=SIGTERM 20s +TIMEOUT ?= --signal=SIGTERM 40s DIR=./ SRCDIR=$(DIR) diff --git a/test/mppa/interop/common.c b/test/mppa/interop/common.c index e3eea128..2b5f5b5e 100644 --- a/test/mppa/interop/common.c +++ b/test/mppa/interop/common.c @@ -51,12 +51,203 @@ long long ll_multillargs(long long arg1, char arg2, char arg3, long long arg4){ return MULTIARG_OP(arg1, arg2, arg3, arg4); } -long long ll_manyllargs(char a0, long long a1, char a2, long long a3, char a4, char a5, long long a6, long long a7, char a8, long long a9, - char a10, long long a11, char a12, long long a13, char a14, char a15, long long a16, long long a17, char a18, long long a19, - char a20, long long a21, char a22, long long a23, char a24, char a25, long long a26, long long a27, char a28, long long a29) +long long ll_manyllargs(char a0, int a1, char a2, long long a3, char a4, char a5, long long a6, long long a7, char a8, long long a9, + char a10, long long a11, char a12, int a13, char a14, char a15, long long a16, long long a17, char a18, long long a19, + char a20, int a21, char a22, long long a23, char a24, char a25, long long a26, int a27, char a28, long long a29) { STACK; return MANYARG_OP(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29); } + +long long stackhell(char a0, int a1, char a2, long long a3, char a4, char a5, long long a6, long long a7, char a8, long long a9, + char a10, long long a11, char a12, int a13, char a14, char a15, long long a16, long long a17, char a18, long long a19, + char a20, int a21, char a22, long long a23, char a24, char a25, long long a26, int a27, char a28, long long a29) +{ + long long b0 = a0; + long long b1 = a1 + b0; + long long b2 = a2 + b1; + int b3 = a3 + b2; + int b4 = a4 + b3; + int b5 = a5 + b4; + int b6 = a6 + b5; + int b7 = a7 + b6; + char b8 = a8 + b7; + char b9 = a9 + b8; + char b10 = a10 + b9; + char b11 = a11 + b10; + char b12 = a12 + b11; + int b13 = a13 + b12; + long long b14 = a14 + b13; + long long b15 = a15 + b14; + long long b16 = a16 + b15; + long long b17 = a17 + b16; + long long b18 = a18 + b17; + long long b19 = a19 + b18; + long long b20 = a20 + b19; + long long b21 = a21 + b20; + long long b22 = a22 + b21; + long long b23 = a23 + b22; + long long b24 = a24 + b23; + long long b25 = a25 + b24; + long long b26 = a26 + b25; + long long b27 = a27 + b26; + int b28 = a28 + b27; + int b29 = a29 + b28; + int b30 = b0 + b29; + int b31 = b1 + b30; + int b32 = b2 + b31; + char b33 = b3 + b32; + char b34 = b4 + b33; + char b35 = b5 + b34; + char b36 = b6 + b35; + char b37 = b7 + b36; + int b38 = b8 + b37; + int b39 = b9 + b38; + int b40 = b0 + b39; + int b41 = b1 + b40; + int b42 = b2 + b41; + int b43 = b3 + b42; + int b44 = b4 + b43; + int b45 = b5 + b44; + int b46 = b6 + b45; + int b47 = b7 + b46; + int b48 = b8 + b47; + long long b49 = b9 + b48; + long long b50 = b0 + b49; + long long b51 = b1 + b50; + long long b52 = b2 + b51; + long long b53 = b3 + b52; + long long b54 = b4 + b53; + long long b55 = b5 + b54; + long long b56 = b6 + b55; + long long b57 = b7 + b56; + int b58 = b8 + b57; + int b59 = b9 + b58; + int b60 = b0 + b59; + int b61 = b1 + b60; + int b62 = b2 + b61; + int b63 = b3 + b62; + int b64 = b4 + b63; + int b65 = b5 + b64; + int b66 = b6 + b65; + int b67 = b7 + b66; + int b68 = b8 + b67; + int b69 = b9 + b68; + char b70 = b0 + b69; + char b71 = b1 + b70; + char b72 = b2 + b71; + char b73 = b3 + b72; + char b74 = b4 + b73; + char b75 = b5 + b74; + char b76 = b6 + b75; + char b77 = b7 + b76; + char b78 = b8 + b77; + char b79 = b9 + b78; + char b80 = b0 + b79; + char b81 = b1 + b80; + char b82 = b2 + b81; + char b83 = b3 + b82; + char b84 = b4 + b83; + int b85 = b5 + b84; + int b86 = b6 + b85; + int b87 = b7 + b86; + int b88 = b8 + b87; + int b89 = b9 + b88; + int b90 = b0 + b89; + int b91 = b1 + b90; + int b92 = b2 + b91; + int b93 = b3 + b92; + int b94 = b4 + b93; + long long b95 = b5 + b94; + long long b96 = b6 + b95; + long long b97 = b7 + b96; + long long b98 = b8 + b97; + long long b99 = b9 + b98; + long long b100 = b0 + b99; + long long b101 = b1 + b100; + long long b102 = b2 + b101; + long long b103 = b3 + b102; + long long b104 = b4 + b103; + long long b105 = b5 + b104; + long long b106 = b6 + b105; + long long b107 = b7 + b106; + long long b108 = b8 + b107; + long long b109 = b9 + b108; + long long b110 = b0 + b109; + long long b111 = b1 + b110; + long long b112 = b2 + b111; + long long b113 = b3 + b112; + long long b114 = b4 + b113; + int b115 = b5 + b114; + int b116 = b6 + b115; + int b117 = b7 + b116; + int b118 = b8 + b117; + int b119 = b9 + b118; + int b120 = b0 + b119; + int b121 = b1 + b120; + int b122 = b2 + b121; + int b123 = b3 + b122; + int b124 = b4 + b123; + int b125 = b5 + b124; + char b126 = b6 + b125; + char b127 = b7 + b126; + char b128 = b8 + b127; + char b129 = b9 + b128; + char b130 = b0 + b129; + char b131 = b1 + b130; + char b132 = b2 + b131; + char b133 = b3 + b132; + char b134 = b4 + b133; + char b135 = b5 + b134; + char b136 = b6 + b135; + char b137 = b7 + b136; + char b138 = b8 + b137; + char b139 = b9 + b138; + char b140 = b0 + b139; + char b141 = b1 + b140; + char b142 = b2 + b141; + char b143 = b3 + b142; + char b144 = b4 + b143; + char b145 = b5 + b144; + char b146 = b6 + b145; + char b147 = b7 + b146; + int b148 = b8 + b147; + int b149 = b9 + b148; + int b150 = b0 + b149; + int b151 = b1 + b150; + int b152 = b2 + b151; + int b153 = b3 + b152; + int b154 = b4 + b153; + int b155 = b5 + b154; + int b156 = b6 + b155; + int b157 = b7 + b156; + int b158 = b8 + b157; + int b159 = b9 + b158; + int b160 = b0 + b159; + int b161 = b1 + b160; + int b162 = b2 + b161; + return MANYARG_OP(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, + a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, + a20, a21, a22, a23, a24, a25, a26, a27, a28, a29) + + b0 + b1 + b2 + b3 + b4 + b5 + b6 + b7 + b8 + b9 + + b10 + b11 + b12 + b13 + b14 + b15 + b16 + b17 + b18 + b19 + + b20 + b21 + b22 + b23 + b24 + b25 + b26 + b27 + b28 + b29 + + b30 + b31 + b32 + b33 + b34 + b35 + b36 + b37 + b38 + b39 + + b40 + b41 + b42 + b43 + b44 + b45 + b46 + b47 + b48 + b49 + + b50 + b51 + b52 + b53 + b54 + b55 + b56 + b57 + b58 + b59 + + b60 + b61 + b62 + b63 + b64 + b65 + b66 + b67 + b68 + b69 + + b70 + b71 + b72 + b73 + b74 + b75 + b76 + b77 + b78 + b79 + + b80 + b81 + b82 + b83 + b84 + b85 + b86 + b87 + b88 + b89 + + b90 + b91 + b92 + b93 + b94 + b95 + b96 + b97 + b98 + b99 + + b100 + b101 + b102 + b103 + b104 + b105 + b106 + b107 + b108 + b109 + + b110 + b111 + b112 + b113 + b114 + b115 + b116 + b117 + b118 + b119 + + b120 + b121 + b122 + b123 + b124 + b125 + b126 + b127 + b128 + b129 + + b130 + b131 + b132 + b133 + b134 + b135 + b136 + b137 + b138 + b139 + + b140 + b141 + b142 + b143 + b144 + b145 + b146 + b147 + b148 + b149 + + b150 + b151 + b152 + b153 + b154 + b155 + b156 + b157 + b158 + b159 + + b160 + b161 + b162 + ; +} + diff --git a/test/mppa/interop/common.h b/test/mppa/interop/common.h index 7b381671..4e4a692a 100644 --- a/test/mppa/interop/common.h +++ b/test/mppa/interop/common.h @@ -21,4 +21,8 @@ long long ll_manyllargs(char a0, long long a1, char a2, long long a3, char a4, c char a10, long long a11, char a12, long long a13, char a14, char a15, long long a16, long long a17, char a18, long long a19, char a20, long long a21, char a22, long long a23, char a24, char a25, long long a26, long long a27, char a28, long long a29); +long long stackhell(char a0, long long a1, char a2, long long a3, char a4, char a5, long long a6, long long a7, char a8, long long a9, + char a10, long long a11, char a12, long long a13, char a14, char a15, long long a16, long long a17, char a18, long long a19, + char a20, long long a21, char a22, long long a23, char a24, char a25, long long a26, long long a27, char a28, long long a29); + #endif diff --git a/test/mppa/interop/stackhell.c b/test/mppa/interop/stackhell.c new file mode 100644 index 00000000..fbe7d56b --- /dev/null +++ b/test/mppa/interop/stackhell.c @@ -0,0 +1,8 @@ +#include "framework.h" +#include "common.h" + +BEGIN_TEST(long long) + c = stackhell(a, b, a-b, a+b, a*2, b*2, a*2-b, a+b*2, (a-b)*2, (a+b)*2, + -2*a, -2*b, a-b, a+b, a*3, b*3, a*3-b, a+b*3, (a-b)*3, (a+b)*3, + -3*a, -3*b, a-b, a+b, a*4, b*4, a*4-b, a+b*4, (a-b)*4, (a+b)*4); +END_TEST() -- cgit From 0ea925ecc01d3da88c1c2b8cb03b318af2720a92 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 28 Nov 2018 14:24:18 +0100 Subject: Added a jobs parameter to the test scripts --- test/mppa/check.sh | 2 +- test/mppa/delout.sh | 6 ++++++ test/mppa/do_test.sh | 10 +++++----- test/mppa/test.sh | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) create mode 100755 test/mppa/delout.sh (limited to 'test') diff --git a/test/mppa/check.sh b/test/mppa/check.sh index 8db50f1b..f25c3e31 100755 --- a/test/mppa/check.sh +++ b/test/mppa/check.sh @@ -3,4 +3,4 @@ source do_test.sh -do_test check +do_test check $1 diff --git a/test/mppa/delout.sh b/test/mppa/delout.sh new file mode 100755 index 00000000..e9c72e1c --- /dev/null +++ b/test/mppa/delout.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +for folder in prng mmult sort instr interop; do + rm -f $folder/*.out + rm -f $folder/out/* +done diff --git a/test/mppa/do_test.sh b/test/mppa/do_test.sh index 41302116..bb626203 100644 --- a/test/mppa/do_test.sh +++ b/test/mppa/do_test.sh @@ -5,7 +5,7 @@ cat << EOF # PRNG tests ## EOF -(cd prng && make $1 -j4) +(cd prng && make $1 -j$2) cat << EOF @@ -13,7 +13,7 @@ cat << EOF # Matrix Multiplication tests ## EOF -(cd mmult && make $1 -j4) +(cd mmult && make $1 -j$2) cat << EOF @@ -21,7 +21,7 @@ cat << EOF # List sort tests ## EOF -(cd sort && make $1 -j4) +(cd sort && make $1 -j$2) cat << EOF @@ -29,7 +29,7 @@ cat << EOF # Instruction unit tests ## EOF -(cd instr && make $1 -j4) +(cd instr && make $1 -j$2) cat << EOF @@ -37,5 +37,5 @@ cat << EOF # Interoperability with GCC ## EOF -(cd interop && make $1 -j4) +(cd interop && make $1 -j$2) } diff --git a/test/mppa/test.sh b/test/mppa/test.sh index dfeb153a..30806a6b 100755 --- a/test/mppa/test.sh +++ b/test/mppa/test.sh @@ -3,4 +3,4 @@ source do_test.sh -do_test test +do_test test $1 -- cgit From 30e8e1618e59bdb585b1fb36cddce41eefe12364 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 28 Nov 2018 17:31:46 +0100 Subject: Wrote some tests on va_arg, need to implement __compcert_va_int32 & cie --- test/mppa/interop/Makefile | 101 ++++++++++- test/mppa/interop/vaarg_common.c | 373 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 467 insertions(+), 7 deletions(-) create mode 100644 test/mppa/interop/vaarg_common.c (limited to 'test') diff --git a/test/mppa/interop/Makefile b/test/mppa/interop/Makefile index 5800ce9d..f4dc259e 100644 --- a/test/mppa/interop/Makefile +++ b/test/mppa/interop/Makefile @@ -1,7 +1,7 @@ K1CC ?= k1-mbr-gcc CC ?= gcc CCOMP ?= ccomp -CFLAGS ?= -O2 +CFLAGS ?= -O2 -Wno-varargs SIMU ?= k1-mppa TIMEOUT ?= --signal=SIGTERM 40s @@ -12,6 +12,7 @@ BINDIR=$(DIR)/bin ASMDIR=$(DIR)/asm OBJDIR=$(DIR)/obj COMMON=common +VAARG_COMMON=vaarg_common ## # Intended flow : .c -> .gcc.s -> .gcc.o -> .gcc.bin -> .gcc.out @@ -19,6 +20,7 @@ COMMON=common # -> .x86-gcc.s -> .x86-gcc.o -> .x86-gcc.bin -> .x86-gcc.out # # The .o -> .bin part uses $(COMMON).gcc.o or $(COMMON).x86-gcc.o depending on the architecture +# There is also a $(VAARG_COMMON) that is the same than $(COMMON) but with va_arg ## K1CCPATH=$(shell which $(K1CC)) @@ -26,17 +28,28 @@ CCPATH=$(shell which $(CC)) CCOMPPATH=$(shell which $(CCOMP)) SIMUPATH=$(shell which $(SIMU)) -TESTNAMES=$(filter-out $(COMMON),$(notdir $(subst .c,,$(wildcard $(DIR)/*.c)))) +TESTNAMES=$(filter-out $(VAARG_COMMON),$(filter-out $(COMMON),$(notdir $(subst .c,,$(wildcard $(DIR)/*.c))))) + X86_GCC_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .x86-gcc.out,$(TESTNAMES))) GCC_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .gcc.out,$(TESTNAMES))) GCC_REV_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .gcc.rev.out,$(TESTNAMES))) CCOMP_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .ccomp.out,$(TESTNAMES))) -OUT=$(X86_GCC_OUT) $(GCC_OUT) $(CCOMP_OUT) $(GCC_REV_OUT) +VAARG_X86_GCC_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .x86-gcc.vaarg.out,$(TESTNAMES))) +VAARG_GCC_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .gcc.vaarg.out,$(TESTNAMES))) +VAARG_GCC_REV_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .gcc.rev.vaarg.out,$(TESTNAMES))) +VAARG_CCOMP_OUT=$(addprefix $(OUTDIR)/,$(addsuffix .ccomp.vaarg.out,$(TESTNAMES))) + +OUT=$(X86_GCC_OUT) $(GCC_OUT) $(CCOMP_OUT) $(GCC_REV_OUT)\ + $(VAARG_GCC_OUT) $(VAARG_GCC_OUT) $(VAARG_CCOMP_OUT) $(VAARG_GCC_REV_OUT) BIN=$(addprefix $(BINDIR)/,$(addsuffix .x86-gcc.bin,$(TESTNAMES)))\ $(addprefix $(BINDIR)/,$(addsuffix .gcc.bin,$(TESTNAMES)))\ $(addprefix $(BINDIR)/,$(addsuffix .ccomp.bin,$(TESTNAMES)))\ - $(addprefix $(BINDIR)/,$(addsuffix .gcc.rev.bin,$(TESTNAMES))) + $(addprefix $(BINDIR)/,$(addsuffix .gcc.rev.bin,$(TESTNAMES)))\ + $(addprefix $(BINDIR)/,$(addsuffix .x86-gcc.vaarg.bin,$(TESTNAMES)))\ + $(addprefix $(BINDIR)/,$(addsuffix .gcc.vaarg.bin,$(TESTNAMES)))\ + $(addprefix $(BINDIR)/,$(addsuffix .ccomp.vaarg.bin,$(TESTNAMES)))\ + $(addprefix $(BINDIR)/,$(addsuffix .gcc.rev.vaarg.bin,$(TESTNAMES))) ## # Targets @@ -45,25 +58,35 @@ BIN=$(addprefix $(BINDIR)/,$(addsuffix .x86-gcc.bin,$(TESTNAMES)))\ all: $(BIN) .PHONY: -test: $(X86_GCC_OUT) $(GCC_OUT) +test: $(X86_GCC_OUT) $(GCC_OUT) $(VAARG_X86_GCC_OUT) $(VAARG_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;\ + vaarg_x86out=$(OUTDIR)/$$test.x86-gcc.vaarg.out;\ + vaarg_gccout=$(OUTDIR)/$$test.gcc.vaarg.out;\ if ! diff $$x86out $$gccout; then\ >&2 echo "ERROR: $$x86out and $$gccout differ";\ else\ echo "GOOD: $$x86out and $$gccout concur";\ fi;\ + if ! diff $$vaarg_x86out $$vaarg_gccout; then\ + >&2 echo "ERROR: $$vaarg_x86out and $$vaarg_gccout differ";\ + else\ + echo "GOOD: $$vaarg_x86out and $$vaarg_gccout concur";\ + fi;\ done .PHONY: -check: $(GCC_OUT) $(CCOMP_OUT) $(GCC_REV_OUT) +check: $(GCC_OUT) $(CCOMP_OUT) $(GCC_REV_OUT) $(VAARG_GCC_OUT) $(VAARG_CCOMP_OUT) $(VAARG_GCC_REV_OUT) @echo "Comparing k1 gcc output to ccomp.." @for test in $(TESTNAMES); do\ gccout=$(OUTDIR)/$$test.gcc.out;\ ccompout=$(OUTDIR)/$$test.ccomp.out;\ gccrevout=$(OUTDIR)/$$test.gcc.rev.out;\ + vaarg_gccout=$(OUTDIR)/$$test.gcc.vaarg.out;\ + vaarg_ccompout=$(OUTDIR)/$$test.ccomp.vaarg.out;\ + vaarg_gccrevout=$(OUTDIR)/$$test.gcc.rev.vaarg.out;\ if ! diff $$ccompout $$gccout; then\ >&2 echo "ERROR: $$ccompout and $$gccout differ";\ else\ @@ -74,6 +97,16 @@ check: $(GCC_OUT) $(CCOMP_OUT) $(GCC_REV_OUT) else\ echo "GOOD: $$gccrevout and $$gccout concur";\ fi;\ + if ! diff $$vaarg_ccompout $$vaarg_gccout; then\ + >&2 echo "ERROR: $$vaarg_ccompout and $$vaarg_gccout differ";\ + else\ + echo "GOOD: $$vaarg_ccompout and $$vaarg_gccout concur";\ + fi;\ + if ! diff $$vaarg_gccrevout $$vaarg_gccout; then\ + >&2 echo "ERROR: $$vaarg_gccrevout and $$vaarg_gccout differ";\ + else\ + echo "GOOD: $$vaarg_gccrevout and $$vaarg_gccout concur";\ + fi;\ done ## @@ -99,7 +132,8 @@ check: $(GCC_OUT) $(CCOMP_OUT) $(GCC_REV_OUT) # @mkdir -p $(@D) # $(SIMU) -- $< > $@ ; echo $$? >> $@ -## Version avec timeout +## No vaarg + $(OUTDIR)/%.x86-gcc.out: $(BINDIR)/%.x86-gcc.bin @mkdir -p $(@D) ret=0; timeout $(TIMEOUT) ./$< > $@ || { ret=$$?; }; echo $$ret >> $@ @@ -116,10 +150,30 @@ $(OUTDIR)/%.ccomp.out: $(BINDIR)/%.ccomp.bin $(SIMUPATH) @mkdir -p $(@D) ret=0; timeout $(TIMEOUT) $(SIMU) -- $< > $@ || { ret=$$?; }; echo $$ret >> $@ +## With vaarg + +$(OUTDIR)/%.x86-gcc.vaarg.out: $(BINDIR)/%.x86-gcc.vaarg.bin + @mkdir -p $(@D) + ret=0; timeout $(TIMEOUT) ./$< > $@ || { ret=$$?; }; echo $$ret >> $@ + +$(OUTDIR)/%.gcc.vaarg.out: $(BINDIR)/%.gcc.vaarg.bin $(SIMUPATH) + @mkdir -p $(@D) + ret=0; timeout $(TIMEOUT) $(SIMU) -- $< > $@ || { ret=$$?; }; echo $$ret >> $@ + +$(OUTDIR)/%.gcc.rev.vaarg.out: $(BINDIR)/%.gcc.rev.vaarg.bin $(SIMUPATH) + @mkdir -p $(@D) + ret=0; timeout $(TIMEOUT) $(SIMU) -- $< > $@ || { ret=$$?; }; echo $$ret >> $@ + +$(OUTDIR)/%.ccomp.vaarg.out: $(BINDIR)/%.ccomp.vaarg.bin $(SIMUPATH) + @mkdir -p $(@D) + ret=0; timeout $(TIMEOUT) $(SIMU) -- $< > $@ || { ret=$$?; }; echo $$ret >> $@ + ## # Object to binary ## +## common + $(BINDIR)/$(COMMON).x86-gcc.bin: $(OBJDIR)/$(COMMON).x86-gcc.o $(CCPATH) @mkdir -p $(@D) $(CC) $(CFLAGS) $< -o $@ @@ -132,6 +186,22 @@ $(BINDIR)/$(COMMON).ccomp.bin: $(OBJDIR)/$(COMMON).ccomp.o $(CCOMPPATH) @mkdir -p $(@D) $(CCOMP) $(CFLAGS) $< -o $@ +## vaarg_common + +$(BINDIR)/$(VAARG_COMMON).x86-gcc.bin: $(OBJDIR)/$(VAARG_COMMON).x86-gcc.o $(CCPATH) + @mkdir -p $(@D) + $(CC) $(CFLAGS) $< -o $@ + +$(BINDIR)/$(VAARG_COMMON).gcc.bin: $(OBJDIR)/$(VAARG_COMMON).gcc.o $(K1CCPATH) + @mkdir -p $(@D) + $(K1CC) $(CFLAGS) $< -o $@ + +$(BINDIR)/$(VAARG_COMMON).ccomp.bin: $(OBJDIR)/$(VAARG_COMMON).ccomp.o $(CCOMPPATH) + @mkdir -p $(@D) + $(CCOMP) $(CFLAGS) $< -o $@ + +## no vaarg + $(BINDIR)/%.x86-gcc.bin: $(OBJDIR)/%.x86-gcc.o $(OBJDIR)/$(COMMON).x86-gcc.o $(CCPATH) @mkdir -p $(@D) $(CC) $(CFLAGS) $(wordlist 1,2,$^) -o $@ @@ -148,6 +218,23 @@ $(BINDIR)/%.ccomp.bin: $(OBJDIR)/%.ccomp.o $(OBJDIR)/$(COMMON).gcc.o $(CCOMPPATH @mkdir -p $(@D) $(CCOMP) $(CFLAGS) $(wordlist 1,2,$^) -o $@ +## with vaarg + +$(BINDIR)/%.x86-gcc.vaarg.bin: $(OBJDIR)/%.x86-gcc.o $(OBJDIR)/$(VAARG_COMMON).x86-gcc.o $(CCPATH) + @mkdir -p $(@D) + $(CC) $(CFLAGS) $(wordlist 1,2,$^) -o $@ + +$(BINDIR)/%.gcc.vaarg.bin: $(OBJDIR)/%.gcc.o $(OBJDIR)/$(VAARG_COMMON).gcc.o $(K1CCPATH) + @mkdir -p $(@D) + $(K1CC) $(CFLAGS) $(wordlist 1,2,$^) -o $@ + +$(BINDIR)/%.gcc.rev.vaarg.bin: $(OBJDIR)/%.gcc.o $(OBJDIR)/$(VAARG_COMMON).ccomp.o $(K1CCPATH) + @mkdir -p $(@D) + $(K1CC) $(CFLAGS) $(wordlist 1,2,$^) -o $@ + +$(BINDIR)/%.ccomp.vaarg.bin: $(OBJDIR)/%.ccomp.o $(OBJDIR)/$(VAARG_COMMON).gcc.o $(CCOMPPATH) + @mkdir -p $(@D) + $(CCOMP) $(CFLAGS) $(wordlist 1,2,$^) -o $@ ## # Assembly to object diff --git a/test/mppa/interop/vaarg_common.c b/test/mppa/interop/vaarg_common.c new file mode 100644 index 00000000..a04b67bf --- /dev/null +++ b/test/mppa/interop/vaarg_common.c @@ -0,0 +1,373 @@ +#include + +#define STACK int a[100];\ + a[42] = 42; + +#define ONEARG_OP(arg) (3*arg+2) + +#define MULTIARG_OP(arg1, arg2, arg3, arg4) (arg1 ^ arg2 << arg3 - arg4) + +#define MANYARG_OP(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9,\ + a10, a11, a12, a13, a14, a15, a16, a17, a18, a19,\ + a20, a21, a22, a23, a24, a25, a26, a27, a28, a29)\ + (a0 + a1 * a2 + a3 * a4 + a5 + a6 + a7 - a8 + a9 +\ + a10 + a11 - a12 ^ a13 + a14 - a15 + a16 ^ a17 + a18 + a19 +\ + a20 + a21 + a22 * a23 + a24 + a25 << a26 & a27 + a28 + a29) + +#define VA_START(vl, n) va_list vl; va_start(vl, n) +#define VA_END(vl) va_end(vl) + +void void_void(void){ + STACK; +} + +long long ll_void(void){ + STACK; + return 0xdeadbeefdeadbeefULL; +} + +// int i_oneiarg(int arg){ +int i_oneiarg(int arg, ...){ + STACK; + VA_START(vl, 0); + VA_END(vl); + return ONEARG_OP(arg); +} + +//int i_multiiargs(int arg1, char arg2, char arg3, int arg4){ +int i_multiiargs(int arg1, ...){ + STACK; + VA_START(vl, 3); + char arg2 = va_arg(vl, int); + char arg3 = va_arg(vl, int); + int arg4 = va_arg(vl, int); + VA_END(vl); + return MULTIARG_OP(arg1, arg2, arg3, arg4); +} + +//int i_manyiargs(char a0, int a1, char a2, int a3, char a4, char a5, int a6, int a7, char a8, int a9, +// char a10, int a11, char a12, int a13, char a14, char a15, int a16, int a17, char a18, int a19, +// char a20, int a21, char a22, int a23, char a24, char a25, int a26, int a27, char a28, int a29) +int i_manyiargs(char a0, ...) +{ + STACK; + VA_START(vl, 29); + int a1 = va_arg(vl, int); + char a2 = va_arg(vl, int); + int a3 = va_arg(vl, int); + char a4 = va_arg(vl, int); + char a5 = va_arg(vl, int); + int a6 = va_arg(vl, int); + int a7 = va_arg(vl, int); + char a8 = va_arg(vl, int); + int a9 = va_arg(vl, int); + char a10 = va_arg(vl, int); + int a11 = va_arg(vl, int); + char a12 = va_arg(vl, int); + int a13 = va_arg(vl, int); + char a14 = va_arg(vl, int); + char a15 = va_arg(vl, int); + int a16 = va_arg(vl, int); + int a17 = va_arg(vl, int); + char a18 = va_arg(vl, int); + int a19 = va_arg(vl, int); + char a20 = va_arg(vl, int); + int a21 = va_arg(vl, int); + char a22 = va_arg(vl, int); + int a23 = va_arg(vl, int); + char a24 = va_arg(vl, int); + char a25 = va_arg(vl, int); + int a26 = va_arg(vl, int); + int a27 = va_arg(vl, int); + char a28 = va_arg(vl, int); + int a29 = va_arg(vl, int); + VA_END(vl); + return MANYARG_OP(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, + a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, + a20, a21, a22, a23, a24, a25, a26, a27, a28, a29); +} + +//int ll_onellarg(long long arg){ +int ll_onellarg(long long arg, ...){ + STACK; + VA_START(vl, 0); + VA_END(vl); + return ONEARG_OP(arg); +} + +//long long ll_multillargs(long long arg1, char arg2, char arg3, long long arg4){ +long long ll_multillargs(long long arg1, ...){ + STACK; + VA_START(vl, 3); + char arg2 = va_arg(vl, int); + char arg3 = va_arg(vl, int); + long long arg4 = va_arg(vl, long long); + VA_END(vl); + return MULTIARG_OP(arg1, arg2, arg3, arg4); +} + +//long long ll_manyllargs(char a0, int a1, char a2, long long a3, char a4, char a5, long long a6, long long a7, char a8, long long a9, +// char a10, long long a11, char a12, int a13, char a14, char a15, long long a16, long long a17, char a18, long long a19, +// char a20, int a21, char a22, long long a23, char a24, char a25, long long a26, int a27, char a28, long long a29) +long long ll_manyllargs(char a0, ...) +{ + STACK; + VA_START(vl, 29); + int a1 = va_arg(vl, int); + char a2 = va_arg(vl, int); + long long a3 = va_arg(vl, long long); + char a4 = va_arg(vl, int); + char a5 = va_arg(vl, int); + long long a6 = va_arg(vl, long long); + long long a7 = va_arg(vl, long long); + char a8 = va_arg(vl, int); + long long a9 = va_arg(vl, long long); + char a10 = va_arg(vl, int); + long long a11 = va_arg(vl, long long); + char a12 = va_arg(vl, int); + int a13 = va_arg(vl, int); + char a14 = va_arg(vl, int); + char a15 = va_arg(vl, int); + long long a16 = va_arg(vl, long long); + long long a17 = va_arg(vl, long long); + char a18 = va_arg(vl, int); + long long a19 = va_arg(vl, long long); + char a20 = va_arg(vl, int); + int a21 = va_arg(vl, int); + char a22 = va_arg(vl, int); + long long a23 = va_arg(vl, long long); + char a24 = va_arg(vl, int); + char a25 = va_arg(vl, int); + long long a26 = va_arg(vl, long long); + int a27 = va_arg(vl, int); + char a28 = va_arg(vl, int); + long long a29 = va_arg(vl, long long); + VA_END(vl); + return MANYARG_OP(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, + a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, + a20, a21, a22, a23, a24, a25, a26, a27, a28, a29); +} + +//long long stackhell(char a0, int a1, char a2, long long a3, char a4, char a5, long long a6, long long a7, char a8, long long a9, +// char a10, long long a11, char a12, int a13, char a14, char a15, long long a16, long long a17, char a18, long long a19, +// char a20, int a21, char a22, long long a23, char a24, char a25, long long a26, int a27, char a28, long long a29) +long long stackhell(char a0, ...) +{ + VA_START(vl, 29); + int a1 = va_arg(vl, int); + char a2 = va_arg(vl, int); + long long a3 = va_arg(vl, long long); + char a4 = va_arg(vl, int); + char a5 = va_arg(vl, int); + long long a6 = va_arg(vl, long long); + long long a7 = va_arg(vl, long long); + char a8 = va_arg(vl, int); + long long a9 = va_arg(vl, long long); + char a10 = va_arg(vl, int); + long long a11 = va_arg(vl, long long); + char a12 = va_arg(vl, int); + int a13 = va_arg(vl, int); + char a14 = va_arg(vl, int); + char a15 = va_arg(vl, int); + long long a16 = va_arg(vl, long long); + long long a17 = va_arg(vl, long long); + char a18 = va_arg(vl, int); + long long a19 = va_arg(vl, long long); + char a20 = va_arg(vl, int); + int a21 = va_arg(vl, int); + char a22 = va_arg(vl, int); + long long a23 = va_arg(vl, long long); + char a24 = va_arg(vl, int); + char a25 = va_arg(vl, int); + long long a26 = va_arg(vl, long long); + int a27 = va_arg(vl, int); + char a28 = va_arg(vl, int); + long long a29 = va_arg(vl, long long); + VA_END(vl); + + long long b0 = a0; + long long b1 = a1 + b0; + long long b2 = a2 + b1; + int b3 = a3 + b2; + int b4 = a4 + b3; + int b5 = a5 + b4; + int b6 = a6 + b5; + int b7 = a7 + b6; + char b8 = a8 + b7; + char b9 = a9 + b8; + char b10 = a10 + b9; + char b11 = a11 + b10; + char b12 = a12 + b11; + int b13 = a13 + b12; + long long b14 = a14 + b13; + long long b15 = a15 + b14; + long long b16 = a16 + b15; + long long b17 = a17 + b16; + long long b18 = a18 + b17; + long long b19 = a19 + b18; + long long b20 = a20 + b19; + long long b21 = a21 + b20; + long long b22 = a22 + b21; + long long b23 = a23 + b22; + long long b24 = a24 + b23; + long long b25 = a25 + b24; + long long b26 = a26 + b25; + long long b27 = a27 + b26; + int b28 = a28 + b27; + int b29 = a29 + b28; + int b30 = b0 + b29; + int b31 = b1 + b30; + int b32 = b2 + b31; + char b33 = b3 + b32; + char b34 = b4 + b33; + char b35 = b5 + b34; + char b36 = b6 + b35; + char b37 = b7 + b36; + int b38 = b8 + b37; + int b39 = b9 + b38; + int b40 = b0 + b39; + int b41 = b1 + b40; + int b42 = b2 + b41; + int b43 = b3 + b42; + int b44 = b4 + b43; + int b45 = b5 + b44; + int b46 = b6 + b45; + int b47 = b7 + b46; + int b48 = b8 + b47; + long long b49 = b9 + b48; + long long b50 = b0 + b49; + long long b51 = b1 + b50; + long long b52 = b2 + b51; + long long b53 = b3 + b52; + long long b54 = b4 + b53; + long long b55 = b5 + b54; + long long b56 = b6 + b55; + long long b57 = b7 + b56; + int b58 = b8 + b57; + int b59 = b9 + b58; + int b60 = b0 + b59; + int b61 = b1 + b60; + int b62 = b2 + b61; + int b63 = b3 + b62; + int b64 = b4 + b63; + int b65 = b5 + b64; + int b66 = b6 + b65; + int b67 = b7 + b66; + int b68 = b8 + b67; + int b69 = b9 + b68; + char b70 = b0 + b69; + char b71 = b1 + b70; + char b72 = b2 + b71; + char b73 = b3 + b72; + char b74 = b4 + b73; + char b75 = b5 + b74; + char b76 = b6 + b75; + char b77 = b7 + b76; + char b78 = b8 + b77; + char b79 = b9 + b78; + char b80 = b0 + b79; + char b81 = b1 + b80; + char b82 = b2 + b81; + char b83 = b3 + b82; + char b84 = b4 + b83; + int b85 = b5 + b84; + int b86 = b6 + b85; + int b87 = b7 + b86; + int b88 = b8 + b87; + int b89 = b9 + b88; + int b90 = b0 + b89; + int b91 = b1 + b90; + int b92 = b2 + b91; + int b93 = b3 + b92; + int b94 = b4 + b93; + long long b95 = b5 + b94; + long long b96 = b6 + b95; + long long b97 = b7 + b96; + long long b98 = b8 + b97; + long long b99 = b9 + b98; + long long b100 = b0 + b99; + long long b101 = b1 + b100; + long long b102 = b2 + b101; + long long b103 = b3 + b102; + long long b104 = b4 + b103; + long long b105 = b5 + b104; + long long b106 = b6 + b105; + long long b107 = b7 + b106; + long long b108 = b8 + b107; + long long b109 = b9 + b108; + long long b110 = b0 + b109; + long long b111 = b1 + b110; + long long b112 = b2 + b111; + long long b113 = b3 + b112; + long long b114 = b4 + b113; + int b115 = b5 + b114; + int b116 = b6 + b115; + int b117 = b7 + b116; + int b118 = b8 + b117; + int b119 = b9 + b118; + int b120 = b0 + b119; + int b121 = b1 + b120; + int b122 = b2 + b121; + int b123 = b3 + b122; + int b124 = b4 + b123; + int b125 = b5 + b124; + char b126 = b6 + b125; + char b127 = b7 + b126; + char b128 = b8 + b127; + char b129 = b9 + b128; + char b130 = b0 + b129; + char b131 = b1 + b130; + char b132 = b2 + b131; + char b133 = b3 + b132; + char b134 = b4 + b133; + char b135 = b5 + b134; + char b136 = b6 + b135; + char b137 = b7 + b136; + char b138 = b8 + b137; + char b139 = b9 + b138; + char b140 = b0 + b139; + char b141 = b1 + b140; + char b142 = b2 + b141; + char b143 = b3 + b142; + char b144 = b4 + b143; + char b145 = b5 + b144; + char b146 = b6 + b145; + char b147 = b7 + b146; + int b148 = b8 + b147; + int b149 = b9 + b148; + int b150 = b0 + b149; + int b151 = b1 + b150; + int b152 = b2 + b151; + int b153 = b3 + b152; + int b154 = b4 + b153; + int b155 = b5 + b154; + int b156 = b6 + b155; + int b157 = b7 + b156; + int b158 = b8 + b157; + int b159 = b9 + b158; + int b160 = b0 + b159; + int b161 = b1 + b160; + int b162 = b2 + b161; + return MANYARG_OP(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, + a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, + a20, a21, a22, a23, a24, a25, a26, a27, a28, a29) + + b0 + b1 + b2 + b3 + b4 + b5 + b6 + b7 + b8 + b9 + + b10 + b11 + b12 + b13 + b14 + b15 + b16 + b17 + b18 + b19 + + b20 + b21 + b22 + b23 + b24 + b25 + b26 + b27 + b28 + b29 + + b30 + b31 + b32 + b33 + b34 + b35 + b36 + b37 + b38 + b39 + + b40 + b41 + b42 + b43 + b44 + b45 + b46 + b47 + b48 + b49 + + b50 + b51 + b52 + b53 + b54 + b55 + b56 + b57 + b58 + b59 + + b60 + b61 + b62 + b63 + b64 + b65 + b66 + b67 + b68 + b69 + + b70 + b71 + b72 + b73 + b74 + b75 + b76 + b77 + b78 + b79 + + b80 + b81 + b82 + b83 + b84 + b85 + b86 + b87 + b88 + b89 + + b90 + b91 + b92 + b93 + b94 + b95 + b96 + b97 + b98 + b99 + + b100 + b101 + b102 + b103 + b104 + b105 + b106 + b107 + b108 + b109 + + b110 + b111 + b112 + b113 + b114 + b115 + b116 + b117 + b118 + b119 + + b120 + b121 + b122 + b123 + b124 + b125 + b126 + b127 + b128 + b129 + + b130 + b131 + b132 + b133 + b134 + b135 + b136 + b137 + b138 + b139 + + b140 + b141 + b142 + b143 + b144 + b145 + b146 + b147 + b148 + b149 + + b150 + b151 + b152 + b153 + b154 + b155 + b156 + b157 + b158 + b159 + + b160 + b161 + b162 + ; +} + -- cgit From 79a2dac7e5317e515ce9610db1d48d0fc9ff0708 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Fri, 30 Nov 2018 17:31:11 +0100 Subject: Finished implementation of va_arg + testing done --- test/mppa/instr/Makefile | 2 +- test/mppa/interop/Makefile | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/mppa/instr/Makefile b/test/mppa/instr/Makefile index 27449e88..9d1fbb5f 100644 --- a/test/mppa/instr/Makefile +++ b/test/mppa/instr/Makefile @@ -3,7 +3,7 @@ CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 SIMU ?= k1-mppa -TIMEOUT ?= --signal=SIGTERM 20s +TIMEOUT ?= --signal=SIGTERM 60s DIR=./ SRCDIR=$(DIR) diff --git a/test/mppa/interop/Makefile b/test/mppa/interop/Makefile index f4dc259e..78271a4e 100644 --- a/test/mppa/interop/Makefile +++ b/test/mppa/interop/Makefile @@ -3,7 +3,7 @@ CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 -Wno-varargs SIMU ?= k1-mppa -TIMEOUT ?= --signal=SIGTERM 40s +TIMEOUT ?= --signal=SIGTERM 80s DIR=./ SRCDIR=$(DIR) @@ -212,7 +212,7 @@ $(BINDIR)/%.gcc.bin: $(OBJDIR)/%.gcc.o $(OBJDIR)/$(COMMON).gcc.o $(K1CCPATH) $(BINDIR)/%.gcc.rev.bin: $(OBJDIR)/%.gcc.o $(OBJDIR)/$(COMMON).ccomp.o $(K1CCPATH) @mkdir -p $(@D) - $(K1CC) $(CFLAGS) $(wordlist 1,2,$^) -o $@ + $(CCOMP) $(CFLAGS) $(wordlist 1,2,$^) -o $@ $(BINDIR)/%.ccomp.bin: $(OBJDIR)/%.ccomp.o $(OBJDIR)/$(COMMON).gcc.o $(CCOMPPATH) @mkdir -p $(@D) @@ -230,7 +230,7 @@ $(BINDIR)/%.gcc.vaarg.bin: $(OBJDIR)/%.gcc.o $(OBJDIR)/$(VAARG_COMMON).gcc.o $(K $(BINDIR)/%.gcc.rev.vaarg.bin: $(OBJDIR)/%.gcc.o $(OBJDIR)/$(VAARG_COMMON).ccomp.o $(K1CCPATH) @mkdir -p $(@D) - $(K1CC) $(CFLAGS) $(wordlist 1,2,$^) -o $@ + $(CCOMP) $(CFLAGS) $(wordlist 1,2,$^) -o $@ $(BINDIR)/%.ccomp.vaarg.bin: $(OBJDIR)/%.ccomp.o $(OBJDIR)/$(VAARG_COMMON).gcc.o $(CCOMPPATH) @mkdir -p $(@D) -- cgit From e925d4d2ed91ddd08337b6bb9ecb5064803e1981 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Fri, 7 Dec 2018 14:45:57 +0100 Subject: Added a printf wrapper in test/mppa/lib --- test/mppa/do_test.sh | 9 +++ test/mppa/lib/Makefile | 133 ++++++++++++++++++++++++++++++++++++++++++++ test/mppa/lib/printf-test.c | 9 +++ test/mppa/lib/printf.c | 9 +++ 4 files changed, 160 insertions(+) create mode 100644 test/mppa/lib/Makefile create mode 100644 test/mppa/lib/printf-test.c create mode 100644 test/mppa/lib/printf.c (limited to 'test') diff --git a/test/mppa/do_test.sh b/test/mppa/do_test.sh index bb626203..5cc23dee 100644 --- a/test/mppa/do_test.sh +++ b/test/mppa/do_test.sh @@ -38,4 +38,13 @@ cat << EOF ## EOF (cd interop && make $1 -j$2) + +cat << EOF + +## +# printf wrapper test +## +(cd lib && make $1 -j$2) +EOF + } diff --git a/test/mppa/lib/Makefile b/test/mppa/lib/Makefile new file mode 100644 index 00000000..affc1afd --- /dev/null +++ b/test/mppa/lib/Makefile @@ -0,0 +1,133 @@ +K1CC ?= k1-mbr-gcc +K1AR ?= k1-mbr-ar +CC ?= gcc +AR ?= gcc-ar +CCOMP ?= ccomp +CFLAGS ?= -O1 -Wl,--wrap=printf +SIMU ?= k1-mppa +TIMEOUT ?= --signal=SIGTERM 60s + +DIR=./ +SRCDIR=$(DIR) +OUTDIR=$(DIR)/out +BINDIR=$(DIR)/bin +ASMDIR=$(DIR)/asm +OBJDIR=$(DIR)/obj + +K1CCPATH=$(shell which $(K1CC)) +K1ARPATH=$(shell which $(K1AR)) +CCPATH=$(shell which $(CC)) +ARPATH=$(shell which $(AR)) +SIMUPATH=$(shell which $(SIMU)) + +TESTNAMES=printf-test +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) system.x86-gcc.a system.gcc.a + +.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 + +## Version avec timeout +$(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 >> $@ + +# Object to binary + +$(BINDIR)/%.x86-gcc.bin: $(OBJDIR)/%.x86-gcc.o system.x86-gcc.a $(CCPATH) + @mkdir -p $(@D) + $(CC) $(CFLAGS) $(filter-out $(CCPATH),$^) -o $@ + +$(BINDIR)/%.gcc.bin: $(OBJDIR)/%.gcc.o system.gcc.a $(K1CCPATH) + @mkdir -p $(@D) + $(K1CC) $(CFLAGS) $(filter-out $(K1CCPATH),$^) -o $@ + +$(BINDIR)/%.ccomp.bin: $(OBJDIR)/%.ccomp.o system.gcc.a $(CCOMPPATH) + @mkdir -p $(@D) + $(CCOMP) $(CFLAGS) $(filter-out $(CCOMPPATH),$^) -o $@ + +# Generating libraries +system.x86-gcc.a: $(OBJDIR)/printf.x86-gcc.o $(ARPATH) + $(AR) rcs $@ $< + +system.gcc.a: $(OBJDIR)/printf.gcc.o $(K1ARPATH) + $(K1AR) rcs $@ $< + +# Assembly to object + +$(OBJDIR)/%.x86-gcc.o: $(ASMDIR)/%.x86-gcc.s $(CCPATH) + @mkdir -p $(@D) + $(CC) $(CFLAGS) -c $< -o $@ + +$(OBJDIR)/%.gcc.o: $(ASMDIR)/%.gcc.s $(K1CCPATH) + @mkdir -p $(@D) + $(K1CC) $(CFLAGS) -c $< -o $@ + +$(OBJDIR)/%.ccomp.o: $(ASMDIR)/%.ccomp.s $(CCOMPPATH) + $(CCOMP) $(CFLAGS) -c $< -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/lib/printf-test.c b/test/mppa/lib/printf-test.c new file mode 100644 index 00000000..25afd436 --- /dev/null +++ b/test/mppa/lib/printf-test.c @@ -0,0 +1,9 @@ +int printf(const char *, ...); + +int main(void){ + int a = 42; + char *str = "Hi there"; + printf("%s, I am %u\n", str, a); + + return 0; +} diff --git a/test/mppa/lib/printf.c b/test/mppa/lib/printf.c new file mode 100644 index 00000000..79984ef6 --- /dev/null +++ b/test/mppa/lib/printf.c @@ -0,0 +1,9 @@ +#include +#include + +int __wrap_printf(const char *format, ...){ + va_list args; + va_start(args, format); + vprintf(format, args); + va_end(args); +} -- cgit From a045315a8d1da5c4f726512b0dd972897afe9971 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Fri, 7 Dec 2018 16:43:08 +0100 Subject: Added printf to the unitary tests for instructions --- test/mppa/instr/Makefile | 53 ++++++++++++++++++++++----------------------- test/mppa/instr/framework.h | 3 +++ 2 files changed, 29 insertions(+), 27 deletions(-) (limited to 'test') diff --git a/test/mppa/instr/Makefile b/test/mppa/instr/Makefile index 9d1fbb5f..336f3dcb 100644 --- a/test/mppa/instr/Makefile +++ b/test/mppa/instr/Makefile @@ -1,15 +1,17 @@ K1CC ?= k1-mbr-gcc CC ?= gcc CCOMP ?= ccomp -CFLAGS ?= -O2 +CFLAGS ?= -O2 -Wl,--wrap=printf SIMU ?= k1-mppa -TIMEOUT ?= --signal=SIGTERM 60s +TIMEOUT ?= --signal=SIGTERM 120s DIR=./ SRCDIR=$(DIR) OUTDIR=$(DIR)/out BINDIR=$(DIR)/bin ASMDIR=$(DIR)/asm +LIB=../lib/system.x86-gcc.a +K1LIB=../lib/system.gcc.a ## # Intended flow : .c -> .gcc.s -> .gcc.bin -> .gcc.out @@ -37,16 +39,20 @@ BIN=$(addprefix $(BINDIR)/,$(addsuffix .x86-gcc.bin,$(TESTNAMES)))\ all: $(BIN) +GREEN=\033[0;32m +RED=\033[0;31m +NC=\033[0m + .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";\ + if diff -q $$x86out $$gccout > /dev/null; test $${PIPESTATUS[0]} -ne 0; then\ + >&2 printf "$(RED)ERROR: $$x86out and $$gccout differ$(NC)\n";\ else\ - echo "GOOD: $$x86out and $$gccout concur";\ + printf "$(GREEN)GOOD: $$x86out and $$gccout concur$(NC)\n";\ fi;\ done @@ -56,10 +62,10 @@ check: $(GCC_OUT) $(CCOMP_OUT) @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";\ + if diff -q $$ccompout $$gccout > /dev/null; test $${PIPESTATUS[0]} -ne 0; then\ + >&2 printf "$(RED)ERROR: $$ccompout and $$gccout differ$(NC)\n";\ else\ - echo "GOOD: $$ccompout and $$gccout concur";\ + printf "$(GREEN)GOOD: $$ccompout and $$gccout concur$(NC)\n";\ fi;\ done @@ -68,20 +74,13 @@ check: $(GCC_OUT) $(CCOMP_OUT) ## .SECONDARY: -# Generating output +$(LIB): + (cd $(dir $(LIB)) && make) -## Version sans les timeout -#$(OUTDIR)/%.x86-gcc.out: $(BINDIR)/%.x86-gcc.bin -# @mkdir -p $(@D) -# ./$< > $@; echo $$? >> $@ -# -#$(OUTDIR)/%.gcc.out: $(BINDIR)/%.gcc.bin $(SIMUPATH) -# @mkdir -p $(@D) -# $(SIMU) -- $< > $@ ; echo $$? >> $@ -# -#$(OUTDIR)/%.ccomp.out: $(BINDIR)/%.ccomp.bin $(SIMUPATH) -# @mkdir -p $(@D) -# $(SIMU) -- $< > $@ ; echo $$? >> $@ +$(K1LIB): + (cd $(dir $(LIB)) && make) + +# Generating output ## Version avec timeout $(OUTDIR)/%.x86-gcc.out: $(BINDIR)/%.x86-gcc.bin @@ -98,17 +97,17 @@ $(OUTDIR)/%.ccomp.out: $(BINDIR)/%.ccomp.bin $(SIMUPATH) # Assembly to binary -$(BINDIR)/%.x86-gcc.bin: $(ASMDIR)/%.x86-gcc.s $(CCPATH) +$(BINDIR)/%.x86-gcc.bin: $(ASMDIR)/%.x86-gcc.s $(LIB) $(CCPATH) @mkdir -p $(@D) - $(CC) $(CFLAGS) $< -o $@ + $(CC) $(CFLAGS) $(filter-out $(CCPATH),$^) -o $@ -$(BINDIR)/%.gcc.bin: $(ASMDIR)/%.gcc.s $(K1CCPATH) +$(BINDIR)/%.gcc.bin: $(ASMDIR)/%.gcc.s $(K1LIB) $(K1CCPATH) @mkdir -p $(@D) - $(K1CC) $(CFLAGS) $< -o $@ + $(K1CC) $(CFLAGS) $(filter-out $(K1CCPATH),$^) -o $@ -$(BINDIR)/%.ccomp.bin: $(ASMDIR)/%.ccomp.s $(CCOMPPATH) +$(BINDIR)/%.ccomp.bin: $(ASMDIR)/%.ccomp.s $(K1LIB) $(CCOMPPATH) @mkdir -p $(@D) - $(CCOMP) $(CFLAGS) $< -o $@ + $(CCOMP) $(CFLAGS) $(filter-out $(CCOMPPATH),$^) -o $@ # Source to assembly diff --git a/test/mppa/instr/framework.h b/test/mppa/instr/framework.h index 52ba97bc..f43ec616 100644 --- a/test/mppa/instr/framework.h +++ b/test/mppa/instr/framework.h @@ -3,6 +3,8 @@ #include "../prng/prng.c" +int printf(const char *, ...); + #define BEGIN_TEST_N(type, N)\ int main(void){\ type t[N], c, i, j, S;\ @@ -28,6 +30,7 @@ /* In between BEGIN_TEST and END_TEST : definition of c */ #define END_TEST()\ + printf("%llu\n", c);\ S += c;\ }\ return S;\ -- cgit From 51a27f176b0eb5fb2943807a5cb95f2024420936 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 11 Dec 2018 14:26:46 +0100 Subject: Fixed div64 and mod64 --- test/mppa/instr/Makefile | 5 +++-- test/mppa/interop/Makefile | 40 ++++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 20 deletions(-) (limited to 'test') diff --git a/test/mppa/instr/Makefile b/test/mppa/instr/Makefile index 336f3dcb..66e40365 100644 --- a/test/mppa/instr/Makefile +++ b/test/mppa/instr/Makefile @@ -1,7 +1,8 @@ K1CC ?= k1-mbr-gcc CC ?= gcc CCOMP ?= ccomp -CFLAGS ?= -O2 -Wl,--wrap=printf +OPTIM ?= -O2 +CFLAGS ?= $(OPTIM) -Wl,--wrap=printf SIMU ?= k1-mppa TIMEOUT ?= --signal=SIGTERM 120s @@ -23,7 +24,7 @@ CCPATH=$(shell which $(CC)) CCOMPPATH=$(shell which $(CCOMP)) SIMUPATH=$(shell which $(SIMU)) -TESTNAMES=$(notdir $(subst .c,,$(wildcard $(DIR)/*.c))) +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))) diff --git a/test/mppa/interop/Makefile b/test/mppa/interop/Makefile index 78271a4e..e8c88ed8 100644 --- a/test/mppa/interop/Makefile +++ b/test/mppa/interop/Makefile @@ -57,6 +57,10 @@ BIN=$(addprefix $(BINDIR)/,$(addsuffix .x86-gcc.bin,$(TESTNAMES)))\ all: $(BIN) +GREEN=\033[0;32m +RED=\033[0;31m +NC=\033[0m + .PHONY: test: $(X86_GCC_OUT) $(GCC_OUT) $(VAARG_X86_GCC_OUT) $(VAARG_GCC_OUT) @echo "Comparing x86 gcc output to k1 gcc.." @@ -65,15 +69,15 @@ test: $(X86_GCC_OUT) $(GCC_OUT) $(VAARG_X86_GCC_OUT) $(VAARG_GCC_OUT) gccout=$(OUTDIR)/$$test.gcc.out;\ vaarg_x86out=$(OUTDIR)/$$test.x86-gcc.vaarg.out;\ vaarg_gccout=$(OUTDIR)/$$test.gcc.vaarg.out;\ - if ! diff $$x86out $$gccout; then\ - >&2 echo "ERROR: $$x86out and $$gccout differ";\ + if ! diff $$x86out $$gccout > /dev/null; then\ + >&2 printf "$(RED)ERROR: $$x86out and $$gccout differ$(NC)\n";\ else\ - echo "GOOD: $$x86out and $$gccout concur";\ + printf "$(GREEN)GOOD: $$x86out and $$gccout concur$(NC)\n";\ fi;\ - if ! diff $$vaarg_x86out $$vaarg_gccout; then\ - >&2 echo "ERROR: $$vaarg_x86out and $$vaarg_gccout differ";\ + if ! diff $$vaarg_x86out $$vaarg_gccout > /dev/null; then\ + >&2 printf "$(RED)ERROR: $$vaarg_x86out and $$vaarg_gccout differ$(NC)\n";\ else\ - echo "GOOD: $$vaarg_x86out and $$vaarg_gccout concur";\ + printf "$(GREEN)GOOD: $$vaarg_x86out and $$vaarg_gccout concur$(NC)\n";\ fi;\ done @@ -87,25 +91,25 @@ check: $(GCC_OUT) $(CCOMP_OUT) $(GCC_REV_OUT) $(VAARG_GCC_OUT) $(VAARG_CCOMP_OUT vaarg_gccout=$(OUTDIR)/$$test.gcc.vaarg.out;\ vaarg_ccompout=$(OUTDIR)/$$test.ccomp.vaarg.out;\ vaarg_gccrevout=$(OUTDIR)/$$test.gcc.rev.vaarg.out;\ - if ! diff $$ccompout $$gccout; then\ - >&2 echo "ERROR: $$ccompout and $$gccout differ";\ + if ! diff $$ccompout $$gccout > /dev/null; then\ + >&2 printf "$(RED)ERROR: $$ccompout and $$gccout differ$(NC)\n";\ else\ - echo "GOOD: $$ccompout and $$gccout concur";\ + printf "$(GREEN)GOOD: $$ccompout and $$gccout concur$(NC)\n";\ fi;\ - if ! diff $$gccrevout $$gccout; then\ - >&2 echo "ERROR: $$gccrevout and $$gccout differ";\ + if ! diff $$gccrevout $$gccout > /dev/null; then\ + >&2 printf "$(RED)ERROR: $$gccrevout and $$gccout differ$(NC)\n";\ else\ - echo "GOOD: $$gccrevout and $$gccout concur";\ + printf "$(GREEN)GOOD: $$gccrevout and $$gccout concur$(NC)\n";\ fi;\ - if ! diff $$vaarg_ccompout $$vaarg_gccout; then\ - >&2 echo "ERROR: $$vaarg_ccompout and $$vaarg_gccout differ";\ + if ! diff $$vaarg_ccompout $$vaarg_gccout > /dev/null; then\ + >&2 printf "$(RED)ERROR: $$vaarg_ccompout and $$vaarg_gccout differ$(NC)\n";\ else\ - echo "GOOD: $$vaarg_ccompout and $$vaarg_gccout concur";\ + printf "$(GREEN)GOOD: $$vaarg_ccompout and $$vaarg_gccout concur$(NC)\n";\ fi;\ - if ! diff $$vaarg_gccrevout $$vaarg_gccout; then\ - >&2 echo "ERROR: $$vaarg_gccrevout and $$vaarg_gccout differ";\ + if ! diff $$vaarg_gccrevout $$vaarg_gccout > /dev/null; then\ + >&2 printf "$(RED)ERROR: $$vaarg_gccrevout and $$vaarg_gccout differ$(NC)\n";\ else\ - echo "GOOD: $$vaarg_gccrevout and $$vaarg_gccout concur";\ + printf "$(GREEN)GOOD: $$vaarg_gccrevout and $$vaarg_gccout concur$(NC)\n";\ fi;\ done -- cgit From 16c895f9cbef271e6f7711a83de06f02d4eeeb02 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 11 Dec 2018 17:27:02 +0100 Subject: In va_arg tests, 2nd argument of va_start is now correct --- test/mppa/interop/Makefile | 2 +- test/mppa/interop/vaarg_common.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/mppa/interop/Makefile b/test/mppa/interop/Makefile index e8c88ed8..5818cbcb 100644 --- a/test/mppa/interop/Makefile +++ b/test/mppa/interop/Makefile @@ -3,7 +3,7 @@ CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 -Wno-varargs SIMU ?= k1-mppa -TIMEOUT ?= --signal=SIGTERM 80s +TIMEOUT ?= --signal=SIGTERM 120s DIR=./ SRCDIR=$(DIR) diff --git a/test/mppa/interop/vaarg_common.c b/test/mppa/interop/vaarg_common.c index a04b67bf..e213a20b 100644 --- a/test/mppa/interop/vaarg_common.c +++ b/test/mppa/interop/vaarg_common.c @@ -14,7 +14,7 @@ a10 + a11 - a12 ^ a13 + a14 - a15 + a16 ^ a17 + a18 + a19 +\ a20 + a21 + a22 * a23 + a24 + a25 << a26 & a27 + a28 + a29) -#define VA_START(vl, n) va_list vl; va_start(vl, n) +#define VA_START(vl, arg) va_list vl; va_start(vl, arg) #define VA_END(vl) va_end(vl) void void_void(void){ @@ -29,7 +29,7 @@ long long ll_void(void){ // int i_oneiarg(int arg){ int i_oneiarg(int arg, ...){ STACK; - VA_START(vl, 0); + VA_START(vl, arg); VA_END(vl); return ONEARG_OP(arg); } @@ -37,7 +37,7 @@ int i_oneiarg(int arg, ...){ //int i_multiiargs(int arg1, char arg2, char arg3, int arg4){ int i_multiiargs(int arg1, ...){ STACK; - VA_START(vl, 3); + VA_START(vl, arg1); char arg2 = va_arg(vl, int); char arg3 = va_arg(vl, int); int arg4 = va_arg(vl, int); @@ -51,7 +51,7 @@ int i_multiiargs(int arg1, ...){ int i_manyiargs(char a0, ...) { STACK; - VA_START(vl, 29); + VA_START(vl, a0); int a1 = va_arg(vl, int); char a2 = va_arg(vl, int); int a3 = va_arg(vl, int); @@ -90,7 +90,7 @@ int i_manyiargs(char a0, ...) //int ll_onellarg(long long arg){ int ll_onellarg(long long arg, ...){ STACK; - VA_START(vl, 0); + VA_START(vl, arg); VA_END(vl); return ONEARG_OP(arg); } @@ -98,7 +98,7 @@ int ll_onellarg(long long arg, ...){ //long long ll_multillargs(long long arg1, char arg2, char arg3, long long arg4){ long long ll_multillargs(long long arg1, ...){ STACK; - VA_START(vl, 3); + VA_START(vl, arg1); char arg2 = va_arg(vl, int); char arg3 = va_arg(vl, int); long long arg4 = va_arg(vl, long long); @@ -112,7 +112,7 @@ long long ll_multillargs(long long arg1, ...){ long long ll_manyllargs(char a0, ...) { STACK; - VA_START(vl, 29); + VA_START(vl, a0); int a1 = va_arg(vl, int); char a2 = va_arg(vl, int); long long a3 = va_arg(vl, long long); @@ -153,7 +153,7 @@ long long ll_manyllargs(char a0, ...) // char a20, int a21, char a22, long long a23, char a24, char a25, long long a26, int a27, char a28, long long a29) long long stackhell(char a0, ...) { - VA_START(vl, 29); + VA_START(vl, a0); int a1 = va_arg(vl, int); char a2 = va_arg(vl, int); long long a3 = va_arg(vl, long long); -- cgit From fe3fc2fd3d5a312ac526c5596e851e315782d9f6 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 11 Dec 2018 17:38:57 +0100 Subject: Added the use of two va_list in a va_arg test --- test/mppa/interop/vaarg_common.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/mppa/interop/vaarg_common.c b/test/mppa/interop/vaarg_common.c index e213a20b..9033893b 100644 --- a/test/mppa/interop/vaarg_common.c +++ b/test/mppa/interop/vaarg_common.c @@ -52,18 +52,22 @@ int i_manyiargs(char a0, ...) { STACK; VA_START(vl, a0); + VA_START(vl2, a0); int a1 = va_arg(vl, int); char a2 = va_arg(vl, int); int a3 = va_arg(vl, int); char a4 = va_arg(vl, int); char a5 = va_arg(vl, int); + char b1 = va_arg(vl2, int); int a6 = va_arg(vl, int); int a7 = va_arg(vl, int); char a8 = va_arg(vl, int); + char b2 = va_arg(vl2, int); int a9 = va_arg(vl, int); char a10 = va_arg(vl, int); int a11 = va_arg(vl, int); char a12 = va_arg(vl, int); + char b3 = va_arg(vl2, int); int a13 = va_arg(vl, int); char a14 = va_arg(vl, int); char a15 = va_arg(vl, int); @@ -78,13 +82,15 @@ int i_manyiargs(char a0, ...) char a24 = va_arg(vl, int); char a25 = va_arg(vl, int); int a26 = va_arg(vl, int); + char b4 = va_arg(vl2, int); int a27 = va_arg(vl, int); char a28 = va_arg(vl, int); int a29 = va_arg(vl, int); VA_END(vl); - return MANYARG_OP(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, - a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, - a20, a21, a22, a23, a24, a25, a26, a27, a28, a29); + VA_END(vl); + return MANYARG_OP(a0, a1, a2, a3, a4, (a5*b2), a6, a7, a8, a9, + (a10*b3), a11, a12, a13, a14, a15, a16, a17, a18, a19, + a20, (a21*b1), a22, a23, (a24*b3), a25, a26, a27, a28, a29); } //int ll_onellarg(long long arg){ -- cgit From 576dac0317ae5e9930fb2cdfbaa36efce28d17e2 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Thu, 17 Jan 2019 14:39:59 +0100 Subject: Fixed the forvar test --- test/mppa/instr/forvar.c | 6 +++--- test/mppa/instr/framework.h | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/mppa/instr/forvar.c b/test/mppa/instr/forvar.c index 57548274..9e43c198 100644 --- a/test/mppa/instr/forvar.c +++ b/test/mppa/instr/forvar.c @@ -2,8 +2,8 @@ BEGIN_TEST(int) { - int j; - for (j = 0 ; j < (b & 0x8) ; j++) + int k; + for (k = 0 ; k < (b & 0x8) ; k++) c += a; } -END_TEST() +END_TEST32() diff --git a/test/mppa/instr/framework.h b/test/mppa/instr/framework.h index f43ec616..d1c652bd 100644 --- a/test/mppa/instr/framework.h +++ b/test/mppa/instr/framework.h @@ -37,4 +37,14 @@ int printf(const char *, ...); } /* END END_TEST */ +#define END_TEST32()\ + printf("%u\n", c);\ + S += c;\ + }\ + return S;\ + } + /* END END_TEST32 */ + #endif + + -- cgit From d366e22b0c8665ab73d162cf8db98b91b2e4314e Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Thu, 17 Jan 2019 19:46:11 +0100 Subject: test (does not compile yet) --- test/monniaux/Makefile | 23 +++++++++++++ test/monniaux/int_mat.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 test/monniaux/Makefile create mode 100644 test/monniaux/int_mat.c (limited to 'test') diff --git a/test/monniaux/Makefile b/test/monniaux/Makefile new file mode 100644 index 00000000..26fd90d7 --- /dev/null +++ b/test/monniaux/Makefile @@ -0,0 +1,23 @@ +CFLAGS=-Wall -O3 +K1C_CC=k1-mbr-gcc +K1C_CFLAGS=-Wall -O3 -std=c99 +K1C_CCOMP=../../ccomp +K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int + +EXECUTABLES=int_mat.host int_mat.k1c int_mat.k1c_ccomp + +all: $(EXECUTABLES) + +int_mat.host: int_mat.c + $(CC) $(CFLAGS) $+ -o $@ + +int_mat.k1c: int_mat.c + $(K1C_CC) $(K1C_CFLAGS) $+ -o $@ + +int_mat.k1c_ccomp: int_mat.c + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) $+ -o $@ + +clean: + $(RM) -f $(EXECUTABLES) + +.PHONY: clean diff --git a/test/monniaux/int_mat.c b/test/monniaux/int_mat.c new file mode 100644 index 00000000..a1615e70 --- /dev/null +++ b/test/monniaux/int_mat.c @@ -0,0 +1,92 @@ +#include +#include +#include +#include + +typedef uint32_t modint; + +#define MODULUS 257 + +void modint_mat_mul1(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b) { + for(unsigned i=0; i Date: Thu, 17 Jan 2019 20:20:25 +0100 Subject: for testing postpass --- test/monniaux/Makefile | 24 +++++++++++++++--------- test/monniaux/int_mat.c | 27 +-------------------------- test/monniaux/int_mat_run.c | 22 ++++++++++++++++++++++ test/monniaux/modint.h | 26 ++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 test/monniaux/int_mat_run.c create mode 100644 test/monniaux/modint.h (limited to 'test') diff --git a/test/monniaux/Makefile b/test/monniaux/Makefile index 26fd90d7..91644c2f 100644 --- a/test/monniaux/Makefile +++ b/test/monniaux/Makefile @@ -4,20 +4,26 @@ K1C_CFLAGS=-Wall -O3 -std=c99 K1C_CCOMP=../../ccomp K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int -EXECUTABLES=int_mat.host int_mat.k1c int_mat.k1c_ccomp +PRODUCTS=int_mat.host int_mat.k1c int_mat.k1c_ccomp int_mat.k1c_ccomp.s -all: $(EXECUTABLES) +all: $(PRODUCTS) -int_mat.host: int_mat.c - $(CC) $(CFLAGS) $+ -o $@ +int_mat.host: int_mat.c int_mat_run.c modint.h + $(CC) $(CFLAGS) int_mat.c int_mat_run.c -o $@ -int_mat.k1c: int_mat.c - $(K1C_CC) $(K1C_CFLAGS) $+ -o $@ +int_mat.k1c: int_mat.c int_mat_run.k1c.o modint.h + $(K1C_CC) $(K1C_CFLAGS) int_mat.c int_mat_run.k1c.o -o $@ -int_mat.k1c_ccomp: int_mat.c - $(K1C_CCOMP) $(K1C_CCOMPFLAGS) $+ -o $@ +int_mat_run.k1c.o: int_mat_run.c modint.h + $(K1C_CC) $(K1C_CFLAGS) -c int_mat_run.c -o $@ + +int_mat.k1c_ccomp.s: int_mat.c modint.h + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -S int_mat.c -o $@ + +int_mat.k1c_ccomp: int_mat.k1c_ccomp.s int_mat_run.k1c.o modint.h + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) int_mat.k1c_ccomp.s int_mat_run.k1c.o -o $@ clean: - $(RM) -f $(EXECUTABLES) + $(RM) -f $(PRODUCTS) .PHONY: clean diff --git a/test/monniaux/int_mat.c b/test/monniaux/int_mat.c index a1615e70..936f45d6 100644 --- a/test/monniaux/int_mat.c +++ b/test/monniaux/int_mat.c @@ -1,11 +1,4 @@ -#include -#include -#include -#include - -typedef uint32_t modint; - -#define MODULUS 257 +#include "modint.h" void modint_mat_mul1(unsigned m, unsigned n, unsigned p, modint * restrict c, unsigned stride_c, @@ -72,21 +65,3 @@ bool modint_mat_equal(unsigned m, } return true; } - -int main() { - const unsigned m = 200, n = 100, p = 150; - modint *a = malloc(sizeof(modint) * m * n); - modint_mat_random(m, n, a, n); - modint *b = malloc(sizeof(modint) * n * p); - modint_mat_random(n, p, b, p); - modint *c1 = malloc(sizeof(modint) * m * p); - modint_mat_mul1(m, n, p, c1, p, a, n, b, p); - modint *c2 = malloc(sizeof(modint) * m * p); - modint_mat_mul2(m, n, p, c2, p, a, n, b, p); - printf("equal = %s\n", modint_mat_equal(m, n, c1, p, c2, p)?"true":"false"); - free(a); - free(b); - free(c1); - free(c2); - return 0; -} diff --git a/test/monniaux/int_mat_run.c b/test/monniaux/int_mat_run.c new file mode 100644 index 00000000..ec68d719 --- /dev/null +++ b/test/monniaux/int_mat_run.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include "modint.h" + +int main() { + const unsigned m = 40, n = 20, p = 30; + modint *a = malloc(sizeof(modint) * m * n); + modint_mat_random(m, n, a, n); + modint *b = malloc(sizeof(modint) * n * p); + modint_mat_random(n, p, b, p); + modint *c1 = malloc(sizeof(modint) * m * p); + modint_mat_mul1(m, n, p, c1, p, a, n, b, p); + modint *c2 = malloc(sizeof(modint) * m * p); + modint_mat_mul2(m, n, p, c2, p, a, n, b, p); + printf("equal = %s\n", modint_mat_equal(m, n, c1, p, c2, p)?"true":"false"); + free(a); + free(b); + free(c1); + free(c2); + return 0; +} diff --git a/test/monniaux/modint.h b/test/monniaux/modint.h new file mode 100644 index 00000000..f1c591f8 --- /dev/null +++ b/test/monniaux/modint.h @@ -0,0 +1,26 @@ +#include +#include + +typedef uint32_t modint; +#define MODULUS 257 + +void modint_mat_mul1(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b); + +void modint_mat_mul2(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b); + +modint modint_random(void); + +void modint_mat_random(unsigned m, + unsigned n, + modint *a, unsigned stride_a); + +bool modint_mat_equal(unsigned m, + unsigned n, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b); -- cgit From 34595a9b0a2a4f7314a894294b8a9f92baa497c2 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Thu, 17 Jan 2019 20:29:57 +0100 Subject: so that we can compare gcc and ccomp .s --- test/monniaux/Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/monniaux/Makefile b/test/monniaux/Makefile index 91644c2f..6dc4cf61 100644 --- a/test/monniaux/Makefile +++ b/test/monniaux/Makefile @@ -4,15 +4,18 @@ K1C_CFLAGS=-Wall -O3 -std=c99 K1C_CCOMP=../../ccomp K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int -PRODUCTS=int_mat.host int_mat.k1c int_mat.k1c_ccomp int_mat.k1c_ccomp.s +PRODUCTS=int_mat.host int_mat.k1c int_mat.k1c_ccomp int_mat.k1c_ccomp.s int_mat.k1c.s all: $(PRODUCTS) int_mat.host: int_mat.c int_mat_run.c modint.h $(CC) $(CFLAGS) int_mat.c int_mat_run.c -o $@ -int_mat.k1c: int_mat.c int_mat_run.k1c.o modint.h - $(K1C_CC) $(K1C_CFLAGS) int_mat.c int_mat_run.k1c.o -o $@ +int_mat.k1c.s: int_mat.c modint.h + $(K1C_CC) $(K1C_CFLAGS) -S int_mat.c -o $@ + +int_mat.k1c: int_mat.k1c.s int_mat_run.k1c.o modint.h + $(K1C_CC) $(K1C_CFLAGS) int_mat.k1c.s int_mat_run.k1c.o -o $@ int_mat_run.k1c.o: int_mat_run.c modint.h $(K1C_CC) $(K1C_CFLAGS) -c int_mat_run.c -o $@ -- cgit From e470d6f582e381da781f1bf33612aa2f429a1a87 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Thu, 17 Jan 2019 20:52:25 +0100 Subject: show cycle counts --- test/monniaux/int_mat_run.c | 46 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/monniaux/int_mat_run.c b/test/monniaux/int_mat_run.c index ec68d719..3091f929 100644 --- a/test/monniaux/int_mat_run.c +++ b/test/monniaux/int_mat_run.c @@ -1,19 +1,61 @@ #include #include #include +#include #include "modint.h" +typedef uint64_t cycle_t; + +#ifdef __K1C__ +#include +static inline void cycle_count_config(void) +{ + /* config pmc for cycle count */ + uint64_t pmc_value = __builtin_k1_get(K1_SFR_PMC); + + pmc_value &= ~(0xfULL); + __builtin_k1_set(K1_SFR_PMC, pmc_value); +} + +static inline uint64_t get_cycle(void) +{ + return __builtin_k1_get(K1_SFR_PM0); +} +#else +static inline void cycle_count_config(void) { } +#ifdef __x86_64__ +#include +static inline cycle_t get_cycle(void) { return __rdtsc(); } +#else +static inline cycle_t get_cycle(void) { return 0; } +#endif +#endif + int main() { const unsigned m = 40, n = 20, p = 30; + cycle_count_config(); modint *a = malloc(sizeof(modint) * m * n); modint_mat_random(m, n, a, n); modint *b = malloc(sizeof(modint) * n * p); modint_mat_random(n, p, b, p); + modint *c1 = malloc(sizeof(modint) * m * p); - modint_mat_mul1(m, n, p, c1, p, a, n, b, p); + cycle_t c1_time = get_cycle(); + modint_mat_mul1(m, n, p, c1, p, a, n, b, p); + c1_time = get_cycle()-c1_time; + modint *c2 = malloc(sizeof(modint) * m * p); + cycle_t c2_time = get_cycle(); modint_mat_mul2(m, n, p, c2, p, a, n, b, p); - printf("equal = %s\n", modint_mat_equal(m, n, c1, p, c2, p)?"true":"false"); + c2_time = get_cycle()-c2_time; + + printf("equal = %s\n" + "c1_time = %" PRIu64 "\n" + "c2_time = %" PRIu64 "\n", + modint_mat_equal(m, n, c1, p, c2, p)?"true":"false", + c1_time, + c2_time); + free(a); free(b); free(c1); -- cgit From b75c350d2ce747e85b4418c32841cb028de021fa Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Thu, 17 Jan 2019 21:39:35 +0100 Subject: various matrix multiplication procedures --- test/monniaux/int_mat.c | 20 ++++++++++++++++++++ test/monniaux/int_mat_run.c | 17 +++++++++++++---- test/monniaux/modint.h | 5 +++++ 3 files changed, 38 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/monniaux/int_mat.c b/test/monniaux/int_mat.c index 936f45d6..5bea64fc 100644 --- a/test/monniaux/int_mat.c +++ b/test/monniaux/int_mat.c @@ -38,6 +38,26 @@ void modint_mat_mul2(unsigned m, unsigned n, unsigned p, } } +void modint_mat_mul3(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b) { + for(unsigned i=0; i Date: Thu, 17 Jan 2019 23:07:26 +0100 Subject: bugfix --- test/monniaux/int_mat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/monniaux/int_mat.c b/test/monniaux/int_mat.c index 5bea64fc..a750937d 100644 --- a/test/monniaux/int_mat.c +++ b/test/monniaux/int_mat.c @@ -46,7 +46,7 @@ void modint_mat_mul3(unsigned m, unsigned n, unsigned p, for(unsigned k=0; k Date: Fri, 18 Jan 2019 11:48:35 +0100 Subject: clearer filenames --- test/monniaux/Makefile | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/monniaux/Makefile b/test/monniaux/Makefile index 6dc4cf61..b7c3d8c5 100644 --- a/test/monniaux/Makefile +++ b/test/monniaux/Makefile @@ -4,27 +4,38 @@ K1C_CFLAGS=-Wall -O3 -std=c99 K1C_CCOMP=../../ccomp K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int -PRODUCTS=int_mat.host int_mat.k1c int_mat.k1c_ccomp int_mat.k1c_ccomp.s int_mat.k1c.s +PRODUCTS=int_mat.host int_mat.gcc.k1c int_mat.ccomp.k1c int_mat.ccomp.k1c.s int_mat.gcc.k1c.s all: $(PRODUCTS) -int_mat.host: int_mat.c int_mat_run.c modint.h - $(CC) $(CFLAGS) int_mat.c int_mat_run.c -o $@ +%.gcc.k1c.s: %.c + $(K1C_CC) $(K1C_CFLAGS) -S $< -o $@ + +%.gcc.k1c.o: %.gcc.k1c.s + $(K1C_CC) $(K1C_CFLAGS) -c $< -o $@ + +%.gcc.k1c.o: %.gcc.k1c.c + $(K1C_CC) $(K1C_CFLAGS) -c $< -o $@ -int_mat.k1c.s: int_mat.c modint.h - $(K1C_CC) $(K1C_CFLAGS) -S int_mat.c -o $@ +%.ccomp.k1c.s: %.c + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -S $< -o $@ -int_mat.k1c: int_mat.k1c.s int_mat_run.k1c.o modint.h - $(K1C_CC) $(K1C_CFLAGS) int_mat.k1c.s int_mat_run.k1c.o -o $@ +%.ccomp.k1c.o: %.ccomp.k1c.s + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -c $< -o $@ + +%.ccomp.k1c.o: %.ccomp.k1c.c + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -c $< -o $@ + +int_mat.host: int_mat.c int_mat_run.c modint.h + $(CC) $(CFLAGS) int_mat.c int_mat_run.c -o $@ -int_mat_run.k1c.o: int_mat_run.c modint.h - $(K1C_CC) $(K1C_CFLAGS) -c int_mat_run.c -o $@ +int_mat.gcc.k1c.s int_mat.ccomp.k1c.s: modint.h -int_mat.k1c_ccomp.s: int_mat.c modint.h - $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -S int_mat.c -o $@ +int_mat.gcc.k1c: int_mat.gcc.k1c.o int_mat_run.gcc.k1c.o + $(K1C_CC) $(K1C_CFLAGS) $+ -o $@ -int_mat.k1c_ccomp: int_mat.k1c_ccomp.s int_mat_run.k1c.o modint.h - $(K1C_CCOMP) $(K1C_CCOMPFLAGS) int_mat.k1c_ccomp.s int_mat_run.k1c.o -o $@ +int_mat.ccomp.k1c: int_mat.ccomp.k1c.o int_mat_run.gcc.k1c.o + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) $+ -o $@ clean: $(RM) -f $(PRODUCTS) -- cgit From 6d9954bf61b0e709ae93e7e7212c8090fc07dc56 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Fri, 18 Jan 2019 11:53:21 +0100 Subject: some better experiments... --- test/monniaux/Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/monniaux/Makefile b/test/monniaux/Makefile index b7c3d8c5..be534653 100644 --- a/test/monniaux/Makefile +++ b/test/monniaux/Makefile @@ -4,7 +4,7 @@ K1C_CFLAGS=-Wall -O3 -std=c99 K1C_CCOMP=../../ccomp K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int -PRODUCTS=int_mat.host int_mat.gcc.k1c int_mat.ccomp.k1c int_mat.ccomp.k1c.s int_mat.gcc.k1c.s +PRODUCTS=int_mat.host int_mat.gcc.k1c.out int_mat.ccomp.k1c.out int_mat.ccomp.k1c.s int_mat.gcc.k1c.s all: $(PRODUCTS) @@ -37,7 +37,10 @@ int_mat.gcc.k1c: int_mat.gcc.k1c.o int_mat_run.gcc.k1c.o int_mat.ccomp.k1c: int_mat.ccomp.k1c.o int_mat_run.gcc.k1c.o $(K1C_CCOMP) $(K1C_CCOMPFLAGS) $+ -o $@ +%.k1c.out: %.k1c + k1-cluster --cycle-based -- $< | tee $@ + clean: - $(RM) -f $(PRODUCTS) + $(RM) -f $(PRODUCTS) int_mat.gcc.k1c.o int_mat.ccomp.k1c.o .PHONY: clean -- cgit From 3685268c6334f68001b2454fc3fa294d8b7a0688 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Fri, 18 Jan 2019 12:57:55 +0100 Subject: fourth version --- test/monniaux/int_mat.c | 22 ++++++++++++++++++++++ test/monniaux/int_mat_run.c | 13 +++++++++++-- test/monniaux/modint.h | 5 +++++ 3 files changed, 38 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/monniaux/int_mat.c b/test/monniaux/int_mat.c index a750937d..cc8c59e5 100644 --- a/test/monniaux/int_mat.c +++ b/test/monniaux/int_mat.c @@ -58,6 +58,28 @@ void modint_mat_mul3(unsigned m, unsigned n, unsigned p, } } +void modint_mat_mul4(unsigned m, unsigned n, unsigned p, + modint * c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b) { + const modint *pa_i = a; + modint * pc_i = c; + for(unsigned i=0; i Date: Fri, 18 Jan 2019 13:02:58 +0100 Subject: fix free() bug --- test/monniaux/int_mat_run.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test') diff --git a/test/monniaux/int_mat_run.c b/test/monniaux/int_mat_run.c index 3fc4b64e..9367fae0 100644 --- a/test/monniaux/int_mat_run.c +++ b/test/monniaux/int_mat_run.c @@ -78,5 +78,7 @@ int main() { free(b); free(c1); free(c2); + free(c3); + free(c4); return 0; } -- cgit From ac6e6181c48b0e21219c1ea57e30fa8d3c3f1714 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Fri, 18 Jan 2019 14:07:17 +0100 Subject: some unrolling --- test/monniaux/Makefile | 2 +- test/monniaux/int_mat.c | 29 +++++++++++++++++++++++++++++ test/monniaux/int_mat_run.c | 14 ++++++++++++-- test/monniaux/modint.h | 5 +++++ 4 files changed, 47 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/monniaux/Makefile b/test/monniaux/Makefile index be534653..aa559699 100644 --- a/test/monniaux/Makefile +++ b/test/monniaux/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -O3 K1C_CC=k1-mbr-gcc -K1C_CFLAGS=-Wall -O3 -std=c99 +K1C_CFLAGS=-Wall -O2 -std=c99 K1C_CCOMP=../../ccomp K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int diff --git a/test/monniaux/int_mat.c b/test/monniaux/int_mat.c index cc8c59e5..d3e14e26 100644 --- a/test/monniaux/int_mat.c +++ b/test/monniaux/int_mat.c @@ -80,6 +80,35 @@ void modint_mat_mul4(unsigned m, unsigned n, unsigned p, } } +void modint_mat_mul5(unsigned m, unsigned n, unsigned p, + modint * c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b) { + const modint *pa_i = a; + modint * pc_i = c; + for(unsigned i=0; i Date: Fri, 18 Jan 2019 15:16:17 +0100 Subject: moved to subdirectory --- test/monniaux/Makefile | 46 ----------- test/monniaux/int_mat.c | 138 -------------------------------- test/monniaux/int_mat_run.c | 94 ---------------------- test/monniaux/mod_int_mat/Makefile | 46 +++++++++++ test/monniaux/mod_int_mat/int_mat.c | 138 ++++++++++++++++++++++++++++++++ test/monniaux/mod_int_mat/int_mat_run.c | 94 ++++++++++++++++++++++ test/monniaux/mod_int_mat/modint.h | 41 ++++++++++ test/monniaux/modint.h | 41 ---------- 8 files changed, 319 insertions(+), 319 deletions(-) delete mode 100644 test/monniaux/Makefile delete mode 100644 test/monniaux/int_mat.c delete mode 100644 test/monniaux/int_mat_run.c create mode 100644 test/monniaux/mod_int_mat/Makefile create mode 100644 test/monniaux/mod_int_mat/int_mat.c create mode 100644 test/monniaux/mod_int_mat/int_mat_run.c create mode 100644 test/monniaux/mod_int_mat/modint.h delete mode 100644 test/monniaux/modint.h (limited to 'test') diff --git a/test/monniaux/Makefile b/test/monniaux/Makefile deleted file mode 100644 index aa559699..00000000 --- a/test/monniaux/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -CFLAGS=-Wall -O3 -K1C_CC=k1-mbr-gcc -K1C_CFLAGS=-Wall -O2 -std=c99 -K1C_CCOMP=../../ccomp -K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int - -PRODUCTS=int_mat.host int_mat.gcc.k1c.out int_mat.ccomp.k1c.out int_mat.ccomp.k1c.s int_mat.gcc.k1c.s - -all: $(PRODUCTS) - -%.gcc.k1c.s: %.c - $(K1C_CC) $(K1C_CFLAGS) -S $< -o $@ - -%.gcc.k1c.o: %.gcc.k1c.s - $(K1C_CC) $(K1C_CFLAGS) -c $< -o $@ - -%.gcc.k1c.o: %.gcc.k1c.c - $(K1C_CC) $(K1C_CFLAGS) -c $< -o $@ - -%.ccomp.k1c.s: %.c - $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -S $< -o $@ - -%.ccomp.k1c.o: %.ccomp.k1c.s - $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -c $< -o $@ - -%.ccomp.k1c.o: %.ccomp.k1c.c - $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -c $< -o $@ - -int_mat.host: int_mat.c int_mat_run.c modint.h - $(CC) $(CFLAGS) int_mat.c int_mat_run.c -o $@ - -int_mat.gcc.k1c.s int_mat.ccomp.k1c.s: modint.h - -int_mat.gcc.k1c: int_mat.gcc.k1c.o int_mat_run.gcc.k1c.o - $(K1C_CC) $(K1C_CFLAGS) $+ -o $@ - -int_mat.ccomp.k1c: int_mat.ccomp.k1c.o int_mat_run.gcc.k1c.o - $(K1C_CCOMP) $(K1C_CCOMPFLAGS) $+ -o $@ - -%.k1c.out: %.k1c - k1-cluster --cycle-based -- $< | tee $@ - -clean: - $(RM) -f $(PRODUCTS) int_mat.gcc.k1c.o int_mat.ccomp.k1c.o - -.PHONY: clean diff --git a/test/monniaux/int_mat.c b/test/monniaux/int_mat.c deleted file mode 100644 index d3e14e26..00000000 --- a/test/monniaux/int_mat.c +++ /dev/null @@ -1,138 +0,0 @@ -#include "modint.h" - -void modint_mat_mul1(unsigned m, unsigned n, unsigned p, - modint * restrict c, unsigned stride_c, - const modint *a, unsigned stride_a, - const modint *b, unsigned stride_b) { - for(unsigned i=0; i -#include -#include -#include -#include "modint.h" - -typedef uint64_t cycle_t; - -#ifdef __K1C__ -#include -static inline void cycle_count_config(void) -{ - /* config pmc for cycle count */ - uint64_t pmc_value = __builtin_k1_get(K1_SFR_PMC); - - pmc_value &= ~(0xfULL); - __builtin_k1_set(K1_SFR_PMC, pmc_value); -} - -static inline uint64_t get_cycle(void) -{ - return __builtin_k1_get(K1_SFR_PM0); -} -#else -static inline void cycle_count_config(void) { } -#ifdef __x86_64__ -#include -static inline cycle_t get_cycle(void) { return __rdtsc(); } -#else -static inline cycle_t get_cycle(void) { return 0; } -#endif -#endif - -int main() { - const unsigned m = 40, n = 21, p = 30; - cycle_count_config(); - modint *a = malloc(sizeof(modint) * m * n); - modint_mat_random(m, n, a, n); - modint *b = malloc(sizeof(modint) * n * p); - modint_mat_random(n, p, b, p); - - modint *c1 = malloc(sizeof(modint) * m * p); - cycle_t c1_time = get_cycle(); - modint_mat_mul1(m, n, p, c1, p, a, n, b, p); - c1_time = get_cycle()-c1_time; - - modint *c2 = malloc(sizeof(modint) * m * p); - cycle_t c2_time = get_cycle(); - modint_mat_mul2(m, n, p, c2, p, a, n, b, p); - c2_time = get_cycle()-c2_time; - - modint *c3 = malloc(sizeof(modint) * m * p); - cycle_t c3_time = get_cycle(); - modint_mat_mul3(m, n, p, c3, p, a, n, b, p); - c3_time = get_cycle()-c3_time; - - modint *c4 = malloc(sizeof(modint) * m * p); - cycle_t c4_time = get_cycle(); - modint_mat_mul4(m, n, p, c4, p, a, n, b, p); - c4_time = get_cycle()-c4_time; - - modint *c5 = malloc(sizeof(modint) * m * p); - cycle_t c5_time = get_cycle(); - modint_mat_mul5(m, n, p, c5, p, a, n, b, p); - c5_time = get_cycle()-c5_time; - - printf("c1==c2: %s\n" - "c1==c3: %s\n" - "c1==c4: %s\n" - "c1==c5: %s\n" - "c1_time = %" PRIu64 "\n" - "c2_time = %" PRIu64 "\n" - "c3_time = %" PRIu64 "\n" - "c4_time = %" PRIu64 "\n" - "c5_time = %" PRIu64 "\n", - modint_mat_equal(m, n, c1, p, c2, p)?"true":"false", - modint_mat_equal(m, n, c1, p, c3, p)?"true":"false", - modint_mat_equal(m, n, c1, p, c4, p)?"true":"false", - modint_mat_equal(m, n, c1, p, c5, p)?"true":"false", - c1_time, - c2_time, - c3_time, - c4_time, - c5_time); - - free(a); - free(b); - free(c1); - free(c2); - free(c3); - free(c4); - free(c5); - return 0; -} diff --git a/test/monniaux/mod_int_mat/Makefile b/test/monniaux/mod_int_mat/Makefile new file mode 100644 index 00000000..be534653 --- /dev/null +++ b/test/monniaux/mod_int_mat/Makefile @@ -0,0 +1,46 @@ +CFLAGS=-Wall -O3 +K1C_CC=k1-mbr-gcc +K1C_CFLAGS=-Wall -O3 -std=c99 +K1C_CCOMP=../../ccomp +K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int + +PRODUCTS=int_mat.host int_mat.gcc.k1c.out int_mat.ccomp.k1c.out int_mat.ccomp.k1c.s int_mat.gcc.k1c.s + +all: $(PRODUCTS) + +%.gcc.k1c.s: %.c + $(K1C_CC) $(K1C_CFLAGS) -S $< -o $@ + +%.gcc.k1c.o: %.gcc.k1c.s + $(K1C_CC) $(K1C_CFLAGS) -c $< -o $@ + +%.gcc.k1c.o: %.gcc.k1c.c + $(K1C_CC) $(K1C_CFLAGS) -c $< -o $@ + +%.ccomp.k1c.s: %.c + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -S $< -o $@ + +%.ccomp.k1c.o: %.ccomp.k1c.s + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -c $< -o $@ + +%.ccomp.k1c.o: %.ccomp.k1c.c + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -c $< -o $@ + +int_mat.host: int_mat.c int_mat_run.c modint.h + $(CC) $(CFLAGS) int_mat.c int_mat_run.c -o $@ + +int_mat.gcc.k1c.s int_mat.ccomp.k1c.s: modint.h + +int_mat.gcc.k1c: int_mat.gcc.k1c.o int_mat_run.gcc.k1c.o + $(K1C_CC) $(K1C_CFLAGS) $+ -o $@ + +int_mat.ccomp.k1c: int_mat.ccomp.k1c.o int_mat_run.gcc.k1c.o + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) $+ -o $@ + +%.k1c.out: %.k1c + k1-cluster --cycle-based -- $< | tee $@ + +clean: + $(RM) -f $(PRODUCTS) int_mat.gcc.k1c.o int_mat.ccomp.k1c.o + +.PHONY: clean diff --git a/test/monniaux/mod_int_mat/int_mat.c b/test/monniaux/mod_int_mat/int_mat.c new file mode 100644 index 00000000..d3e14e26 --- /dev/null +++ b/test/monniaux/mod_int_mat/int_mat.c @@ -0,0 +1,138 @@ +#include "modint.h" + +void modint_mat_mul1(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b) { + for(unsigned i=0; i +#include +#include +#include +#include "modint.h" + +typedef uint64_t cycle_t; + +#ifdef __K1C__ +#include +static inline void cycle_count_config(void) +{ + /* config pmc for cycle count */ + uint64_t pmc_value = __builtin_k1_get(K1_SFR_PMC); + + pmc_value &= ~(0xfULL); + __builtin_k1_set(K1_SFR_PMC, pmc_value); +} + +static inline uint64_t get_cycle(void) +{ + return __builtin_k1_get(K1_SFR_PM0); +} +#else +static inline void cycle_count_config(void) { } +#ifdef __x86_64__ +#include +static inline cycle_t get_cycle(void) { return __rdtsc(); } +#else +static inline cycle_t get_cycle(void) { return 0; } +#endif +#endif + +int main() { + const unsigned m = 40, n = 21, p = 30; + cycle_count_config(); + modint *a = malloc(sizeof(modint) * m * n); + modint_mat_random(m, n, a, n); + modint *b = malloc(sizeof(modint) * n * p); + modint_mat_random(n, p, b, p); + + modint *c1 = malloc(sizeof(modint) * m * p); + cycle_t c1_time = get_cycle(); + modint_mat_mul1(m, n, p, c1, p, a, n, b, p); + c1_time = get_cycle()-c1_time; + + modint *c2 = malloc(sizeof(modint) * m * p); + cycle_t c2_time = get_cycle(); + modint_mat_mul2(m, n, p, c2, p, a, n, b, p); + c2_time = get_cycle()-c2_time; + + modint *c3 = malloc(sizeof(modint) * m * p); + cycle_t c3_time = get_cycle(); + modint_mat_mul3(m, n, p, c3, p, a, n, b, p); + c3_time = get_cycle()-c3_time; + + modint *c4 = malloc(sizeof(modint) * m * p); + cycle_t c4_time = get_cycle(); + modint_mat_mul4(m, n, p, c4, p, a, n, b, p); + c4_time = get_cycle()-c4_time; + + modint *c5 = malloc(sizeof(modint) * m * p); + cycle_t c5_time = get_cycle(); + modint_mat_mul5(m, n, p, c5, p, a, n, b, p); + c5_time = get_cycle()-c5_time; + + printf("c1==c2: %s\n" + "c1==c3: %s\n" + "c1==c4: %s\n" + "c1==c5: %s\n" + "c1_time = %" PRIu64 "\n" + "c2_time = %" PRIu64 "\n" + "c3_time = %" PRIu64 "\n" + "c4_time = %" PRIu64 "\n" + "c5_time = %" PRIu64 "\n", + modint_mat_equal(m, n, c1, p, c2, p)?"true":"false", + modint_mat_equal(m, n, c1, p, c3, p)?"true":"false", + modint_mat_equal(m, n, c1, p, c4, p)?"true":"false", + modint_mat_equal(m, n, c1, p, c5, p)?"true":"false", + c1_time, + c2_time, + c3_time, + c4_time, + c5_time); + + free(a); + free(b); + free(c1); + free(c2); + free(c3); + free(c4); + free(c5); + return 0; +} diff --git a/test/monniaux/mod_int_mat/modint.h b/test/monniaux/mod_int_mat/modint.h new file mode 100644 index 00000000..5295258b --- /dev/null +++ b/test/monniaux/mod_int_mat/modint.h @@ -0,0 +1,41 @@ +#include +#include + +typedef uint32_t modint; +#define MODULUS 257 + +void modint_mat_mul1(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b); + +void modint_mat_mul2(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b); + +void modint_mat_mul3(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b); + +void modint_mat_mul4(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b); + +void modint_mat_mul5(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b); + +modint modint_random(void); + +void modint_mat_random(unsigned m, + unsigned n, + modint *a, unsigned stride_a); + +bool modint_mat_equal(unsigned m, + unsigned n, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b); diff --git a/test/monniaux/modint.h b/test/monniaux/modint.h deleted file mode 100644 index 5295258b..00000000 --- a/test/monniaux/modint.h +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include - -typedef uint32_t modint; -#define MODULUS 257 - -void modint_mat_mul1(unsigned m, unsigned n, unsigned p, - modint * restrict c, unsigned stride_c, - const modint *a, unsigned stride_a, - const modint *b, unsigned stride_b); - -void modint_mat_mul2(unsigned m, unsigned n, unsigned p, - modint * restrict c, unsigned stride_c, - const modint *a, unsigned stride_a, - const modint *b, unsigned stride_b); - -void modint_mat_mul3(unsigned m, unsigned n, unsigned p, - modint * restrict c, unsigned stride_c, - const modint *a, unsigned stride_a, - const modint *b, unsigned stride_b); - -void modint_mat_mul4(unsigned m, unsigned n, unsigned p, - modint * restrict c, unsigned stride_c, - const modint *a, unsigned stride_a, - const modint *b, unsigned stride_b); - -void modint_mat_mul5(unsigned m, unsigned n, unsigned p, - modint * restrict c, unsigned stride_c, - const modint *a, unsigned stride_a, - const modint *b, unsigned stride_b); - -modint modint_random(void); - -void modint_mat_random(unsigned m, - unsigned n, - modint *a, unsigned stride_a); - -bool modint_mat_equal(unsigned m, - unsigned n, - const modint *a, unsigned stride_a, - const modint *b, unsigned stride_b); -- cgit From 2a1db308610355d66c6baff004702fd00816e25a Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Fri, 18 Jan 2019 16:09:13 +0100 Subject: adjust path --- test/monniaux/mod_int_mat/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/monniaux/mod_int_mat/Makefile b/test/monniaux/mod_int_mat/Makefile index be534653..9a90a4ae 100644 --- a/test/monniaux/mod_int_mat/Makefile +++ b/test/monniaux/mod_int_mat/Makefile @@ -1,7 +1,7 @@ CFLAGS=-Wall -O3 K1C_CC=k1-mbr-gcc K1C_CFLAGS=-Wall -O3 -std=c99 -K1C_CCOMP=../../ccomp +K1C_CCOMP=../../../ccomp K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int PRODUCTS=int_mat.host int_mat.gcc.k1c.out int_mat.ccomp.k1c.out int_mat.ccomp.k1c.s int_mat.gcc.k1c.s -- cgit From a873e3fb7164db2be4641b244a63895dfc0660dd Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Fri, 18 Jan 2019 17:17:23 +0100 Subject: loop transformation --- test/monniaux/mod_int_mat/int_mat.c | 33 +++++++++++++++++++++++++++++++++ test/monniaux/mod_int_mat/int_mat_run.c | 14 ++++++++++++-- test/monniaux/mod_int_mat/modint.h | 5 +++++ 3 files changed, 50 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/monniaux/mod_int_mat/int_mat.c b/test/monniaux/mod_int_mat/int_mat.c index d3e14e26..58f968c1 100644 --- a/test/monniaux/mod_int_mat/int_mat.c +++ b/test/monniaux/mod_int_mat/int_mat.c @@ -109,6 +109,39 @@ void modint_mat_mul5(unsigned m, unsigned n, unsigned p, } } +void modint_mat_mul6(unsigned m, unsigned n, unsigned p, + modint * c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b) { + const modint *pa_i = a; + modint * pc_i = c; + for(unsigned i=0; i 0) { + do { + modint p0 = *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + modint p1 = *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + total += p0 + p1; + j2++; + } while (j2 < n2); + } + if (n%2) { + total += *pa_i_j * *pb_j_k; + } + pc_i[k] = total % MODULUS; + } + pa_i += stride_a; + pc_i += stride_c; + } +} + modint modint_random(void) { static uint64_t next = 1325997111; next = next * 1103515245 + 12345; diff --git a/test/monniaux/mod_int_mat/int_mat_run.c b/test/monniaux/mod_int_mat/int_mat_run.c index 9d5c0c57..20d564cc 100644 --- a/test/monniaux/mod_int_mat/int_mat_run.c +++ b/test/monniaux/mod_int_mat/int_mat_run.c @@ -64,24 +64,33 @@ int main() { modint_mat_mul5(m, n, p, c5, p, a, n, b, p); c5_time = get_cycle()-c5_time; + modint *c6 = malloc(sizeof(modint) * m * p); + cycle_t c6_time = get_cycle(); + modint_mat_mul6(m, n, p, c6, p, a, n, b, p); + c6_time = get_cycle()-c6_time; + printf("c1==c2: %s\n" "c1==c3: %s\n" "c1==c4: %s\n" "c1==c5: %s\n" + "c1==c6: %s\n" "c1_time = %" PRIu64 "\n" "c2_time = %" PRIu64 "\n" "c3_time = %" PRIu64 "\n" "c4_time = %" PRIu64 "\n" - "c5_time = %" PRIu64 "\n", + "c5_time = %" PRIu64 "\n" + "c6_time = %" PRIu64 "\n", modint_mat_equal(m, n, c1, p, c2, p)?"true":"false", modint_mat_equal(m, n, c1, p, c3, p)?"true":"false", modint_mat_equal(m, n, c1, p, c4, p)?"true":"false", modint_mat_equal(m, n, c1, p, c5, p)?"true":"false", + modint_mat_equal(m, n, c1, p, c6, p)?"true":"false", c1_time, c2_time, c3_time, c4_time, - c5_time); + c5_time, + c6_time); free(a); free(b); @@ -90,5 +99,6 @@ int main() { free(c3); free(c4); free(c5); + free(c6); return 0; } diff --git a/test/monniaux/mod_int_mat/modint.h b/test/monniaux/mod_int_mat/modint.h index 5295258b..92005455 100644 --- a/test/monniaux/mod_int_mat/modint.h +++ b/test/monniaux/mod_int_mat/modint.h @@ -29,6 +29,11 @@ void modint_mat_mul5(unsigned m, unsigned n, unsigned p, const modint *a, unsigned stride_a, const modint *b, unsigned stride_b); +void modint_mat_mul6(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b); + modint modint_random(void); void modint_mat_random(unsigned m, -- cgit From 017d67d668d47fc67038226939653889814cbcac Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Fri, 18 Jan 2019 17:30:07 +0100 Subject: more on matrices --- test/monniaux/mod_int_mat/int_mat.c | 53 +++++++++++++++++++++++++++++++-- test/monniaux/mod_int_mat/int_mat_run.c | 15 ++++++++-- test/monniaux/mod_int_mat/modint.h | 5 ++++ 3 files changed, 68 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/monniaux/mod_int_mat/int_mat.c b/test/monniaux/mod_int_mat/int_mat.c index 58f968c1..0e51d7ba 100644 --- a/test/monniaux/mod_int_mat/int_mat.c +++ b/test/monniaux/mod_int_mat/int_mat.c @@ -122,13 +122,12 @@ void modint_mat_mul6(unsigned m, unsigned n, unsigned p, unsigned j2=0, n2=n/2; if (n2 > 0) { do { - modint p0 = *pa_i_j * *pb_j_k; + total += *pa_i_j * *pb_j_k; pa_i_j ++; pb_j_k += stride_b; - modint p1 = *pa_i_j * *pb_j_k; + total += *pa_i_j * *pb_j_k; pa_i_j ++; pb_j_k += stride_b; - total += p0 + p1; j2++; } while (j2 < n2); } @@ -142,6 +141,54 @@ void modint_mat_mul6(unsigned m, unsigned n, unsigned p, } } +void modint_mat_mul7(unsigned m, unsigned n, unsigned p, + modint * c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b) { + const modint *pa_i = a; + modint * pc_i = c; + for(unsigned i=0; i 0) { + do { + total += *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + total += *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + total += *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + total += *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + j4++; + } while (j4 < n4); + } + } + { + unsigned j4=0, n4=n%4; + if (n4 > 0) { + do { + total += *pa_i_j * *pb_j_k; + pa_i_j ++; + pb_j_k += stride_b; + j4++; + } while (j4 < n4); + } + } + pc_i[k] = total % MODULUS; + } + pa_i += stride_a; + pc_i += stride_c; + } +} + modint modint_random(void) { static uint64_t next = 1325997111; next = next * 1103515245 + 12345; diff --git a/test/monniaux/mod_int_mat/int_mat_run.c b/test/monniaux/mod_int_mat/int_mat_run.c index 20d564cc..42cb54fb 100644 --- a/test/monniaux/mod_int_mat/int_mat_run.c +++ b/test/monniaux/mod_int_mat/int_mat_run.c @@ -69,28 +69,39 @@ int main() { modint_mat_mul6(m, n, p, c6, p, a, n, b, p); c6_time = get_cycle()-c6_time; + modint *c7 = malloc(sizeof(modint) * m * p); + cycle_t c7_time = get_cycle(); + modint_mat_mul7(m, n, p, c7, p, a, n, b, p); + c7_time = get_cycle()-c7_time; + printf("c1==c2: %s\n" "c1==c3: %s\n" "c1==c4: %s\n" "c1==c5: %s\n" "c1==c6: %s\n" + "c1==c7: %s\n" "c1_time = %" PRIu64 "\n" "c2_time = %" PRIu64 "\n" "c3_time = %" PRIu64 "\n" "c4_time = %" PRIu64 "\n" "c5_time = %" PRIu64 "\n" - "c6_time = %" PRIu64 "\n", + "c6_time = %" PRIu64 "\n" + "c7_time = %" PRIu64 "\n", + modint_mat_equal(m, n, c1, p, c2, p)?"true":"false", modint_mat_equal(m, n, c1, p, c3, p)?"true":"false", modint_mat_equal(m, n, c1, p, c4, p)?"true":"false", modint_mat_equal(m, n, c1, p, c5, p)?"true":"false", modint_mat_equal(m, n, c1, p, c6, p)?"true":"false", + modint_mat_equal(m, n, c1, p, c7, p)?"true":"false", + c1_time, c2_time, c3_time, c4_time, c5_time, - c6_time); + c6_time, + c7_time); free(a); free(b); diff --git a/test/monniaux/mod_int_mat/modint.h b/test/monniaux/mod_int_mat/modint.h index 92005455..15c70a15 100644 --- a/test/monniaux/mod_int_mat/modint.h +++ b/test/monniaux/mod_int_mat/modint.h @@ -34,6 +34,11 @@ void modint_mat_mul6(unsigned m, unsigned n, unsigned p, const modint *a, unsigned stride_a, const modint *b, unsigned stride_b); +void modint_mat_mul7(unsigned m, unsigned n, unsigned p, + modint * restrict c, unsigned stride_c, + const modint *a, unsigned stride_a, + const modint *b, unsigned stride_b); + modint modint_random(void); void modint_mat_random(unsigned m, -- cgit From 91c23dece6e83c1b6566530ecf9467e091934474 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Fri, 18 Jan 2019 21:33:13 +0100 Subject: fix Makefile --- test/monniaux/mod_int_mat/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/monniaux/mod_int_mat/Makefile b/test/monniaux/mod_int_mat/Makefile index 9a90a4ae..912d016b 100644 --- a/test/monniaux/mod_int_mat/Makefile +++ b/test/monniaux/mod_int_mat/Makefile @@ -4,7 +4,7 @@ K1C_CFLAGS=-Wall -O3 -std=c99 K1C_CCOMP=../../../ccomp K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int -PRODUCTS=int_mat.host int_mat.gcc.k1c.out int_mat.ccomp.k1c.out int_mat.ccomp.k1c.s int_mat.gcc.k1c.s +PRODUCTS=int_mat.host int_mat.gcc.k1c.out int_mat.ccomp.k1c.out int_mat.ccomp.k1c.s int_mat.gcc.k1c.s int_mat.gcc.k1c int_mat.ccomp.k1c all: $(PRODUCTS) @@ -41,6 +41,6 @@ int_mat.ccomp.k1c: int_mat.ccomp.k1c.o int_mat_run.gcc.k1c.o k1-cluster --cycle-based -- $< | tee $@ clean: - $(RM) -f $(PRODUCTS) int_mat.gcc.k1c.o int_mat.ccomp.k1c.o + $(RM) -f $(PRODUCTS) int_mat.gcc.k1c.o int_mat.ccomp.k1c.o int_mat_run.gcc.k1c.o .PHONY: clean -- cgit From caa53a3dce35e53ed913557f30aef1f063cf67c0 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Sat, 19 Jan 2019 13:21:49 +0100 Subject: fixes in Makefile --- test/monniaux/mod_int_mat/Makefile | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'test') diff --git a/test/monniaux/mod_int_mat/Makefile b/test/monniaux/mod_int_mat/Makefile index 912d016b..b285c03c 100644 --- a/test/monniaux/mod_int_mat/Makefile +++ b/test/monniaux/mod_int_mat/Makefile @@ -14,22 +14,16 @@ all: $(PRODUCTS) %.gcc.k1c.o: %.gcc.k1c.s $(K1C_CC) $(K1C_CFLAGS) -c $< -o $@ -%.gcc.k1c.o: %.gcc.k1c.c - $(K1C_CC) $(K1C_CFLAGS) -c $< -o $@ - %.ccomp.k1c.s: %.c $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -S $< -o $@ %.ccomp.k1c.o: %.ccomp.k1c.s $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -c $< -o $@ -%.ccomp.k1c.o: %.ccomp.k1c.c - $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -c $< -o $@ - int_mat.host: int_mat.c int_mat_run.c modint.h $(CC) $(CFLAGS) int_mat.c int_mat_run.c -o $@ -int_mat.gcc.k1c.s int_mat.ccomp.k1c.s: modint.h +int_mat.gcc.k1c.s int_mat.ccomp.k1c.s int_mat_run.gcc.k1c.s: modint.h int_mat.gcc.k1c: int_mat.gcc.k1c.o int_mat_run.gcc.k1c.o $(K1C_CC) $(K1C_CFLAGS) $+ -o $@ -- cgit From 6c5df17a302e99dec62aa749ffc30745cc7679a4 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Sat, 19 Jan 2019 13:33:57 +0100 Subject: quicksort --- test/monniaux/cycles.h | 26 ++++++++++++++++++++ test/monniaux/mod_int_mat/int_mat_run.c | 28 +--------------------- test/monniaux/quicksort/Makefile | 40 +++++++++++++++++++++++++++++++ test/monniaux/quicksort/quicksort.c | 42 +++++++++++++++++++++++++++++++++ test/monniaux/quicksort/quicksort.h | 7 ++++++ test/monniaux/quicksort/quicksort_run.c | 22 +++++++++++++++++ 6 files changed, 138 insertions(+), 27 deletions(-) create mode 100644 test/monniaux/cycles.h create mode 100644 test/monniaux/quicksort/Makefile create mode 100644 test/monniaux/quicksort/quicksort.c create mode 100644 test/monniaux/quicksort/quicksort.h create mode 100644 test/monniaux/quicksort/quicksort_run.c (limited to 'test') diff --git a/test/monniaux/cycles.h b/test/monniaux/cycles.h new file mode 100644 index 00000000..212e65fc --- /dev/null +++ b/test/monniaux/cycles.h @@ -0,0 +1,26 @@ +typedef uint64_t cycle_t; + +#ifdef __K1C__ +#include +static inline void cycle_count_config(void) +{ + /* config pmc for cycle count */ + uint64_t pmc_value = __builtin_k1_get(K1_SFR_PMC); + + pmc_value &= ~(0xfULL); + __builtin_k1_set(K1_SFR_PMC, pmc_value); +} + +static inline uint64_t get_cycle(void) +{ + return __builtin_k1_get(K1_SFR_PM0); +} +#else +static inline void cycle_count_config(void) { } +#ifdef __x86_64__ +#include +static inline cycle_t get_cycle(void) { return __rdtsc(); } +#else +static inline cycle_t get_cycle(void) { return 0; } +#endif +#endif diff --git a/test/monniaux/mod_int_mat/int_mat_run.c b/test/monniaux/mod_int_mat/int_mat_run.c index 42cb54fb..f3955345 100644 --- a/test/monniaux/mod_int_mat/int_mat_run.c +++ b/test/monniaux/mod_int_mat/int_mat_run.c @@ -3,33 +3,7 @@ #include #include #include "modint.h" - -typedef uint64_t cycle_t; - -#ifdef __K1C__ -#include -static inline void cycle_count_config(void) -{ - /* config pmc for cycle count */ - uint64_t pmc_value = __builtin_k1_get(K1_SFR_PMC); - - pmc_value &= ~(0xfULL); - __builtin_k1_set(K1_SFR_PMC, pmc_value); -} - -static inline uint64_t get_cycle(void) -{ - return __builtin_k1_get(K1_SFR_PM0); -} -#else -static inline void cycle_count_config(void) { } -#ifdef __x86_64__ -#include -static inline cycle_t get_cycle(void) { return __rdtsc(); } -#else -static inline cycle_t get_cycle(void) { return 0; } -#endif -#endif +#include "../cycles.h" int main() { const unsigned m = 40, n = 21, p = 30; diff --git a/test/monniaux/quicksort/Makefile b/test/monniaux/quicksort/Makefile new file mode 100644 index 00000000..1d8913dd --- /dev/null +++ b/test/monniaux/quicksort/Makefile @@ -0,0 +1,40 @@ +CFLAGS=-Wall -O3 +K1C_CC=k1-mbr-gcc +K1C_CFLAGS=-Wall -O3 -std=c99 +K1C_CCOMP=../../../ccomp +K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int + +PRODUCTS=quicksort.host quicksort.gcc.k1c.out quicksort.ccomp.k1c.out quicksort.ccomp.k1c.s quicksort.gcc.k1c.s quicksort.gcc.k1c quicksort.ccomp.k1c + +all: $(PRODUCTS) + +%.gcc.k1c.s: %.c + $(K1C_CC) $(K1C_CFLAGS) -S $< -o $@ + +%.gcc.k1c.o: %.gcc.k1c.s + $(K1C_CC) $(K1C_CFLAGS) -c $< -o $@ + +%.ccomp.k1c.s: %.c + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -S $< -o $@ + +%.ccomp.k1c.o: %.ccomp.k1c.s + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -c $< -o $@ + +quicksort.host: quicksort.c quicksort_run.c quicksort.h + $(CC) $(CFLAGS) quicksort.c quicksort_run.c -o $@ + +quicksort.gcc.k1c.s quicksort.ccomp.k1c.s quicksort_run.gcc.k1c.s: quicksort.h + +quicksort.gcc.k1c: quicksort.gcc.k1c.o quicksort_run.gcc.k1c.o + $(K1C_CC) $(K1C_CFLAGS) $+ -o $@ + +quicksort.ccomp.k1c: quicksort.ccomp.k1c.o quicksort_run.gcc.k1c.o + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) $+ -o $@ + +%.k1c.out: %.k1c + k1-cluster --cycle-based -- $< | tee $@ + +clean: + $(RM) -f $(PRODUCTS) quicksort.gcc.k1c.o quicksort.ccomp.k1c.o quicksort_run.gcc.k1c.o + +.PHONY: clean diff --git a/test/monniaux/quicksort/quicksort.c b/test/monniaux/quicksort/quicksort.c new file mode 100644 index 00000000..de04bf2d --- /dev/null +++ b/test/monniaux/quicksort/quicksort.c @@ -0,0 +1,42 @@ +#include "quicksort.h" + +/* Rosetta Code */ +void quicksort(data *A, int len) { + if (len < 2) return; + + data pivot = A[len / 2]; + + int i, j; + for (i = 0, j = len - 1; ; i++, j--) { + while (A[i] < pivot) i++; + while (A[j] > pivot) j--; + + if (i >= j) break; + + data temp = A[i]; + A[i] = A[j]; + A[j] = temp; + } + + quicksort(A, i); + quicksort(A + i, len - i); +} + +data data_random(void) { + static uint64_t next = 1325997111; + next = next * 1103515245 + 12345; + return next; +} + +void data_vec_random(data *a, unsigned len) { + for(unsigned i=0; i a[i+1]) return false; + } + return true; +} diff --git a/test/monniaux/quicksort/quicksort.h b/test/monniaux/quicksort/quicksort.h new file mode 100644 index 00000000..cc73e7c3 --- /dev/null +++ b/test/monniaux/quicksort/quicksort.h @@ -0,0 +1,7 @@ +#include +#include + +typedef uint64_t data; +void quicksort(data *A, int len); +void data_vec_random(data *a, unsigned len); +bool data_vec_is_sorted(const data *a, unsigned len); diff --git a/test/monniaux/quicksort/quicksort_run.c b/test/monniaux/quicksort/quicksort_run.c new file mode 100644 index 00000000..c269cc48 --- /dev/null +++ b/test/monniaux/quicksort/quicksort_run.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include "quicksort.h" +#include "../cycles.h" + +int main (void) { + cycle_count_config(); + unsigned len=10000; + data *vec = malloc(sizeof(data) * len); + data_vec_random(vec, len); + cycle_t quicksort_time = get_cycle(); + quicksort(vec, len); + quicksort_time = get_cycle() - quicksort_time; + printf("sorted=%s\n" + "quicksort_time=%" PRIu64 "\n", + data_vec_is_sorted(vec, len)?"true":"false", + quicksort_time); + free(vec); + return 0; +} + -- cgit From d70a9e55c3595cf7ee84ca9f3b1d5e272a5e3999 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Sat, 19 Jan 2019 13:42:40 +0100 Subject: use a prime in PRNG --- test/monniaux/mod_int_mat/int_mat.c | 2 +- test/monniaux/quicksort/quicksort.c | 2 +- test/monniaux/quicksort/quicksort_run.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/monniaux/mod_int_mat/int_mat.c b/test/monniaux/mod_int_mat/int_mat.c index 0e51d7ba..fc763811 100644 --- a/test/monniaux/mod_int_mat/int_mat.c +++ b/test/monniaux/mod_int_mat/int_mat.c @@ -191,7 +191,7 @@ void modint_mat_mul7(unsigned m, unsigned n, unsigned p, modint modint_random(void) { static uint64_t next = 1325997111; - next = next * 1103515245 + 12345; + next = next * 1103515249 + 12345; return next % MODULUS; } diff --git a/test/monniaux/quicksort/quicksort.c b/test/monniaux/quicksort/quicksort.c index de04bf2d..4b93ae7b 100644 --- a/test/monniaux/quicksort/quicksort.c +++ b/test/monniaux/quicksort/quicksort.c @@ -24,7 +24,7 @@ void quicksort(data *A, int len) { data data_random(void) { static uint64_t next = 1325997111; - next = next * 1103515245 + 12345; + next = next * 1103515249 + 12345; return next; } diff --git a/test/monniaux/quicksort/quicksort_run.c b/test/monniaux/quicksort/quicksort_run.c index c269cc48..f9e1b871 100644 --- a/test/monniaux/quicksort/quicksort_run.c +++ b/test/monniaux/quicksort/quicksort_run.c @@ -6,7 +6,7 @@ int main (void) { cycle_count_config(); - unsigned len=10000; + unsigned len=30000; data *vec = malloc(sizeof(data) * len); data_vec_random(vec, len); cycle_t quicksort_time = get_cycle(); -- cgit From 0fb339fd9dc30b997c76563271e9b3e3f24db84d Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Sat, 19 Jan 2019 19:17:46 +0100 Subject: some more example --- test/monniaux/heapsort/Makefile | 40 ++++++++++++++++++++++++ test/monniaux/heapsort/heapsort.c | 58 +++++++++++++++++++++++++++++++++++ test/monniaux/heapsort/heapsort.h | 7 +++++ test/monniaux/heapsort/heapsort_run.c | 22 +++++++++++++ test/monniaux/quicksort/Makefile | 2 +- 5 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 test/monniaux/heapsort/Makefile create mode 100644 test/monniaux/heapsort/heapsort.c create mode 100644 test/monniaux/heapsort/heapsort.h create mode 100644 test/monniaux/heapsort/heapsort_run.c (limited to 'test') diff --git a/test/monniaux/heapsort/Makefile b/test/monniaux/heapsort/Makefile new file mode 100644 index 00000000..47dac2bb --- /dev/null +++ b/test/monniaux/heapsort/Makefile @@ -0,0 +1,40 @@ +CFLAGS=-Wall -O3 +K1C_CC=k1-mbr-gcc +K1C_CFLAGS=-Wall -O3 -std=c99 +K1C_CCOMP=../../../ccomp +K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int + +PRODUCTS=heapsort.host heapsort.gcc.k1c.out heapsort.ccomp.k1c.out heapsort.ccomp.k1c.s heapsort.gcc.k1c.s heapsort.gcc.k1c heapsort.ccomp.k1c + +all: $(PRODUCTS) + +%.gcc.k1c.s: %.c + $(K1C_CC) $(K1C_CFLAGS) -S $< -o $@ + +%.gcc.k1c.o: %.gcc.k1c.s + $(K1C_CC) $(K1C_CFLAGS) -c $< -o $@ + +%.ccomp.k1c.s: %.c + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -S $< -o $@ + +%.ccomp.k1c.o: %.ccomp.k1c.s + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -c $< -o $@ + +heapsort.host: heapsort.c heapsort_run.c heapsort.h + $(CC) $(CFLAGS) heapsort.c heapsort_run.c -o $@ + +heapsort.gcc.k1c.s heapsort.ccomp.k1c.s heapsort_run.gcc.k1c.s: heapsort.h + +heapsort.gcc.k1c: heapsort.gcc.k1c.o heapsort_run.gcc.k1c.o + $(K1C_CC) $(K1C_CFLAGS) $+ -o $@ + +heapsort.ccomp.k1c: heapsort.ccomp.k1c.o heapsort_run.gcc.k1c.o + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) $+ -o $@ + +%.k1c.out: %.k1c + k1-cluster --cycle-based -- $< | tee $@ + +clean: + $(RM) -f $(PRODUCTS) heapsort.gcc.k1c.o heapsort.ccomp.k1c.o heapsort_run.gcc.k1c.o heapsort_run.gcc.k1c.s + +.PHONY: clean diff --git a/test/monniaux/heapsort/heapsort.c b/test/monniaux/heapsort/heapsort.c new file mode 100644 index 00000000..550eff4d --- /dev/null +++ b/test/monniaux/heapsort/heapsort.c @@ -0,0 +1,58 @@ +#include "heapsort.h" + +/* Rosetta Code */ +static inline int max (data *a, int n, int i, int j, int k) { + int m = i; + if (j < n && a[j] > a[m]) { + m = j; + } + if (k < n && a[k] > a[m]) { + m = k; + } + return m; +} + +static void downheap (data *a, int n, int i) { + while (1) { + int j = max(a, n, i, 2 * i + 1, 2 * i + 2); + if (j == i) { + break; + } + data t = a[i]; + a[i] = a[j]; + a[j] = t; + i = j; + } +} + +void heapsort (data *a, int n) { + int i; + for (i = (n - 2) / 2; i >= 0; i--) { + downheap(a, n, i); + } + for (i = 0; i < n; i++) { + data t = a[n - i - 1]; + a[n - i - 1] = a[0]; + a[0] = t; + downheap(a, n - i - 1, 0); + } +} + +data data_random(void) { + static uint64_t next = 1325997111; + next = next * 1103515249 + 12345; + return next; +} + +void data_vec_random(data *a, unsigned len) { + for(unsigned i=0; i a[i+1]) return false; + } + return true; +} diff --git a/test/monniaux/heapsort/heapsort.h b/test/monniaux/heapsort/heapsort.h new file mode 100644 index 00000000..247d6773 --- /dev/null +++ b/test/monniaux/heapsort/heapsort.h @@ -0,0 +1,7 @@ +#include +#include + +typedef uint64_t data; +void heapsort(data *A, int len); +void data_vec_random(data *a, unsigned len); +bool data_vec_is_sorted(const data *a, unsigned len); diff --git a/test/monniaux/heapsort/heapsort_run.c b/test/monniaux/heapsort/heapsort_run.c new file mode 100644 index 00000000..76378067 --- /dev/null +++ b/test/monniaux/heapsort/heapsort_run.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include "heapsort.h" +#include "../cycles.h" + +int main (void) { + cycle_count_config(); + unsigned len=30000; + data *vec = malloc(sizeof(data) * len); + data_vec_random(vec, len); + cycle_t heapsort_time = get_cycle(); + heapsort(vec, len); + heapsort_time = get_cycle() - heapsort_time; + printf("sorted=%s\n" + "heapsort_time=%" PRIu64 "\n", + data_vec_is_sorted(vec, len)?"true":"false", + heapsort_time); + free(vec); + return 0; +} + diff --git a/test/monniaux/quicksort/Makefile b/test/monniaux/quicksort/Makefile index 1d8913dd..683fbc90 100644 --- a/test/monniaux/quicksort/Makefile +++ b/test/monniaux/quicksort/Makefile @@ -35,6 +35,6 @@ quicksort.ccomp.k1c: quicksort.ccomp.k1c.o quicksort_run.gcc.k1c.o k1-cluster --cycle-based -- $< | tee $@ clean: - $(RM) -f $(PRODUCTS) quicksort.gcc.k1c.o quicksort.ccomp.k1c.o quicksort_run.gcc.k1c.o + $(RM) -f $(PRODUCTS) quicksort.gcc.k1c.o quicksort.ccomp.k1c.o quicksort_run.gcc.k1c.o quicksort_run.gcc.k1c.s .PHONY: clean -- cgit From 7cc72ab3116899af56f2b898ce20448ab601eacd Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Mon, 21 Jan 2019 21:44:54 +0100 Subject: DES --- test/monniaux/des/des.c | 500 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 500 insertions(+) create mode 100644 test/monniaux/des/des.c (limited to 'test') diff --git a/test/monniaux/des/des.c b/test/monniaux/des/des.c new file mode 100644 index 00000000..e8fae267 --- /dev/null +++ b/test/monniaux/des/des.c @@ -0,0 +1,500 @@ +#include +#include +#include + +typedef unsigned char ubyte; + +#define KEY_LEN 8 +typedef ubyte des_key_t[KEY_LEN]; + +const static ubyte PC1[] = { + 57, 49, 41, 33, 25, 17, 9, + 1, 58, 50, 42, 34, 26, 18, + 10, 2, 59, 51, 43, 35, 27, + 19, 11, 3, 60, 52, 44, 36, + 63, 55, 47, 39, 31, 23, 15, + 7, 62, 54, 46, 38, 30, 22, + 14, 6, 61, 53, 45, 37, 29, + 21, 13, 5, 28, 20, 12, 4 +}; + +const static ubyte PC2[] = { + 14, 17, 11, 24, 1, 5, + 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, + 16, 7, 27, 20, 13, 2, + 41, 52, 31, 37, 47, 55, + 30, 40, 51, 45, 33, 48, + 44, 49, 39, 56, 34, 53, + 46, 42, 50, 36, 29, 32 +}; + +const static ubyte IP[] = { + 58, 50, 42, 34, 26, 18, 10, 2, + 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, + 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, + 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, + 63, 55, 47, 39, 31, 23, 15, 7 +}; + +const static ubyte E[] = { + 32, 1, 2, 3, 4, 5, + 4, 5, 6, 7, 8, 9, + 8, 9, 10, 11, 12, 13, + 12, 13, 14, 15, 16, 17, + 16, 17, 18, 19, 20, 21, + 20, 21, 22, 23, 24, 25, + 24, 25, 26, 27, 28, 29, + 28, 29, 30, 31, 32, 1 +}; + +const static ubyte S[][64] = { + { + 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, + 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, + 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, + 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 + }, + { + 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, + 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, + 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, + 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 + }, + { + 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, + 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, + 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, + 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 + }, + { + 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, + 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, + 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, + 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 + }, + { + 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, + 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, + 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, + 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 + }, + { + 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, + 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, + 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, + 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 + }, + { + 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, + 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, + 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, + 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 + }, + { + 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, + 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, + 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, + 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 + } +}; + +const static ubyte P[] = { + 16, 7, 20, 21, + 29, 12, 28, 17, + 1, 15, 23, 26, + 5, 18, 31, 10, + 2, 8, 24, 14, + 32, 27, 3, 9, + 19, 13, 30, 6, + 22, 11, 4, 25 +}; + +const static ubyte IP2[] = { + 40, 8, 48, 16, 56, 24, 64, 32, + 39, 7, 47, 15, 55, 23, 63, 31, + 38, 6, 46, 14, 54, 22, 62, 30, + 37, 5, 45, 13, 53, 21, 61, 29, + 36, 4, 44, 12, 52, 20, 60, 28, + 35, 3, 43, 11, 51, 19, 59, 27, + 34, 2, 42, 10, 50, 18, 58, 26, + 33, 1, 41, 9, 49, 17, 57, 25 +}; + +const static ubyte SHIFTS[] = { + 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 +}; + +typedef struct { + ubyte *data; + int len; +} String; + +/* + * Transform a single nibble into a hex character + * + * in: a value < 0x10 + * + * returns: the character that represents the nibble + */ +static char toHex(ubyte in) { + if (0x00 <= in && in < 0x0A) { + return '0' + in; + } + if (0x0A <= in && in <= 0x0F) { + return 'A' + in - 0x0A; + } + return 0; +} + +/* + * Convert an array of bytes into a string + * + * ptr: the array of bytes + * len: the number of bytes + * out: a buffer allocated by the caller with enough space for 2*len+1 characters + */ +static void printBytes(const ubyte *ptr, int len, char *out) { + while (len-- > 0) { + *out++ = toHex(*ptr >> 4); + *out++ = toHex(*ptr & 0x0F); + + ptr++; + } + *out = 0; +} + +/* + * Gets the value of a bit in an array of bytes + * + * src: the array of bytes to index + * index: the desired bit to test the value of + * + * returns: the bit at the specified position in the array + */ +static int peekBit(const ubyte *src, int index) { + int cell = index / 8; + int bit = 7 - index % 8; + return (src[cell] & (1 << bit)) != 0; +} + +/* + * Sets the value of a bit in an array of bytes + * + * dst: the array of bits to set a bit in + * index: the position of the bit to set + * value: the value for the bit to set + */ +static void pokeBit(ubyte *dst, int index, int value) { + int cell = index / 8; + int bit = 7 - index % 8; + if (value == 0) { + dst[cell] &= ~(1 << bit); + } else { + dst[cell] |= (1 << bit); + } +} + +/* + * Transforms one array of bytes by shifting the bits the specified number of positions + * + * src: the array to shift bits from + * len: the length of the src array + * times: the number of positions that the bits should be shifted + * dst: a bytes array allocated by the caller to store the shifted values + */ +static void shiftLeft(const ubyte *src, int len, int times, ubyte *dst) { + int i, t; + for (i = 0; i <= len; ++i) { + pokeBit(dst, i, peekBit(src, i)); + } + for (t = 1; t <= times; ++t) { + int temp = peekBit(dst, 0); + for (i = 1; i <= len; ++i) { + pokeBit(dst, i - 1, peekBit(dst, i)); + } + pokeBit(dst, len - 1, temp); + } +} + +/* + * Calculates the sub keys to be used in processing the messages + * + * key: the array of bytes representing the key + * ks: the subkeys that have been allocated by the caller + */ +typedef ubyte subdes_key_t[17][6]; /* 17 sets of 48 bits */ +static void getSubKeys(const des_key_t key, subdes_key_t ks) { + ubyte c[17][7]; /* 56 bits */ + ubyte d[17][4]; /* 28 bits */ + ubyte kp[7]; + int i, j; + + /* intialize */ + memset(c, 0, sizeof(c)); + memset(d, 0, sizeof(d)); + memset(ks, 0, sizeof(subdes_key_t)); + + /* permute 'key' using table PC1 */ + for (i = 0; i < 56; ++i) { + pokeBit(kp, i, peekBit(key, PC1[i] - 1)); + } + + /* split 'kp' in half and process the resulting series of 'c' and 'd' */ + for (i = 0; i < 28; ++i) { + pokeBit(c[0], i, peekBit(kp, i)); + pokeBit(d[0], i, peekBit(kp, i + 28)); + } + + /* shift the components of c and d */ + for (i = 1; i < 17; ++i) { + shiftLeft(c[i - 1], 28, SHIFTS[i - 1], c[i]); + shiftLeft(d[i - 1], 28, SHIFTS[i - 1], d[i]); + } + + /* merge 'd' into 'c' */ + for (i = 1; i < 17; ++i) { + for (j = 28; j < 56; ++j) { + pokeBit(c[i], j, peekBit(d[i], j - 28)); + } + } + + /* form the sub-keys and store them in 'ks' + * permute 'c' using table PC2 */ + for (i = 1; i < 17; ++i) { + for (j = 0; j < 48; ++j) { + pokeBit(ks[i], j, peekBit(c[i], PC2[j] - 1)); + } + } +} + +/* + * Function used in processing the messages + * + * r: an array of bytes to be processed + * ks: one of the subkeys to be used for processing + * sp: output from the processing + */ +static void f(ubyte *r, ubyte *ks, ubyte *sp) { + ubyte er[6]; /* 48 bits */ + ubyte sr[4]; /* 32 bits */ + int i; + + /* initialize */ + memset(er, 0, sizeof(er)); + memset(sr, 0, sizeof(sr)); + + /* permute 'r' using table E */ + for (i = 0; i < 48; ++i) { + pokeBit(er, i, peekBit(r, E[i] - 1)); + } + + /* xor 'er' with 'ks' and store back into 'er' */ + for (i = 0; i < 6; ++i) { + er[i] ^= ks[i]; + } + + /* process 'er' six bits at a time and store resulting four bits in 'sr' */ + for (i = 0; i < 8; ++i) { + int j = i * 6; + int b[6]; + int k, row, col, m, n; + + for (k = 0; k < 6; ++k) { + b[k] = peekBit(er, j + k) != 0 ? 1 : 0; + } + + row = 2 * b[0] + b[5]; + col = 8 * b[1] + 4 * b[2] + 2 * b[3] + b[4]; + m = S[i][row * 16 + col]; /* apply table s */ + n = 1; + + while (m > 0) { + int p = m % 2; + pokeBit(sr, (i + 1) * 4 - n, p == 1); + m /= 2; + n++; + } + } + + /* permute sr using table P */ + for (i = 0; i < 32; ++i) { + pokeBit(sp, i, peekBit(sr, P[i] - 1)); + } +} + +/* + * Processing of block of the message + * + * message: an 8 byte block from the message + * ks: the subkeys to use in processing + * ep: space for an encoded 8 byte block allocated by the caller + */ +static void processMessage(const ubyte *message, subdes_key_t ks, ubyte *ep) { + ubyte left[17][4]; /* 32 bits */ + ubyte right[17][4]; /* 32 bits */ + ubyte mp[8]; /* 64 bits */ + ubyte e[8]; /* 64 bits */ + int i, j; + + /* permute 'message' using table IP */ + for (i = 0; i < 64; ++i) { + pokeBit(mp, i, peekBit(message, IP[i] - 1)); + } + + /* split 'mp' in half and process the resulting series of 'l' and 'r */ + for (i = 0; i < 32; ++i) { + pokeBit(left[0], i, peekBit(mp, i)); + pokeBit(right[0], i, peekBit(mp, i + 32)); + } + for (i = 1; i < 17; ++i) { + ubyte fs[4]; /* 32 bits */ + + memcpy(left[i], right[i - 1], 4); + f(right[i - 1], ks[i], fs); + for (j = 0; j < 4; ++j) { + left[i - 1][j] ^= fs[j]; + } + memcpy(right[i], left[i - 1], 4); + } + + /* amalgamate r[16] and l[16] (in that order) into 'e' */ + for (i = 0; i < 32; ++i) { + pokeBit(e, i, peekBit(right[16], i)); + } + for (i = 32; i < 64; ++i) { + pokeBit(e, i, peekBit(left[16], i - 32)); + } + + /* permute 'e' using table IP2 ad return result as a hex string */ + for (i = 0; i < 64; ++i) { + pokeBit(ep, i, peekBit(e, IP2[i] - 1)); + } +} + +/* + * Encrypts a message using DES + * + * key: the key to use to encrypt the message + * message: the message to be encrypted + * len: the length of the message + * + * returns: a paring of dynamically allocated memory for the encoded message, + * and the length of the encoded message. + * the caller will need to free the memory after use. + */ +String encrypt(const des_key_t key, const ubyte *message, int len) { + String result = { 0, 0 }; + subdes_key_t ks; + ubyte padByte; + int i; + + getSubKeys(key, ks); + + padByte = 8 - len % 8; + result.len = len + padByte; + result.data = (ubyte*)malloc(result.len); + memcpy(result.data, message, len); + memset(&result.data[len], padByte, padByte); + + for (i = 0; i < result.len; i += 8) { + processMessage(&result.data[i], ks, &result.data[i]); + } + + return result; +} + +/* + * Decrypts a message using DES + * + * key: the key to use to decrypt the message + * message: the message to be decrypted + * len: the length of the message + * + * returns: a paring of dynamically allocated memory for the decoded message, + * and the length of the decoded message. + * the caller will need to free the memory after use. + */ +String decrypt(const des_key_t key, const ubyte *message, int len) { + String result = { 0, 0 }; + subdes_key_t ks; + int i, j; + ubyte padByte; + + getSubKeys(key, ks); + /* reverse the subkeys */ + for (i = 1; i < 9; ++i) { + for (j = 0; j < 6; ++j) { + ubyte temp = ks[i][j]; + ks[i][j] = ks[17 - i][j]; + ks[17 - i][j] = temp; + } + } + + result.data = (ubyte*)malloc(len); + memcpy(result.data, message, len); + result.len = len; + for (i = 0; i < result.len; i += 8) { + processMessage(&result.data[i], ks, &result.data[i]); + } + + padByte = result.data[len - 1]; + result.len -= padByte; + return result; +} + +/* + * Convienience method for showing the round trip processing of a message + */ +void driver(const des_key_t key, const ubyte *message, int len) { + String encoded, decoded; + char buffer[128]; + + printBytes(key, KEY_LEN, buffer); + printf("Key : %s\n", buffer); + + printBytes(message, len, buffer); + printf("Message : %s\n", buffer); + + encoded = encrypt(key, message, len); + printBytes(encoded.data, encoded.len, buffer); + printf("Encoded : %s\n", buffer); + + decoded = decrypt(key, encoded.data, encoded.len); + printBytes(decoded.data, decoded.len, buffer); + printf("Decoded : %s\n\n", buffer); + + /* release allocated memory */ + if (encoded.len > 0) { + free(encoded.data); + encoded.data = 0; + } + if (decoded.len > 0) { + free(decoded.data); + decoded.data = 0; + } +} + +int main() { + const des_key_t keys[] = { + {0x13, 0x34, 0x57, 0x79, 0x9B, 0xBC, 0xDF, 0xF1}, + {0x0E, 0x32, 0x92, 0x32, 0xEA, 0x6D, 0x0D, 0x73}, + {0x0E, 0x32, 0x92, 0x32, 0xEA, 0x6D, 0x0D, 0x73} + }; + const ubyte message1[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }; + const ubyte message2[] = { 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87 }; + const ubyte message3[] = { 0x59, 0x6F, 0x75, 0x72, 0x20, 0x6C, 0x69, 0x70, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x73, 0x6D, 0x6F, 0x6F, 0x74, 0x68, 0x65, 0x72, 0x20, 0x74, 0x68, 0x61, 0x6E, 0x20, 0x76, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x0D, 0x0A }; + int len; + + len = sizeof(message1) / sizeof(ubyte); + driver(keys[0], message1, len); + + len = sizeof(message2) / sizeof(ubyte); + driver(keys[1], message2, len); + + len = sizeof(message3) / sizeof(ubyte); + driver(keys[2], message3, len); +} -- cgit From db6e7fb5263d3b61abc976cb9d3e4250695b3f5e Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Mon, 21 Jan 2019 22:11:34 +0100 Subject: AES --- test/monniaux/tiny-AES-c/Makefile | 61 ++++ test/monniaux/tiny-AES-c/README.md | 80 +++++ test/monniaux/tiny-AES-c/aes.c | 571 +++++++++++++++++++++++++++++++++ test/monniaux/tiny-AES-c/aes.h | 90 ++++++ test/monniaux/tiny-AES-c/aes.hpp | 12 + test/monniaux/tiny-AES-c/library.json | 13 + test/monniaux/tiny-AES-c/test.c | 316 ++++++++++++++++++ test/monniaux/tiny-AES-c/unlicense.txt | 24 ++ 8 files changed, 1167 insertions(+) create mode 100644 test/monniaux/tiny-AES-c/Makefile create mode 100644 test/monniaux/tiny-AES-c/README.md create mode 100644 test/monniaux/tiny-AES-c/aes.c create mode 100644 test/monniaux/tiny-AES-c/aes.h create mode 100644 test/monniaux/tiny-AES-c/aes.hpp create mode 100644 test/monniaux/tiny-AES-c/library.json create mode 100644 test/monniaux/tiny-AES-c/test.c create mode 100644 test/monniaux/tiny-AES-c/unlicense.txt (limited to 'test') diff --git a/test/monniaux/tiny-AES-c/Makefile b/test/monniaux/tiny-AES-c/Makefile new file mode 100644 index 00000000..7b9122eb --- /dev/null +++ b/test/monniaux/tiny-AES-c/Makefile @@ -0,0 +1,61 @@ +#CC = avr-gcc +#CFLAGS = -Wall -mmcu=atmega16 -Os -Wl,-Map,test.map +#OBJCOPY = avr-objcopy +CC = ../../../ccomp +LD = ../../../ccomp +AR = ar +ARFLAGS = rcs +CFLAGS = -Wall -O3 -c -D__thread= -D__int128=int +LDFLAGS = -Wall -O3 -Wl,-Map,test.map +ifdef AES192 +CFLAGS += -DAES192=1 +endif +ifdef AES256 +CFLAGS += -DAES256=1 +endif + +OBJCOPYFLAGS = -j .text -O ihex +OBJCOPY = objcopy + +# include path to AVR library +INCLUDE_PATH = /usr/lib/avr/include +# splint static check +SPLINT = splint test.c aes.c -I$(INCLUDE_PATH) +charindex -unrecog + +default: test.elf + +.SILENT: +.PHONY: lint clean + +test.hex : test.elf + echo copy object-code to new image and format in hex + $(OBJCOPY) ${OBJCOPYFLAGS} $< $@ + +test.o : test.c aes.h aes.o + echo [CC] $@ $(CFLAGS) + $(CC) $(CFLAGS) -o $@ $< + +aes.o : aes.c aes.h + echo [CC] $@ $(CFLAGS) + $(CC) $(CFLAGS) -o $@ $< + +test.elf : aes.o test.o + echo [LD] $@ + $(LD) $(LDFLAGS) -o $@ $^ + +aes.a : aes.o + echo [AR] $@ + $(AR) $(ARFLAGS) $@ $^ + +lib : aes.a + +clean: + rm -f *.OBJ *.LST *.o *.gch *.out *.hex *.map *.elf *.a + +test: + make clean && make && ./test.elf + make clean && make AES192=1 && ./test.elf + make clean && make AES256=1 && ./test.elf + +lint: + $(call SPLINT) diff --git a/test/monniaux/tiny-AES-c/README.md b/test/monniaux/tiny-AES-c/README.md new file mode 100644 index 00000000..e06cfdff --- /dev/null +++ b/test/monniaux/tiny-AES-c/README.md @@ -0,0 +1,80 @@ +### Tiny AES in C + +This is a small and portable implementation of the AES [ECB](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_Codebook_.28ECB.29), [CTR](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_.28CTR.29) and [CBC](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Block_Chaining_.28CBC.29) encryption algorithms written in C. + +You can override the default key-size of 128 bit with 192 or 256 bit by defining the symbols AES192 or AES256 in `aes.h`. + +The API is very simple and looks like this (I am using C99 ``-style annotated types): + +```C +/* Initialize context calling one of: */ +void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key); +void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv); + +/* ... or reset IV at random point: */ +void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv); + +/* Then start encrypting and decrypting with the functions below: */ +void AES_ECB_encrypt(struct AES_ctx* ctx, uint8_t* buf); +void AES_ECB_decrypt(struct AES_ctx* ctx, uint8_t* buf); + +void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length); +void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length); + +/* Same function for encrypting as for decrypting in CTR mode */ +void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length); +``` + +Note: + * No padding is provided so for CBC and ECB all buffers should be multiples of 16 bytes. For padding [PKCS7](https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7) is recommendable. + * ECB mode is considered unsafe for most uses and is not implemented in streaming mode. If you need this mode, call the function for every block of 16 bytes you need encrypted. See [wikipedia's article on ECB](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_Codebook_(ECB)) for more details. + +You can choose to use any or all of the modes-of-operations, by defining the symbols CBC, CTR or ECB. See the header file for clarification. + +C++ users should `#include` [aes.hpp](https://github.com/kokke/tiny-AES-c/blob/master/aes.hpp) instead of [aes.h](https://github.com/kokke/tiny-AES-c/blob/master/aes.h) + +There is no built-in error checking or protection from out-of-bounds memory access errors as a result of malicious input. + +The module uses less than 200 bytes of RAM and 1-2K ROM when compiled for ARM, but YMMV depending on which modes are enabled. + +It is one of the smallest implementations in C I've seen yet, but do contact me if you know of something smaller (or have improvements to the code here). + +I've successfully used the code on 64bit x86, 32bit ARM and 8 bit AVR platforms. + + +GCC size output when only CTR mode is compiled for ARM: + + $ arm-none-eabi-gcc -Os -DCBC=0 -DECB=0 -DCTR=1 -c aes.c + $ size aes.o + text data bss dec hex filename + 1203 0 0 1203 4b3 aes.o + +.. and when compiling for the THUMB instruction set, we end up just below 1K in code size. + + $ arm-none-eabi-gcc -Os -mthumb -DCBC=0 -DECB=0 -DCTR=1 -c aes.c + $ size aes.o + text data bss dec hex filename + 955 0 0 955 3bb aes.o + + +I am using the Free Software Foundation, ARM GCC compiler: + + $ arm-none-eabi-gcc --version + arm-none-eabi-gcc (4.8.4-1+11-1) 4.8.4 20141219 (release) + Copyright (C) 2013 Free Software Foundation, Inc. + This is free software; see the source for copying conditions. There is NO + warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + + +This implementation is verified against the data in: + +[National Institute of Standards and Technology Special Publication 800-38A 2001 ED](http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf) Appendix F: Example Vectors for Modes of Operation of the AES. + +The other appendices in the document are valuable for implementation details on e.g. padding, generation of IVs and nonces in CTR-mode etc. + + +A heartfelt thank-you to all the nice people out there who have contributed to this project. + + +All material in this repository is in the public domain. diff --git a/test/monniaux/tiny-AES-c/aes.c b/test/monniaux/tiny-AES-c/aes.c new file mode 100644 index 00000000..f0f9ac90 --- /dev/null +++ b/test/monniaux/tiny-AES-c/aes.c @@ -0,0 +1,571 @@ +/* + +This is an implementation of the AES algorithm, specifically ECB, CTR and CBC mode. +Block size can be chosen in aes.h - available choices are AES128, AES192, AES256. + +The implementation is verified against the test vectors in: + National Institute of Standards and Technology Special Publication 800-38A 2001 ED + +ECB-AES128 +---------- + + plain-text: + 6bc1bee22e409f96e93d7e117393172a + ae2d8a571e03ac9c9eb76fac45af8e51 + 30c81c46a35ce411e5fbc1191a0a52ef + f69f2445df4f9b17ad2b417be66c3710 + + key: + 2b7e151628aed2a6abf7158809cf4f3c + + resulting cipher + 3ad77bb40d7a3660a89ecaf32466ef97 + f5d3d58503b9699de785895a96fdbaaf + 43b1cd7f598ece23881b00e3ed030688 + 7b0c785e27e8ad3f8223207104725dd4 + + +NOTE: String length must be evenly divisible by 16byte (str_len % 16 == 0) + You should pad the end of the string with zeros if this is not the case. + For AES192/256 the key size is proportionally larger. + +*/ + + +/*****************************************************************************/ +/* Includes: */ +/*****************************************************************************/ +#include +#include // CBC mode, for memset +#include "aes.h" + +/*****************************************************************************/ +/* Defines: */ +/*****************************************************************************/ +// The number of columns comprising a state in AES. This is a constant in AES. Value=4 +#define Nb 4 + +#if defined(AES256) && (AES256 == 1) + #define Nk 8 + #define Nr 14 +#elif defined(AES192) && (AES192 == 1) + #define Nk 6 + #define Nr 12 +#else + #define Nk 4 // The number of 32 bit words in a key. + #define Nr 10 // The number of rounds in AES Cipher. +#endif + +// jcallan@github points out that declaring Multiply as a function +// reduces code size considerably with the Keil ARM compiler. +// See this link for more information: https://github.com/kokke/tiny-AES-C/pull/3 +#ifndef MULTIPLY_AS_A_FUNCTION + #define MULTIPLY_AS_A_FUNCTION 0 +#endif + + + + +/*****************************************************************************/ +/* Private variables: */ +/*****************************************************************************/ +// state - array holding the intermediate results during decryption. +typedef uint8_t state_t[4][4]; + + + +// The lookup-tables are marked const so they can be placed in read-only storage instead of RAM +// The numbers below can be computed dynamically trading ROM for RAM - +// This can be useful in (embedded) bootloader applications, where ROM is often limited. +static const uint8_t sbox[256] = { + //0 1 2 3 4 5 6 7 8 9 A B C D E F + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, + 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, + 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, + 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, + 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, + 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, + 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, + 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, + 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, + 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; + +static const uint8_t rsbox[256] = { + 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, + 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, + 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, + 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, + 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, + 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, + 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06, + 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, + 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, + 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, + 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, + 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, + 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, + 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, + 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, + 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d }; + +// The round constant word array, Rcon[i], contains the values given by +// x to the power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8) +static const uint8_t Rcon[11] = { + 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 }; + +/* + * Jordan Goulder points out in PR #12 (https://github.com/kokke/tiny-AES-C/pull/12), + * that you can remove most of the elements in the Rcon array, because they are unused. + * + * From Wikipedia's article on the Rijndael key schedule @ https://en.wikipedia.org/wiki/Rijndael_key_schedule#Rcon + * + * "Only the first some of these constants are actually used – up to rcon[10] for AES-128 (as 11 round keys are needed), + * up to rcon[8] for AES-192, up to rcon[7] for AES-256. rcon[0] is not used in AES algorithm." + */ + + +/*****************************************************************************/ +/* Private functions: */ +/*****************************************************************************/ +/* +static uint8_t getSBoxValue(uint8_t num) +{ + return sbox[num]; +} +*/ +#define getSBoxValue(num) (sbox[(num)]) +/* +static uint8_t getSBoxInvert(uint8_t num) +{ + return rsbox[num]; +} +*/ +#define getSBoxInvert(num) (rsbox[(num)]) + +// This function produces Nb(Nr+1) round keys. The round keys are used in each round to decrypt the states. +static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) +{ + unsigned i, j, k; + uint8_t tempa[4]; // Used for the column/row operations + + // The first round key is the key itself. + for (i = 0; i < Nk; ++i) + { + RoundKey[(i * 4) + 0] = Key[(i * 4) + 0]; + RoundKey[(i * 4) + 1] = Key[(i * 4) + 1]; + RoundKey[(i * 4) + 2] = Key[(i * 4) + 2]; + RoundKey[(i * 4) + 3] = Key[(i * 4) + 3]; + } + + // All other round keys are found from the previous round keys. + for (i = Nk; i < Nb * (Nr + 1); ++i) + { + { + k = (i - 1) * 4; + tempa[0]=RoundKey[k + 0]; + tempa[1]=RoundKey[k + 1]; + tempa[2]=RoundKey[k + 2]; + tempa[3]=RoundKey[k + 3]; + + } + + if (i % Nk == 0) + { + // This function shifts the 4 bytes in a word to the left once. + // [a0,a1,a2,a3] becomes [a1,a2,a3,a0] + + // Function RotWord() + { + const uint8_t u8tmp = tempa[0]; + tempa[0] = tempa[1]; + tempa[1] = tempa[2]; + tempa[2] = tempa[3]; + tempa[3] = u8tmp; + } + + // SubWord() is a function that takes a four-byte input word and + // applies the S-box to each of the four bytes to produce an output word. + + // Function Subword() + { + tempa[0] = getSBoxValue(tempa[0]); + tempa[1] = getSBoxValue(tempa[1]); + tempa[2] = getSBoxValue(tempa[2]); + tempa[3] = getSBoxValue(tempa[3]); + } + + tempa[0] = tempa[0] ^ Rcon[i/Nk]; + } +#if defined(AES256) && (AES256 == 1) + if (i % Nk == 4) + { + // Function Subword() + { + tempa[0] = getSBoxValue(tempa[0]); + tempa[1] = getSBoxValue(tempa[1]); + tempa[2] = getSBoxValue(tempa[2]); + tempa[3] = getSBoxValue(tempa[3]); + } + } +#endif + j = i * 4; k=(i - Nk) * 4; + RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0]; + RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1]; + RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2]; + RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3]; + } +} + +void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key) +{ + KeyExpansion(ctx->RoundKey, key); +} +#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1)) +void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv) +{ + KeyExpansion(ctx->RoundKey, key); + memcpy (ctx->Iv, iv, AES_BLOCKLEN); +} +void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv) +{ + memcpy (ctx->Iv, iv, AES_BLOCKLEN); +} +#endif + +// This function adds the round key to state. +// The round key is added to the state by an XOR function. +static void AddRoundKey(uint8_t round,state_t* state,uint8_t* RoundKey) +{ + uint8_t i,j; + for (i = 0; i < 4; ++i) + { + for (j = 0; j < 4; ++j) + { + (*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j]; + } + } +} + +// The SubBytes Function Substitutes the values in the +// state matrix with values in an S-box. +static void SubBytes(state_t* state) +{ + uint8_t i, j; + for (i = 0; i < 4; ++i) + { + for (j = 0; j < 4; ++j) + { + (*state)[j][i] = getSBoxValue((*state)[j][i]); + } + } +} + +// The ShiftRows() function shifts the rows in the state to the left. +// Each row is shifted with different offset. +// Offset = Row number. So the first row is not shifted. +static void ShiftRows(state_t* state) +{ + uint8_t temp; + + // Rotate first row 1 columns to left + temp = (*state)[0][1]; + (*state)[0][1] = (*state)[1][1]; + (*state)[1][1] = (*state)[2][1]; + (*state)[2][1] = (*state)[3][1]; + (*state)[3][1] = temp; + + // Rotate second row 2 columns to left + temp = (*state)[0][2]; + (*state)[0][2] = (*state)[2][2]; + (*state)[2][2] = temp; + + temp = (*state)[1][2]; + (*state)[1][2] = (*state)[3][2]; + (*state)[3][2] = temp; + + // Rotate third row 3 columns to left + temp = (*state)[0][3]; + (*state)[0][3] = (*state)[3][3]; + (*state)[3][3] = (*state)[2][3]; + (*state)[2][3] = (*state)[1][3]; + (*state)[1][3] = temp; +} + +static uint8_t xtime(uint8_t x) +{ + return ((x<<1) ^ (((x>>7) & 1) * 0x1b)); +} + +// MixColumns function mixes the columns of the state matrix +static void MixColumns(state_t* state) +{ + uint8_t i; + uint8_t Tmp, Tm, t; + for (i = 0; i < 4; ++i) + { + t = (*state)[i][0]; + Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3] ; + Tm = (*state)[i][0] ^ (*state)[i][1] ; Tm = xtime(Tm); (*state)[i][0] ^= Tm ^ Tmp ; + Tm = (*state)[i][1] ^ (*state)[i][2] ; Tm = xtime(Tm); (*state)[i][1] ^= Tm ^ Tmp ; + Tm = (*state)[i][2] ^ (*state)[i][3] ; Tm = xtime(Tm); (*state)[i][2] ^= Tm ^ Tmp ; + Tm = (*state)[i][3] ^ t ; Tm = xtime(Tm); (*state)[i][3] ^= Tm ^ Tmp ; + } +} + +// Multiply is used to multiply numbers in the field GF(2^8) +// Note: The last call to xtime() is unneeded, but often ends up generating a smaller binary +// The compiler seems to be able to vectorize the operation better this way. +// See https://github.com/kokke/tiny-AES-c/pull/34 +#if MULTIPLY_AS_A_FUNCTION +static uint8_t Multiply(uint8_t x, uint8_t y) +{ + return (((y & 1) * x) ^ + ((y>>1 & 1) * xtime(x)) ^ + ((y>>2 & 1) * xtime(xtime(x))) ^ + ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ + ((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))); /* this last call to xtime() can be omitted */ + } +#else +#define Multiply(x, y) \ + ( ((y & 1) * x) ^ \ + ((y>>1 & 1) * xtime(x)) ^ \ + ((y>>2 & 1) * xtime(xtime(x))) ^ \ + ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ \ + ((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))) \ + +#endif + +// MixColumns function mixes the columns of the state matrix. +// The method used to multiply may be difficult to understand for the inexperienced. +// Please use the references to gain more information. +static void InvMixColumns(state_t* state) +{ + int i; + uint8_t a, b, c, d; + for (i = 0; i < 4; ++i) + { + a = (*state)[i][0]; + b = (*state)[i][1]; + c = (*state)[i][2]; + d = (*state)[i][3]; + + (*state)[i][0] = Multiply(a, 0x0e) ^ Multiply(b, 0x0b) ^ Multiply(c, 0x0d) ^ Multiply(d, 0x09); + (*state)[i][1] = Multiply(a, 0x09) ^ Multiply(b, 0x0e) ^ Multiply(c, 0x0b) ^ Multiply(d, 0x0d); + (*state)[i][2] = Multiply(a, 0x0d) ^ Multiply(b, 0x09) ^ Multiply(c, 0x0e) ^ Multiply(d, 0x0b); + (*state)[i][3] = Multiply(a, 0x0b) ^ Multiply(b, 0x0d) ^ Multiply(c, 0x09) ^ Multiply(d, 0x0e); + } +} + + +// The SubBytes Function Substitutes the values in the +// state matrix with values in an S-box. +static void InvSubBytes(state_t* state) +{ + uint8_t i, j; + for (i = 0; i < 4; ++i) + { + for (j = 0; j < 4; ++j) + { + (*state)[j][i] = getSBoxInvert((*state)[j][i]); + } + } +} + +static void InvShiftRows(state_t* state) +{ + uint8_t temp; + + // Rotate first row 1 columns to right + temp = (*state)[3][1]; + (*state)[3][1] = (*state)[2][1]; + (*state)[2][1] = (*state)[1][1]; + (*state)[1][1] = (*state)[0][1]; + (*state)[0][1] = temp; + + // Rotate second row 2 columns to right + temp = (*state)[0][2]; + (*state)[0][2] = (*state)[2][2]; + (*state)[2][2] = temp; + + temp = (*state)[1][2]; + (*state)[1][2] = (*state)[3][2]; + (*state)[3][2] = temp; + + // Rotate third row 3 columns to right + temp = (*state)[0][3]; + (*state)[0][3] = (*state)[1][3]; + (*state)[1][3] = (*state)[2][3]; + (*state)[2][3] = (*state)[3][3]; + (*state)[3][3] = temp; +} + + +// Cipher is the main function that encrypts the PlainText. +static void Cipher(state_t* state, uint8_t* RoundKey) +{ + uint8_t round = 0; + + // Add the First round key to the state before starting the rounds. + AddRoundKey(0, state, RoundKey); + + // There will be Nr rounds. + // The first Nr-1 rounds are identical. + // These Nr-1 rounds are executed in the loop below. + for (round = 1; round < Nr; ++round) + { + SubBytes(state); + ShiftRows(state); + MixColumns(state); + AddRoundKey(round, state, RoundKey); + } + + // The last round is given below. + // The MixColumns function is not here in the last round. + SubBytes(state); + ShiftRows(state); + AddRoundKey(Nr, state, RoundKey); +} + +#if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1) +static void InvCipher(state_t* state,uint8_t* RoundKey) +{ + uint8_t round = 0; + + // Add the First round key to the state before starting the rounds. + AddRoundKey(Nr, state, RoundKey); + + // There will be Nr rounds. + // The first Nr-1 rounds are identical. + // These Nr-1 rounds are executed in the loop below. + for (round = (Nr - 1); round > 0; --round) + { + InvShiftRows(state); + InvSubBytes(state); + AddRoundKey(round, state, RoundKey); + InvMixColumns(state); + } + + // The last round is given below. + // The MixColumns function is not here in the last round. + InvShiftRows(state); + InvSubBytes(state); + AddRoundKey(0, state, RoundKey); +} +#endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1) + +/*****************************************************************************/ +/* Public functions: */ +/*****************************************************************************/ +#if defined(ECB) && (ECB == 1) + + +void AES_ECB_encrypt(struct AES_ctx *ctx, uint8_t* buf) +{ + // The next function call encrypts the PlainText with the Key using AES algorithm. + Cipher((state_t*)buf, ctx->RoundKey); +} + +void AES_ECB_decrypt(struct AES_ctx* ctx, uint8_t* buf) +{ + // The next function call decrypts the PlainText with the Key using AES algorithm. + InvCipher((state_t*)buf, ctx->RoundKey); +} + + +#endif // #if defined(ECB) && (ECB == 1) + + + + + +#if defined(CBC) && (CBC == 1) + + +static void XorWithIv(uint8_t* buf, uint8_t* Iv) +{ + uint8_t i; + for (i = 0; i < AES_BLOCKLEN; ++i) // The block in AES is always 128bit no matter the key size + { + buf[i] ^= Iv[i]; + } +} + +void AES_CBC_encrypt_buffer(struct AES_ctx *ctx,uint8_t* buf, uint32_t length) +{ + uintptr_t i; + uint8_t *Iv = ctx->Iv; + for (i = 0; i < length; i += AES_BLOCKLEN) + { + XorWithIv(buf, Iv); + Cipher((state_t*)buf, ctx->RoundKey); + Iv = buf; + buf += AES_BLOCKLEN; + //printf("Step %d - %d", i/16, i); + } + /* store Iv in ctx for next call */ + memcpy(ctx->Iv, Iv, AES_BLOCKLEN); +} + +void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length) +{ + uintptr_t i; + uint8_t storeNextIv[AES_BLOCKLEN]; + for (i = 0; i < length; i += AES_BLOCKLEN) + { + memcpy(storeNextIv, buf, AES_BLOCKLEN); + InvCipher((state_t*)buf, ctx->RoundKey); + XorWithIv(buf, ctx->Iv); + memcpy(ctx->Iv, storeNextIv, AES_BLOCKLEN); + buf += AES_BLOCKLEN; + } + +} + +#endif // #if defined(CBC) && (CBC == 1) + + + +#if defined(CTR) && (CTR == 1) + +/* Symmetrical operation: same function for encrypting as for decrypting. Note any IV/nonce should never be reused with the same key */ +void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length) +{ + uint8_t buffer[AES_BLOCKLEN]; + + unsigned i; + int bi; + for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi) + { + if (bi == AES_BLOCKLEN) /* we need to regen xor compliment in buffer */ + { + + memcpy(buffer, ctx->Iv, AES_BLOCKLEN); + Cipher((state_t*)buffer,ctx->RoundKey); + + /* Increment Iv and handle overflow */ + for (bi = (AES_BLOCKLEN - 1); bi >= 0; --bi) + { + /* inc will owerflow */ + if (ctx->Iv[bi] == 255) + { + ctx->Iv[bi] = 0; + continue; + } + ctx->Iv[bi] += 1; + break; + } + bi = 0; + } + + buf[i] = (buf[i] ^ buffer[bi]); + } +} + +#endif // #if defined(CTR) && (CTR == 1) + diff --git a/test/monniaux/tiny-AES-c/aes.h b/test/monniaux/tiny-AES-c/aes.h new file mode 100644 index 00000000..1daab47b --- /dev/null +++ b/test/monniaux/tiny-AES-c/aes.h @@ -0,0 +1,90 @@ +#ifndef _AES_H_ +#define _AES_H_ + +#include + +// #define the macros below to 1/0 to enable/disable the mode of operation. +// +// CBC enables AES encryption in CBC-mode of operation. +// CTR enables encryption in counter-mode. +// ECB enables the basic ECB 16-byte block algorithm. All can be enabled simultaneously. + +// The #ifndef-guard allows it to be configured before #include'ing or at compile time. +#ifndef CBC + #define CBC 1 +#endif + +#ifndef ECB + #define ECB 1 +#endif + +#ifndef CTR + #define CTR 1 +#endif + + +#define AES128 1 +//#define AES192 1 +//#define AES256 1 + +#define AES_BLOCKLEN 16 //Block length in bytes AES is 128b block only + +#if defined(AES256) && (AES256 == 1) + #define AES_KEYLEN 32 + #define AES_keyExpSize 240 +#elif defined(AES192) && (AES192 == 1) + #define AES_KEYLEN 24 + #define AES_keyExpSize 208 +#else + #define AES_KEYLEN 16 // Key length in bytes + #define AES_keyExpSize 176 +#endif + +struct AES_ctx +{ + uint8_t RoundKey[AES_keyExpSize]; +#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1)) + uint8_t Iv[AES_BLOCKLEN]; +#endif +}; + +void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key); +#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1)) +void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv); +void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv); +#endif + +#if defined(ECB) && (ECB == 1) +// buffer size is exactly AES_BLOCKLEN bytes; +// you need only AES_init_ctx as IV is not used in ECB +// NB: ECB is considered insecure for most uses +void AES_ECB_encrypt(struct AES_ctx* ctx, uint8_t* buf); +void AES_ECB_decrypt(struct AES_ctx* ctx, uint8_t* buf); + +#endif // #if defined(ECB) && (ECB == !) + + +#if defined(CBC) && (CBC == 1) +// buffer size MUST be mutile of AES_BLOCKLEN; +// Suggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme +// NOTES: you need to set IV in ctx via AES_init_ctx_iv() or AES_ctx_set_iv() +// no IV should ever be reused with the same key +void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length); +void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length); + +#endif // #if defined(CBC) && (CBC == 1) + + +#if defined(CTR) && (CTR == 1) + +// Same function for encrypting as for decrypting. +// IV is incremented for every block, and used after encryption as XOR-compliment for output +// Suggesting https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme +// NOTES: you need to set IV in ctx with AES_init_ctx_iv() or AES_ctx_set_iv() +// no IV should ever be reused with the same key +void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length); + +#endif // #if defined(CTR) && (CTR == 1) + + +#endif //_AES_H_ diff --git a/test/monniaux/tiny-AES-c/aes.hpp b/test/monniaux/tiny-AES-c/aes.hpp new file mode 100644 index 00000000..ade16425 --- /dev/null +++ b/test/monniaux/tiny-AES-c/aes.hpp @@ -0,0 +1,12 @@ +#ifndef _AES_HPP_ +#define _AES_HPP_ + +#ifndef __cplusplus +#error Do not include the hpp header in a c project! +#endif //__cplusplus + +extern "C" { +#include "aes.h" +} + +#endif //_AES_HPP_ diff --git a/test/monniaux/tiny-AES-c/library.json b/test/monniaux/tiny-AES-c/library.json new file mode 100644 index 00000000..d7abe89a --- /dev/null +++ b/test/monniaux/tiny-AES-c/library.json @@ -0,0 +1,13 @@ +{ + "name": "tiny-AES-c", + "keywords": "cryptography, aes", + "description": "Small portable AES128/192/256 in C", + "repository": + { + "type": "git", + "url": "https://github.com/kokke/tiny-AES-c.git" + }, + "frameworks": "*", + "platforms": "*", + "examples": "test.c" +} diff --git a/test/monniaux/tiny-AES-c/test.c b/test/monniaux/tiny-AES-c/test.c new file mode 100644 index 00000000..67962831 --- /dev/null +++ b/test/monniaux/tiny-AES-c/test.c @@ -0,0 +1,316 @@ +#include +#include +#include + +// Enable ECB, CTR and CBC mode. Note this can be done before including aes.h or at compile-time. +// E.g. with GCC by using the -D flag: gcc -c aes.c -DCBC=0 -DCTR=1 -DECB=1 +#define CBC 1 +#define CTR 1 +#define ECB 1 + +#include "aes.h" + + +static void phex(uint8_t* str); +static int test_encrypt_cbc(void); +static int test_decrypt_cbc(void); +static int test_encrypt_ctr(void); +static int test_decrypt_ctr(void); +static int test_encrypt_ecb(void); +static int test_decrypt_ecb(void); +static void test_encrypt_ecb_verbose(void); + + +int main(void) +{ + int exit; + +#if defined(AES256) + printf("\nTesting AES256\n\n"); +#elif defined(AES192) + printf("\nTesting AES192\n\n"); +#elif defined(AES128) + printf("\nTesting AES128\n\n"); +#else + printf("You need to specify a symbol between AES128, AES192 or AES256. Exiting"); + return 0; +#endif + + exit = test_encrypt_cbc() + test_decrypt_cbc() + + test_encrypt_ctr() + test_decrypt_ctr() + + test_decrypt_ecb() + test_encrypt_ecb(); + test_encrypt_ecb_verbose(); + + return exit; +} + + +// prints string as hex +static void phex(uint8_t* str) +{ + +#if defined(AES256) + uint8_t len = 32; +#elif defined(AES192) + uint8_t len = 24; +#elif defined(AES128) + uint8_t len = 16; +#endif + + unsigned char i; + for (i = 0; i < len; ++i) + printf("%.2x", str[i]); + printf("\n"); +} + +static void test_encrypt_ecb_verbose(void) +{ + // Example of more verbose verification + + uint8_t i; + + // 128bit key + uint8_t key[16] = { (uint8_t) 0x2b, (uint8_t) 0x7e, (uint8_t) 0x15, (uint8_t) 0x16, (uint8_t) 0x28, (uint8_t) 0xae, (uint8_t) 0xd2, (uint8_t) 0xa6, (uint8_t) 0xab, (uint8_t) 0xf7, (uint8_t) 0x15, (uint8_t) 0x88, (uint8_t) 0x09, (uint8_t) 0xcf, (uint8_t) 0x4f, (uint8_t) 0x3c }; + // 512bit text + uint8_t plain_text[64] = { (uint8_t) 0x6b, (uint8_t) 0xc1, (uint8_t) 0xbe, (uint8_t) 0xe2, (uint8_t) 0x2e, (uint8_t) 0x40, (uint8_t) 0x9f, (uint8_t) 0x96, (uint8_t) 0xe9, (uint8_t) 0x3d, (uint8_t) 0x7e, (uint8_t) 0x11, (uint8_t) 0x73, (uint8_t) 0x93, (uint8_t) 0x17, (uint8_t) 0x2a, + (uint8_t) 0xae, (uint8_t) 0x2d, (uint8_t) 0x8a, (uint8_t) 0x57, (uint8_t) 0x1e, (uint8_t) 0x03, (uint8_t) 0xac, (uint8_t) 0x9c, (uint8_t) 0x9e, (uint8_t) 0xb7, (uint8_t) 0x6f, (uint8_t) 0xac, (uint8_t) 0x45, (uint8_t) 0xaf, (uint8_t) 0x8e, (uint8_t) 0x51, + (uint8_t) 0x30, (uint8_t) 0xc8, (uint8_t) 0x1c, (uint8_t) 0x46, (uint8_t) 0xa3, (uint8_t) 0x5c, (uint8_t) 0xe4, (uint8_t) 0x11, (uint8_t) 0xe5, (uint8_t) 0xfb, (uint8_t) 0xc1, (uint8_t) 0x19, (uint8_t) 0x1a, (uint8_t) 0x0a, (uint8_t) 0x52, (uint8_t) 0xef, + (uint8_t) 0xf6, (uint8_t) 0x9f, (uint8_t) 0x24, (uint8_t) 0x45, (uint8_t) 0xdf, (uint8_t) 0x4f, (uint8_t) 0x9b, (uint8_t) 0x17, (uint8_t) 0xad, (uint8_t) 0x2b, (uint8_t) 0x41, (uint8_t) 0x7b, (uint8_t) 0xe6, (uint8_t) 0x6c, (uint8_t) 0x37, (uint8_t) 0x10 }; + + // print text to encrypt, key and IV + printf("ECB encrypt verbose:\n\n"); + printf("plain text:\n"); + for (i = (uint8_t) 0; i < (uint8_t) 4; ++i) + { + phex(plain_text + i * (uint8_t) 16); + } + printf("\n"); + + printf("key:\n"); + phex(key); + printf("\n"); + + // print the resulting cipher as 4 x 16 byte strings + printf("ciphertext:\n"); + + struct AES_ctx ctx; + AES_init_ctx(&ctx, key); + + for (i = 0; i < 4; ++i) + { + AES_ECB_encrypt(&ctx, plain_text + (i * 16)); + phex(plain_text + (i * 16)); + } + printf("\n"); +} + + +static int test_encrypt_ecb(void) +{ +#if defined(AES256) + uint8_t key[] = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, + 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 }; + uint8_t out[] = { 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c, 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8 }; +#elif defined(AES192) + uint8_t key[] = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, + 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b }; + uint8_t out[] = { 0xbd, 0x33, 0x4f, 0x1d, 0x6e, 0x45, 0xf2, 0x5f, 0xf7, 0x12, 0xa2, 0x14, 0x57, 0x1f, 0xa5, 0xcc }; +#elif defined(AES128) + uint8_t key[] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; + uint8_t out[] = { 0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60, 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97 }; +#endif + + uint8_t in[] = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a }; + struct AES_ctx ctx; + + AES_init_ctx(&ctx, key); + AES_ECB_encrypt(&ctx, in); + + printf("ECB encrypt: "); + + if (0 == memcmp((char*) out, (char*) in, 16)) { + printf("SUCCESS!\n"); + return(0); + } else { + printf("FAILURE!\n"); + return(1); + } +} + +static int test_decrypt_cbc(void) +{ + +#if defined(AES256) + uint8_t key[] = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, + 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 }; + uint8_t in[] = { 0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba, 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6, + 0x9c, 0xfc, 0x4e, 0x96, 0x7e, 0xdb, 0x80, 0x8d, 0x67, 0x9f, 0x77, 0x7b, 0xc6, 0x70, 0x2c, 0x7d, + 0x39, 0xf2, 0x33, 0x69, 0xa9, 0xd9, 0xba, 0xcf, 0xa5, 0x30, 0xe2, 0x63, 0x04, 0x23, 0x14, 0x61, + 0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc, 0xda, 0x6c, 0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b }; +#elif defined(AES192) + uint8_t key[] = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b }; + uint8_t in[] = { 0x4f, 0x02, 0x1d, 0xb2, 0x43, 0xbc, 0x63, 0x3d, 0x71, 0x78, 0x18, 0x3a, 0x9f, 0xa0, 0x71, 0xe8, + 0xb4, 0xd9, 0xad, 0xa9, 0xad, 0x7d, 0xed, 0xf4, 0xe5, 0xe7, 0x38, 0x76, 0x3f, 0x69, 0x14, 0x5a, + 0x57, 0x1b, 0x24, 0x20, 0x12, 0xfb, 0x7a, 0xe0, 0x7f, 0xa9, 0xba, 0xac, 0x3d, 0xf1, 0x02, 0xe0, + 0x08, 0xb0, 0xe2, 0x79, 0x88, 0x59, 0x88, 0x81, 0xd9, 0x20, 0xa9, 0xe6, 0x4f, 0x56, 0x15, 0xcd }; +#elif defined(AES128) + uint8_t key[] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; + uint8_t in[] = { 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d, + 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee, 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2, + 0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b, 0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16, + 0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09, 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7 }; +#endif + uint8_t iv[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; + uint8_t out[] = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, + 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, + 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, + 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }; +// uint8_t buffer[64]; + struct AES_ctx ctx; + + AES_init_ctx_iv(&ctx, key, iv); + AES_CBC_decrypt_buffer(&ctx, in, 64); + + printf("CBC decrypt: "); + + if (0 == memcmp((char*) out, (char*) in, 64)) { + printf("SUCCESS!\n"); + return(0); + } else { + printf("FAILURE!\n"); + return(1); + } +} + +static int test_encrypt_cbc(void) +{ +#if defined(AES256) + uint8_t key[] = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, + 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 }; + uint8_t out[] = { 0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba, 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6, + 0x9c, 0xfc, 0x4e, 0x96, 0x7e, 0xdb, 0x80, 0x8d, 0x67, 0x9f, 0x77, 0x7b, 0xc6, 0x70, 0x2c, 0x7d, + 0x39, 0xf2, 0x33, 0x69, 0xa9, 0xd9, 0xba, 0xcf, 0xa5, 0x30, 0xe2, 0x63, 0x04, 0x23, 0x14, 0x61, + 0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc, 0xda, 0x6c, 0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b }; +#elif defined(AES192) + uint8_t key[] = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b }; + uint8_t out[] = { 0x4f, 0x02, 0x1d, 0xb2, 0x43, 0xbc, 0x63, 0x3d, 0x71, 0x78, 0x18, 0x3a, 0x9f, 0xa0, 0x71, 0xe8, + 0xb4, 0xd9, 0xad, 0xa9, 0xad, 0x7d, 0xed, 0xf4, 0xe5, 0xe7, 0x38, 0x76, 0x3f, 0x69, 0x14, 0x5a, + 0x57, 0x1b, 0x24, 0x20, 0x12, 0xfb, 0x7a, 0xe0, 0x7f, 0xa9, 0xba, 0xac, 0x3d, 0xf1, 0x02, 0xe0, + 0x08, 0xb0, 0xe2, 0x79, 0x88, 0x59, 0x88, 0x81, 0xd9, 0x20, 0xa9, 0xe6, 0x4f, 0x56, 0x15, 0xcd }; +#elif defined(AES128) + uint8_t key[] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; + uint8_t out[] = { 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d, + 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee, 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2, + 0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b, 0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16, + 0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09, 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7 }; +#endif + uint8_t iv[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; + uint8_t in[] = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, + 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, + 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, + 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }; + struct AES_ctx ctx; + + AES_init_ctx_iv(&ctx, key, iv); + AES_CBC_encrypt_buffer(&ctx, in, 64); + + printf("CBC encrypt: "); + + if (0 == memcmp((char*) out, (char*) in, 64)) { + printf("SUCCESS!\n"); + return(0); + } else { + printf("FAILURE!\n"); + return(1); + } +} + +static int test_xcrypt_ctr(const char* xcrypt); +static int test_encrypt_ctr(void) +{ + return test_xcrypt_ctr("encrypt"); +} + +static int test_decrypt_ctr(void) +{ + return test_xcrypt_ctr("decrypt"); +} + +static int test_xcrypt_ctr(const char* xcrypt) +{ +#if defined(AES256) + uint8_t key[32] = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, + 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 }; + uint8_t in[64] = { 0x60, 0x1e, 0xc3, 0x13, 0x77, 0x57, 0x89, 0xa5, 0xb7, 0xa7, 0xf5, 0x04, 0xbb, 0xf3, 0xd2, 0x28, + 0xf4, 0x43, 0xe3, 0xca, 0x4d, 0x62, 0xb5, 0x9a, 0xca, 0x84, 0xe9, 0x90, 0xca, 0xca, 0xf5, 0xc5, + 0x2b, 0x09, 0x30, 0xda, 0xa2, 0x3d, 0xe9, 0x4c, 0xe8, 0x70, 0x17, 0xba, 0x2d, 0x84, 0x98, 0x8d, + 0xdf, 0xc9, 0xc5, 0x8d, 0xb6, 0x7a, 0xad, 0xa6, 0x13, 0xc2, 0xdd, 0x08, 0x45, 0x79, 0x41, 0xa6 }; +#elif defined(AES192) + uint8_t key[24] = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, + 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b }; + uint8_t in[64] = { 0x1a, 0xbc, 0x93, 0x24, 0x17, 0x52, 0x1c, 0xa2, 0x4f, 0x2b, 0x04, 0x59, 0xfe, 0x7e, 0x6e, 0x0b, + 0x09, 0x03, 0x39, 0xec, 0x0a, 0xa6, 0xfa, 0xef, 0xd5, 0xcc, 0xc2, 0xc6, 0xf4, 0xce, 0x8e, 0x94, + 0x1e, 0x36, 0xb2, 0x6b, 0xd1, 0xeb, 0xc6, 0x70, 0xd1, 0xbd, 0x1d, 0x66, 0x56, 0x20, 0xab, 0xf7, + 0x4f, 0x78, 0xa7, 0xf6, 0xd2, 0x98, 0x09, 0x58, 0x5a, 0x97, 0xda, 0xec, 0x58, 0xc6, 0xb0, 0x50 }; +#elif defined(AES128) + uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; + uint8_t in[64] = { 0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26, 0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce, + 0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff, 0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff, + 0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e, 0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab, + 0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1, 0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee }; +#endif + uint8_t iv[16] = { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; + uint8_t out[64] = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, + 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, + 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, + 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }; + struct AES_ctx ctx; + + AES_init_ctx_iv(&ctx, key, iv); + AES_CTR_xcrypt_buffer(&ctx, in, 64); + + printf("CTR %s: ", xcrypt); + + if (0 == memcmp((char *) out, (char *) in, 64)) { + printf("SUCCESS!\n"); + return(0); + } else { + printf("FAILURE!\n"); + return(1); + } +} + + +static int test_decrypt_ecb(void) +{ +#if defined(AES256) + uint8_t key[] = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, + 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 }; + uint8_t in[] = { 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c, 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8 }; +#elif defined(AES192) + uint8_t key[] = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, + 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b }; + uint8_t in[] = { 0xbd, 0x33, 0x4f, 0x1d, 0x6e, 0x45, 0xf2, 0x5f, 0xf7, 0x12, 0xa2, 0x14, 0x57, 0x1f, 0xa5, 0xcc }; +#elif defined(AES128) + uint8_t key[] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; + uint8_t in[] = { 0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60, 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97 }; +#endif + + uint8_t out[] = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a }; + struct AES_ctx ctx; + + AES_init_ctx(&ctx, key); + AES_ECB_decrypt(&ctx, in); + + printf("ECB decrypt: "); + + if (0 == memcmp((char*) out, (char*) in, 16)) { + printf("SUCCESS!\n"); + return(0); + } else { + printf("FAILURE!\n"); + return(1); + } +} + + diff --git a/test/monniaux/tiny-AES-c/unlicense.txt b/test/monniaux/tiny-AES-c/unlicense.txt new file mode 100644 index 00000000..68a49daa --- /dev/null +++ b/test/monniaux/tiny-AES-c/unlicense.txt @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to -- cgit From 8909fb3df6fd282d6b8f24b288ef5d7ddbdb741a Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Tue, 22 Jan 2019 09:46:30 +0100 Subject: SHA-2 from https://github.com/amosnier/sha-2 --- test/monniaux/sha-2/LICENSE | 24 ++++ test/monniaux/sha-2/Makefile | 40 +++++++ test/monniaux/sha-2/README.md | 99 ++++++++++++++++ test/monniaux/sha-2/sha-256.c | 210 +++++++++++++++++++++++++++++++++ test/monniaux/sha-2/sha-256.h | 1 + test/monniaux/sha-2/sha-256_run.c | 238 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 612 insertions(+) create mode 100644 test/monniaux/sha-2/LICENSE create mode 100644 test/monniaux/sha-2/Makefile create mode 100644 test/monniaux/sha-2/README.md create mode 100644 test/monniaux/sha-2/sha-256.c create mode 100644 test/monniaux/sha-2/sha-256.h create mode 100644 test/monniaux/sha-2/sha-256_run.c (limited to 'test') diff --git a/test/monniaux/sha-2/LICENSE b/test/monniaux/sha-2/LICENSE new file mode 100644 index 00000000..cf1ab25d --- /dev/null +++ b/test/monniaux/sha-2/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/test/monniaux/sha-2/Makefile b/test/monniaux/sha-2/Makefile new file mode 100644 index 00000000..2904b77d --- /dev/null +++ b/test/monniaux/sha-2/Makefile @@ -0,0 +1,40 @@ +CFLAGS=-Wall -O3 +K1C_CC=k1-mbr-gcc +K1C_CFLAGS=-Wall -O3 -std=c99 +K1C_CCOMP=../../../ccomp +K1C_CCOMPFLAGS=-Wall -O3 -D__thread= -D__int128=int + +PRODUCTS=sha-256.host sha-256.gcc.k1c.out sha-256.ccomp.k1c.out sha-256.ccomp.k1c.s sha-256.gcc.k1c.s sha-256.gcc.k1c sha-256.ccomp.k1c + +all: $(PRODUCTS) + +%.gcc.k1c.s: %.c + $(K1C_CC) $(K1C_CFLAGS) -S $< -o $@ + +%.gcc.k1c.o: %.gcc.k1c.s + $(K1C_CC) $(K1C_CFLAGS) -c $< -o $@ + +%.ccomp.k1c.s: %.c + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -S $< -o $@ + +%.ccomp.k1c.o: %.ccomp.k1c.s + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) -c $< -o $@ + +sha-256.host: sha-256.c sha-256_run.c sha-256.h + $(CC) $(CFLAGS) sha-256.c sha-256_run.c -o $@ + +sha-256.gcc.k1c.s sha-256.ccomp.k1c.s sha-256_run.gcc.k1c.s: sha-256.h + +sha-256.gcc.k1c: sha-256.gcc.k1c.o sha-256_run.gcc.k1c.o + $(K1C_CC) $(K1C_CFLAGS) $+ -o $@ + +sha-256.ccomp.k1c: sha-256.ccomp.k1c.o sha-256_run.gcc.k1c.o + $(K1C_CCOMP) $(K1C_CCOMPFLAGS) $+ -o $@ + +%.k1c.out: %.k1c + k1-cluster --cycle-based -- $< | tee $@ + +clean: + $(RM) -f $(PRODUCTS) sha-256.gcc.k1c.o sha-256.ccomp.k1c.o sha-256_run.gcc.k1c.o sha-256_run.gcc.k1c.s + +.PHONY: clean diff --git a/test/monniaux/sha-2/README.md b/test/monniaux/sha-2/README.md new file mode 100644 index 00000000..bd975955 --- /dev/null +++ b/test/monniaux/sha-2/README.md @@ -0,0 +1,99 @@ +# sha-2 [![Build Status](https://travis-ci.org/amosnier/sha-2.svg?branch=master)](https://travis-ci.org/amosnier/sha-2) + +https://github.com/amosnier/sha-2 + +## Contents + +SHA-2 algorithm implementations. + +At the moment, only SHA-256 is implemented. + +## Design criteria + +- Easy to test, include in any project, compile and link. + +- ANSI C with as little specific C99 as possible (e.g. extended + integer types are used, but not bool). + +- Portable. Makes no assumptions on the target system's endianess or + word size. + +- The SHA-256 implementation is a straightforward implementation of + the algorithm specified on + [Wikipedia](https://en.wikipedia.org/wiki/SHA-2). + +## Notes + +The Makefile is as minimal as possible. No effort was put into making +it general. Its purpose is mainly to ease testing for the developer's +host machine. The actual implementation is however extremely easy to +include in any project, may it use GNU make or any other build tool. + +## Code review + +This code has been reviewed at [Stack Exchange CODE +REVIEW](https://codereview.stackexchange.com/questions/182812/self-contained-sha-256-implementation-in-c), +and the implementation has been improved accordingly. + +## Testing + +Testing is continuously performed on Travis CI (see above). + +Apart from that, the implementation has been successfully tested on an x86-64 machine +under Linux as well as on a 16-bit DSP. On the x86-64 machine, all the +available NIST test vectors where successfully tested ([SHA-256 +examples](https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA256.pdf) +and [SHA-2 Additional +examples](https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA2_Additional.pdf), +plus a few others). + +In particular: + +``` +Input Message: "abc" +Message Digest is BA7816BF 8F01CFEA 414140DE 5DAE2223 B00361A3 96177A9C B410FF61 F20015AD +``` + +``` +Input Message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" +Message Digest is 248D6A61 D20638B8 E5C02693 0C3E6039 A33CE459 64FF2167 F6ECEDD4 19DB06C1 +``` + +``` +SHA-256 Test Data +#1) 1 byte 0xbd +68325720 aabd7c82 f30f554b 313d0570 c95accbb 7dc4b5aa e11204c0 8ffe732b +#2) 4 bytes 0xc98c8e55 +7abc22c0 ae5af26c e93dbb94 433a0e0b 2e119d01 4f8e7f65 bd56c61c cccd9504 +#3) 55 bytes of zeros +02779466 cdec1638 11d07881 5c633f21 90141308 1449002f 24aa3e80 f0b88ef7 +#4) 56 bytes of zeros +d4817aa5 497628e7 c77e6b60 6107042b bba31308 88c5f47a 375e6179 be789fbb +#5) 57 bytes of zeros +65a16cb7 861335d5 ace3c607 18b5052e 44660726 da4cd13b b745381b 235a1785 +#6) 64 bytes of zeros +f5a5fd42 d16a2030 2798ef6e d309979b 43003d23 20d9f0e8 ea9831a9 2759fb4b +#7) 1000 bytes of zeros +541b3e9d aa09b20b f85fa273 e5cbd3e8 0185aa4e c298e765 db87742b 70138a53 +#8) 1000 bytes of 0x41 ‘A’ +c2e68682 3489ced2 017f6059 b8b23931 8b6364f6 dcd835d0 a519105a 1eadd6e4 +#9) 1005 bytes of 0x55 ‘U’ +f4d62dde c0f3dd90 ea1380fa 16a5ff8d c4c54b21 740650f2 4afc4120 903552b0 +#10) 1000000 bytes of zeros +d29751f2 649b32ff 572b5e0a 9f541ea6 60a50f94 ff0beedf b0b692b9 24cc8025 +#11) 0x20000000 (536870912) bytes of 0x5a ‘Z’ +15a1868c 12cc5395 1e182344 277447cd 0979536b adcc512a d24c67e9 b2d4f3dd +#12) 0x41000000 (1090519040) bytes of zeros +461c19a9 3bd4344f 9215f5ec 64357090 342bc66b 15a14831 7d276e31 cbc20b53 +#13) 0x6000003e (1610612798) bytes of 0x42 ‘B’ +c23ce8a7 895f4b21 ec0daf37 920ac0a2 62a22004 5a03eb2d fed48ef9 b05aabea +``` + +## License + +This repository is made available in the public domain. See [LICENSE +FILE](LICENSE). + +## Reference implementation + +I had missed that when I made this implementation but [RFC 6234, chapter 8](https://tools.ietf.org/html/rfc6234#section-8) actually includes a reference implementation in C that is (at least in ambition) broader in scope than this one. I have however neither compiled nor tested it. diff --git a/test/monniaux/sha-2/sha-256.c b/test/monniaux/sha-2/sha-256.c new file mode 100644 index 00000000..53d6ff2e --- /dev/null +++ b/test/monniaux/sha-2/sha-256.c @@ -0,0 +1,210 @@ +#include +#include + +#include "sha-256.h" + +#define CHUNK_SIZE 64 +#define TOTAL_LEN_LEN 8 + +/* + * ABOUT bool: this file does not use bool in order to be as pre-C99 compatible as possible. + */ + +/* + * Comments from pseudo-code at https://en.wikipedia.org/wiki/SHA-2 are reproduced here. + * When useful for clarification, portions of the pseudo-code are reproduced here too. + */ + +/* + * Initialize array of round constants: + * (first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311): + */ +static const uint32_t k[] = { + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 +}; + +struct buffer_state { + const uint8_t * p; + size_t len; + size_t total_len; + int single_one_delivered; /* bool */ + int total_len_delivered; /* bool */ +}; + +static inline uint32_t right_rot(uint32_t value, unsigned int count) +{ + /* + * Defined behaviour in standard C for all count where 0 < count < 32, + * which is what we need here. + */ + return value >> count | value << (32 - count); +} + +static void init_buf_state(struct buffer_state * state, const void * input, size_t len) +{ + state->p = input; + state->len = len; + state->total_len = len; + state->single_one_delivered = 0; + state->total_len_delivered = 0; +} + +/* Return value: bool */ +static int calc_chunk(uint8_t chunk[CHUNK_SIZE], struct buffer_state * state) +{ + size_t space_in_chunk; + + if (state->total_len_delivered) { + return 0; + } + + if (state->len >= CHUNK_SIZE) { + memcpy(chunk, state->p, CHUNK_SIZE); + state->p += CHUNK_SIZE; + state->len -= CHUNK_SIZE; + return 1; + } + + memcpy(chunk, state->p, state->len); + chunk += state->len; + space_in_chunk = CHUNK_SIZE - state->len; + state->p += state->len; + state->len = 0; + + /* If we are here, space_in_chunk is one at minimum. */ + if (!state->single_one_delivered) { + *chunk++ = 0x80; + space_in_chunk -= 1; + state->single_one_delivered = 1; + } + + /* + * Now: + * - either there is enough space left for the total length, and we can conclude, + * - or there is too little space left, and we have to pad the rest of this chunk with zeroes. + * In the latter case, we will conclude at the next invokation of this function. + */ + if (space_in_chunk >= TOTAL_LEN_LEN) { + const size_t left = space_in_chunk - TOTAL_LEN_LEN; + size_t len = state->total_len; + int i; + memset(chunk, 0x00, left); + chunk += left; + + /* Storing of len * 8 as a big endian 64-bit without overflow. */ + chunk[7] = (uint8_t) (len << 3); + len >>= 5; + for (i = 6; i >= 0; i--) { + chunk[i] = (uint8_t) len; + len >>= 8; + } + state->total_len_delivered = 1; + } else { + memset(chunk, 0x00, space_in_chunk); + } + + return 1; +} + +/* + * Limitations: + * - Since input is a pointer in RAM, the data to hash should be in RAM, which could be a problem + * for large data sizes. + * - SHA algorithms theoretically operate on bit strings. However, this implementation has no support + * for bit string lengths that are not multiples of eight, and it really operates on arrays of bytes. + * In particular, the len parameter is a number of bytes. + */ +void calc_sha_256(uint8_t hash[32], const void * input, size_t len) +{ + /* + * Note 1: All integers (expect indexes) are 32-bit unsigned integers and addition is calculated modulo 2^32. + * Note 2: For each round, there is one round constant k[i] and one entry in the message schedule array w[i], 0 = i = 63 + * Note 3: The compression function uses 8 working variables, a through h + * Note 4: Big-endian convention is used when expressing the constants in this pseudocode, + * and when parsing message block data from bytes to words, for example, + * the first word of the input message "abc" after padding is 0x61626380 + */ + + /* + * Initialize hash values: + * (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19): + */ + uint32_t h[] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }; + int i, j; + + /* 512-bit chunks is what we will operate on. */ + uint8_t chunk[64]; + + struct buffer_state state; + + init_buf_state(&state, input, len); + + while (calc_chunk(chunk, &state)) { + uint32_t ah[8]; + + /* + * create a 64-entry message schedule array w[0..63] of 32-bit words + * (The initial values in w[0..63] don't matter, so many implementations zero them here) + * copy chunk into first 16 words w[0..15] of the message schedule array + */ + uint32_t w[64]; + const uint8_t *p = chunk; + + memset(w, 0x00, sizeof w); + for (i = 0; i < 16; i++) { + w[i] = (uint32_t) p[0] << 24 | (uint32_t) p[1] << 16 | + (uint32_t) p[2] << 8 | (uint32_t) p[3]; + p += 4; + } + + /* Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array: */ + for (i = 16; i < 64; i++) { + const uint32_t s0 = right_rot(w[i - 15], 7) ^ right_rot(w[i - 15], 18) ^ (w[i - 15] >> 3); + const uint32_t s1 = right_rot(w[i - 2], 17) ^ right_rot(w[i - 2], 19) ^ (w[i - 2] >> 10); + w[i] = w[i - 16] + s0 + w[i - 7] + s1; + } + + /* Initialize working variables to current hash value: */ + for (i = 0; i < 8; i++) + ah[i] = h[i]; + + /* Compression function main loop: */ + for (i = 0; i < 64; i++) { + const uint32_t s1 = right_rot(ah[4], 6) ^ right_rot(ah[4], 11) ^ right_rot(ah[4], 25); + const uint32_t ch = (ah[4] & ah[5]) ^ (~ah[4] & ah[6]); + const uint32_t temp1 = ah[7] + s1 + ch + k[i] + w[i]; + const uint32_t s0 = right_rot(ah[0], 2) ^ right_rot(ah[0], 13) ^ right_rot(ah[0], 22); + const uint32_t maj = (ah[0] & ah[1]) ^ (ah[0] & ah[2]) ^ (ah[1] & ah[2]); + const uint32_t temp2 = s0 + maj; + + ah[7] = ah[6]; + ah[6] = ah[5]; + ah[5] = ah[4]; + ah[4] = ah[3] + temp1; + ah[3] = ah[2]; + ah[2] = ah[1]; + ah[1] = ah[0]; + ah[0] = temp1 + temp2; + } + + /* Add the compressed chunk to the current hash value: */ + for (i = 0; i < 8; i++) + h[i] += ah[i]; + } + + /* Produce the final hash value (big-endian): */ + for (i = 0, j = 0; i < 8; i++) + { + hash[j++] = (uint8_t) (h[i] >> 24); + hash[j++] = (uint8_t) (h[i] >> 16); + hash[j++] = (uint8_t) (h[i] >> 8); + hash[j++] = (uint8_t) h[i]; + } +} diff --git a/test/monniaux/sha-2/sha-256.h b/test/monniaux/sha-2/sha-256.h new file mode 100644 index 00000000..47f06ebf --- /dev/null +++ b/test/monniaux/sha-2/sha-256.h @@ -0,0 +1 @@ +void calc_sha_256(uint8_t hash[32], const void *input, size_t len); diff --git a/test/monniaux/sha-2/sha-256_run.c b/test/monniaux/sha-2/sha-256_run.c new file mode 100644 index 00000000..5b5031c3 --- /dev/null +++ b/test/monniaux/sha-2/sha-256_run.c @@ -0,0 +1,238 @@ +#include +#include +#include +#include + +#include "sha-256.h" + +struct string_vector { + const char *input; + const char *output; +}; + +static const struct string_vector STRING_VECTORS[] = { + { + "", + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + { + "abc", + "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" + }, + { + "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", + "a8ae6e6ee929abea3afcfc5258c8ccd6f85273e0d4626d26c7279f3250f77c8e" + }, + { + "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde", + "057ee79ece0b9a849552ab8d3c335fe9a5f1c46ef5f1d9b190c295728628299c" + }, + { + "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0", + "2a6ad82f3620d3ebe9d678c812ae12312699d673240d5be8fac0910a70000d93" + }, + { + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" + }, + { + "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno" + "ijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", + "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1" + } +}; + +#define LARGE_MESSAGES 1 + +static uint8_t data1[] = { 0xbd }; +static uint8_t data2[] = { 0xc9, 0x8c, 0x8e, 0x55 }; +static uint8_t data7[1000]; +static uint8_t data8[1000]; +static uint8_t data9[1005]; +#if LARGE_MESSAGES +#define SIZEOF_DATA11 536870912 +#define SIZEOF_DATA12 1090519040 +#define SIZEOF_DATA13 1610612798 +static uint8_t * data11; +static uint8_t * data12; +static uint8_t * data13; +#endif + +struct vector { + const uint8_t *input; + size_t input_len; + const char *output; +}; + +static struct vector vectors[] = { + { + data1, + sizeof data1, + "68325720aabd7c82f30f554b313d0570c95accbb7dc4b5aae11204c08ffe732b" + }, + { + data2, + sizeof data2, + "7abc22c0ae5af26ce93dbb94433a0e0b2e119d014f8e7f65bd56c61ccccd9504" + }, + { + data7, + 55, + "02779466cdec163811d078815c633f21901413081449002f24aa3e80f0b88ef7" + }, + { + data7, + 56, + "d4817aa5497628e7c77e6b606107042bbba3130888c5f47a375e6179be789fbb" + }, + { + data7, + 57, + "65a16cb7861335d5ace3c60718b5052e44660726da4cd13bb745381b235a1785" + }, + { + data7, + 64, + "f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb4b" + }, + { + data7, + sizeof data7, + "541b3e9daa09b20bf85fa273e5cbd3e80185aa4ec298e765db87742b70138a53" + }, + { + data8, + sizeof data8, + "c2e686823489ced2017f6059b8b239318b6364f6dcd835d0a519105a1eadd6e4" + }, + { + data9, + sizeof data9, + "f4d62ddec0f3dd90ea1380fa16a5ff8dc4c54b21740650f24afc4120903552b0" + } +#if LARGE_MESSAGES + , + { + NULL, + 1000000, + "d29751f2649b32ff572b5e0a9f541ea660a50f94ff0beedfb0b692b924cc8025" + }, + { + NULL, + SIZEOF_DATA11, + "15a1868c12cc53951e182344277447cd0979536badcc512ad24c67e9b2d4f3dd" + }, + { + NULL, + SIZEOF_DATA12, + "461c19a93bd4344f9215f5ec64357090342bc66b15a148317d276e31cbc20b53" + }, + { + NULL, + SIZEOF_DATA13, + "c23ce8a7895f4b21ec0daf37920ac0a262a220045a03eb2dfed48ef9b05aabea" + } +#endif +}; + +static void construct_binary_messages(void) +{ + memset(data7, 0x00, sizeof data7); + memset(data8, 0x41, sizeof data8); + memset(data9, 0x55, sizeof data9); +#if LARGE_MESSAGES + /* + * Heap allocation as a workaround for some linkers not liking + * large BSS segments. + */ + data11 = malloc(SIZEOF_DATA11); + data12 = malloc(SIZEOF_DATA12); + data13 = malloc(SIZEOF_DATA13); + memset(data11, 0x5a, SIZEOF_DATA11); + memset(data12, 0x00, SIZEOF_DATA12); + memset(data13, 0x42, SIZEOF_DATA13); + vectors[9].input = data12; + vectors[10].input = data11; + vectors[11].input = data12; + vectors[12].input = data13; +#endif +} + +static void destruct_binary_messages(void) +{ +#if LARGE_MESSAGES + free(data11); + free(data12); + free(data13); +#endif +} + +static void hash_to_string(char string[65], const uint8_t hash[32]) +{ + size_t i; + for (i = 0; i < 32; i++) { + string += sprintf(string, "%02x", hash[i]); + } +} + +static int string_test(const char input[], const char output[]) +{ + uint8_t hash[32]; + char hash_string[65]; + calc_sha_256(hash, input, strlen(input)); + hash_to_string(hash_string, hash); + printf("input: %s\n", input); + printf("hash : %s\n", hash_string); + if (strcmp(output, hash_string)) { + printf("FAILURE!\n\n"); + return 1; + } else { + printf("SUCCESS!\n\n"); + return 0; + } +} + +/* + * Limitation: + * - The variable input_len will be truncated to its LONG_BIT least + * significant bits in the print output. This will never be a problem + * for values that in practice are less than 2^32 - 1. Rationale: ANSI + * C-compatibility and keeping it simple. + */ +static int test(const uint8_t * input, size_t input_len, const char output[]) +{ + uint8_t hash[32]; + char hash_string[65]; + calc_sha_256(hash, input, input_len); + hash_to_string(hash_string, hash); + printf("input starts with 0x%02x, length %lu\n", *input, (unsigned long) input_len); + printf("hash : %s\n", hash_string); + if (strcmp(output, hash_string)) { + printf("FAILURE!\n\n"); + return 1; + } else { + printf("SUCCESS!\n\n"); + return 0; + } +} + +int main(void) +{ + size_t i; + for (i = 0; i < (sizeof STRING_VECTORS / sizeof (struct string_vector)); i++) { + const struct string_vector *vector = &STRING_VECTORS[i]; + if (string_test(vector->input, vector->output)) + return 1; + } + construct_binary_messages(); + for (i = 0; i < (sizeof vectors / sizeof (struct vector)); i++) { + const struct vector *vector = &vectors[i]; + if (test(vector->input, vector->input_len, vector->output)) + { + destruct_binary_messages(); + return 1; + } + } + destruct_binary_messages(); + return 0; +} -- cgit From 6acefcbbc51aa7d2edb7b2098a5b15d06e742604 Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 22 Jan 2019 16:18:22 +0100 Subject: Added sxwd and zxwd support --- test/mppa/instr/cast_S32_S64.c | 7 +++++++ test/mppa/instr/cast_S64_U32.c | 7 +++++++ test/mppa/instr/cast_U32_S64.c | 7 +++++++ 3 files changed, 21 insertions(+) create mode 100644 test/mppa/instr/cast_S32_S64.c create mode 100644 test/mppa/instr/cast_S64_U32.c create mode 100644 test/mppa/instr/cast_U32_S64.c (limited to 'test') diff --git a/test/mppa/instr/cast_S32_S64.c b/test/mppa/instr/cast_S32_S64.c new file mode 100644 index 00000000..09c97e00 --- /dev/null +++ b/test/mppa/instr/cast_S32_S64.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(int) +{ + c = (long long) a; +} +END_TEST32() diff --git a/test/mppa/instr/cast_S64_U32.c b/test/mppa/instr/cast_S64_U32.c new file mode 100644 index 00000000..da49b2a8 --- /dev/null +++ b/test/mppa/instr/cast_S64_U32.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(long long) +{ + c = (unsigned int) a; +} +END_TEST() diff --git a/test/mppa/instr/cast_U32_S64.c b/test/mppa/instr/cast_U32_S64.c new file mode 100644 index 00000000..b6bcdf6a --- /dev/null +++ b/test/mppa/instr/cast_U32_S64.c @@ -0,0 +1,7 @@ +#include "framework.h" + +BEGIN_TEST(unsigned int) +{ + c = (long long) a; +} +END_TEST() -- cgit From 94c51be3203aedbf7874c812b90176069a53c88f Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Tue, 22 Jan 2019 18:13:57 +0100 Subject: attribution --- test/monniaux/des/des.c | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/monniaux/des/des.c b/test/monniaux/des/des.c index e8fae267..64ccdc5e 100644 --- a/test/monniaux/des/des.c +++ b/test/monniaux/des/des.c @@ -1,3 +1,4 @@ +/* From Rosetta Code */ #include #include #include -- cgit From fbcbdb2585263ab5156660347bbe6ad3376221a0 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Tue, 22 Jan 2019 18:35:57 +0100 Subject: check malloc() return values --- test/monniaux/sha-2/sha-256_run.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/monniaux/sha-2/sha-256_run.c b/test/monniaux/sha-2/sha-256_run.c index 5b5031c3..68fbcd3e 100644 --- a/test/monniaux/sha-2/sha-256_run.c +++ b/test/monniaux/sha-2/sha-256_run.c @@ -135,6 +135,15 @@ static struct vector vectors[] = { #endif }; +static void *my_malloc(size_t size) { + void *p=malloc(size); + if (p==0) { + fprintf(stderr, "malloc(%zu) failed\n", size); + abort(); + } + return p; +} + static void construct_binary_messages(void) { memset(data7, 0x00, sizeof data7); @@ -145,9 +154,9 @@ static void construct_binary_messages(void) * Heap allocation as a workaround for some linkers not liking * large BSS segments. */ - data11 = malloc(SIZEOF_DATA11); - data12 = malloc(SIZEOF_DATA12); - data13 = malloc(SIZEOF_DATA13); + data11 = my_malloc(SIZEOF_DATA11); + data12 = my_malloc(SIZEOF_DATA12); + data13 = my_malloc(SIZEOF_DATA13); memset(data11, 0x5a, SIZEOF_DATA11); memset(data12, 0x00, SIZEOF_DATA12); memset(data13, 0x42, SIZEOF_DATA13); -- cgit From 0511adf1024647271e230ca13c6f8801d0313efd Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Tue, 22 Jan 2019 18:50:28 +0100 Subject: sha-2 benchmark works --- test/monniaux/sha-2/sha-256_run.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/monniaux/sha-2/sha-256_run.c b/test/monniaux/sha-2/sha-256_run.c index 68fbcd3e..6017712c 100644 --- a/test/monniaux/sha-2/sha-256_run.c +++ b/test/monniaux/sha-2/sha-256_run.c @@ -2,7 +2,8 @@ #include #include #include - +#include +#include "../cycles.h" #include "sha-256.h" struct string_vector { @@ -42,7 +43,7 @@ static const struct string_vector STRING_VECTORS[] = { } }; -#define LARGE_MESSAGES 1 +#define LARGE_MESSAGES 0 static uint8_t data1[] = { 0xbd }; static uint8_t data2[] = { 0xc9, 0x8c, 0x8e, 0x55 }; @@ -135,6 +136,7 @@ static struct vector vectors[] = { #endif }; +#if LARGE_MESSAGES static void *my_malloc(size_t size) { void *p=malloc(size); if (p==0) { @@ -143,6 +145,7 @@ static void *my_malloc(size_t size) { } return p; } +#endif static void construct_binary_messages(void) { @@ -183,12 +186,26 @@ static void hash_to_string(char string[65], const uint8_t hash[32]) string += sprintf(string, "%02x", hash[i]); } } - + +static cycle_t cycle_total, cycle_start_time; + +static void cycle_count_start(void) { + cycle_start_time=get_cycle(); +} + +static void cycle_count_end(void) { + cycle_total += get_cycle()-cycle_start_time; +} + static int string_test(const char input[], const char output[]) { uint8_t hash[32]; char hash_string[65]; + + cycle_count_start(); calc_sha_256(hash, input, strlen(input)); + cycle_count_end(); + hash_to_string(hash_string, hash); printf("input: %s\n", input); printf("hash : %s\n", hash_string); @@ -227,6 +244,7 @@ static int test(const uint8_t * input, size_t input_len, const char output[]) int main(void) { + cycle_count_config(); size_t i; for (i = 0; i < (sizeof STRING_VECTORS / sizeof (struct string_vector)); i++) { const struct string_vector *vector = &STRING_VECTORS[i]; @@ -243,5 +261,6 @@ int main(void) } } destruct_binary_messages(); + printf("total cycles = %" PRIu64 "\n", cycle_total); return 0; } -- cgit From 1451c1269ec670e068ac0a4c083b116e35ae2bea Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Tue, 22 Jan 2019 19:54:53 +0100 Subject: correct measurement --- test/monniaux/sha-2/sha-256_run.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/monniaux/sha-2/sha-256_run.c b/test/monniaux/sha-2/sha-256_run.c index 6017712c..546b7dbc 100644 --- a/test/monniaux/sha-2/sha-256_run.c +++ b/test/monniaux/sha-2/sha-256_run.c @@ -44,6 +44,7 @@ static const struct string_vector STRING_VECTORS[] = { }; #define LARGE_MESSAGES 0 +#define LARGER_MESSAGES 0 static uint8_t data1[] = { 0xbd }; static uint8_t data2[] = { 0xc9, 0x8c, 0x8e, 0x55 }; @@ -110,14 +111,14 @@ static struct vector vectors[] = { data9, sizeof data9, "f4d62ddec0f3dd90ea1380fa16a5ff8dc4c54b21740650f24afc4120903552b0" - } + }, #if LARGE_MESSAGES - , { NULL, 1000000, "d29751f2649b32ff572b5e0a9f541ea660a50f94ff0beedfb0b692b924cc8025" }, +#if LARGER_MESSAGES { NULL, SIZEOF_DATA11, @@ -134,6 +135,7 @@ static struct vector vectors[] = { "c23ce8a7895f4b21ec0daf37920ac0a262a220045a03eb2dfed48ef9b05aabea" } #endif +#endif }; #if LARGE_MESSAGES @@ -153,6 +155,7 @@ static void construct_binary_messages(void) memset(data8, 0x41, sizeof data8); memset(data9, 0x55, sizeof data9); #if LARGE_MESSAGES +#if LARGER_MESSAGES /* * Heap allocation as a workaround for some linkers not liking * large BSS segments. @@ -167,15 +170,23 @@ static void construct_binary_messages(void) vectors[10].input = data11; vectors[11].input = data12; vectors[12].input = data13; +#else + vectors[9].input = data12 = my_malloc(vectors[9].input_len); + memset(data12, 0x00, vectors[9].input_len); +#endif #endif } static void destruct_binary_messages(void) { #if LARGE_MESSAGES +#if LARGER_MESSAGES free(data11); free(data12); free(data13); +#else + free(data12); +#endif #endif } @@ -229,7 +240,11 @@ static int test(const uint8_t * input, size_t input_len, const char output[]) { uint8_t hash[32]; char hash_string[65]; + + cycle_count_start(); calc_sha_256(hash, input, input_len); + cycle_count_end(); + hash_to_string(hash_string, hash); printf("input starts with 0x%02x, length %lu\n", *input, (unsigned long) input_len); printf("hash : %s\n", hash_string); -- cgit From a79cd6dc8c5f0e8e2d2d2df3f6a7763dd46db34e Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Tue, 22 Jan 2019 20:49:28 +0100 Subject: replace array[8] by 8 variables --- test/monniaux/sha-2/sha-256.c | 103 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) (limited to 'test') diff --git a/test/monniaux/sha-2/sha-256.c b/test/monniaux/sha-2/sha-256.c index 53d6ff2e..0da642e1 100644 --- a/test/monniaux/sha-2/sha-256.c +++ b/test/monniaux/sha-2/sha-256.c @@ -121,6 +121,7 @@ static int calc_chunk(uint8_t chunk[CHUNK_SIZE], struct buffer_state * state) * for bit string lengths that are not multiples of eight, and it really operates on arrays of bytes. * In particular, the len parameter is a number of bytes. */ +#if USE_ORIGINAL void calc_sha_256(uint8_t hash[32], const void * input, size_t len) { /* @@ -208,3 +209,105 @@ void calc_sha_256(uint8_t hash[32], const void * input, size_t len) hash[j++] = (uint8_t) h[i]; } } +#else +/* Modified by D. Monniaux */ +void calc_sha_256(uint8_t hash[32], const void * input, size_t len) +{ + /* + * Note 1: All integers (expect indexes) are 32-bit unsigned integers and addition is calculated modulo 2^32. + * Note 2: For each round, there is one round constant k[i] and one entry in the message schedule array w[i], 0 = i = 63 + * Note 3: The compression function uses 8 working variables, a through h + * Note 4: Big-endian convention is used when expressing the constants in this pseudocode, + * and when parsing message block data from bytes to words, for example, + * the first word of the input message "abc" after padding is 0x61626380 + */ + + /* + * Initialize hash values: + * (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19): + */ + uint32_t h[] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }; + int i, j; + + /* 512-bit chunks is what we will operate on. */ + uint8_t chunk[64]; + + struct buffer_state state; + + init_buf_state(&state, input, len); + + while (calc_chunk(chunk, &state)) { + uint32_t ah0, ah1, ah2, ah3, ah4, ah5, ah6, ah7; + + /* + * create a 64-entry message schedule array w[0..63] of 32-bit words + * (The initial values in w[0..63] don't matter, so many implementations zero them here) + * copy chunk into first 16 words w[0..15] of the message schedule array + */ + uint32_t w[64]; + const uint8_t *p = chunk; + + memset(w, 0x00, sizeof w); + for (i = 0; i < 16; i++) { + w[i] = (uint32_t) p[0] << 24 | (uint32_t) p[1] << 16 | + (uint32_t) p[2] << 8 | (uint32_t) p[3]; + p += 4; + } + + /* Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array: */ + for (i = 16; i < 64; i++) { + const uint32_t s0 = right_rot(w[i - 15], 7) ^ right_rot(w[i - 15], 18) ^ (w[i - 15] >> 3); + const uint32_t s1 = right_rot(w[i - 2], 17) ^ right_rot(w[i - 2], 19) ^ (w[i - 2] >> 10); + w[i] = w[i - 16] + s0 + w[i - 7] + s1; + } + + /* Initialize working variables to current hash value: */ + ah0 = h[0]; + ah1 = h[1]; + ah2 = h[2]; + ah3 = h[3]; + ah4 = h[4]; + ah5 = h[5]; + ah6 = h[6]; + ah7 = h[7]; + + /* Compression function main loop: */ + for (i = 0; i < 64; i++) { + const uint32_t s1 = right_rot(ah4, 6) ^ right_rot(ah4, 11) ^ right_rot(ah4, 25); + const uint32_t ch = (ah4 & ah5) ^ (~ah4 & ah6); + const uint32_t temp1 = ah7 + s1 + ch + k[i] + w[i]; + const uint32_t s0 = right_rot(ah0, 2) ^ right_rot(ah0, 13) ^ right_rot(ah0, 22); + const uint32_t maj = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + const uint32_t temp2 = s0 + maj; + + ah7 = ah6; + ah6 = ah5; + ah5 = ah4; + ah4 = ah3 + temp1; + ah3 = ah2; + ah2 = ah1; + ah1 = ah0; + ah0 = temp1 + temp2; + } + + /* Add the compressed chunk to the current hash value: */ + h[0] += ah0; + h[1] += ah1; + h[2] += ah2; + h[3] += ah3; + h[4] += ah4; + h[5] += ah5; + h[6] += ah6; + h[7] += ah7; + } + + /* Produce the final hash value (big-endian): */ + for (i = 0, j = 0; i < 8; i++) + { + hash[j++] = (uint8_t) (h[i] >> 24); + hash[j++] = (uint8_t) (h[i] >> 16); + hash[j++] = (uint8_t) (h[i] >> 8); + hash[j++] = (uint8_t) h[i]; + } +} +#endif -- cgit From f95bd41761db8c2894dbba60c5e8a1a3a60230cb Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Tue, 22 Jan 2019 21:54:03 +0100 Subject: unroll loops --- test/monniaux/sha-2/sha-256.c | 232 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) (limited to 'test') diff --git a/test/monniaux/sha-2/sha-256.c b/test/monniaux/sha-2/sha-256.c index 0da642e1..f083a2e1 100644 --- a/test/monniaux/sha-2/sha-256.c +++ b/test/monniaux/sha-2/sha-256.c @@ -210,6 +210,7 @@ void calc_sha_256(uint8_t hash[32], const void * input, size_t len) } } #else +#if DO_NOT_UNROLL /* Modified by D. Monniaux */ void calc_sha_256(uint8_t hash[32], const void * input, size_t len) { @@ -310,4 +311,235 @@ void calc_sha_256(uint8_t hash[32], const void * input, size_t len) hash[j++] = (uint8_t) h[i]; } } +#else +/* Modified by D. Monniaux */ +void calc_sha_256(uint8_t hash[32], const void * input, size_t len) +{ + /* + * Note 1: All integers (expect indexes) are 32-bit unsigned integers and addition is calculated modulo 2^32. + * Note 2: For each round, there is one round constant k[i] and one entry in the message schedule array w[i], 0 = i = 63 + * Note 3: The compression function uses 8 working variables, a through h + * Note 4: Big-endian convention is used when expressing the constants in this pseudocode, + * and when parsing message block data from bytes to words, for example, + * the first word of the input message "abc" after padding is 0x61626380 + */ + + /* + * Initialize hash values: + * (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19): + */ + uint32_t h[] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }; + int i, j; + + /* 512-bit chunks is what we will operate on. */ + uint8_t chunk[64]; + + struct buffer_state state; + + init_buf_state(&state, input, len); + + while (calc_chunk(chunk, &state)) { + uint32_t ah0, ah1, ah2, ah3, ah4, ah5, ah6, ah7; + + /* + * create a 64-entry message schedule array w[0..63] of 32-bit words + * (The initial values in w[0..63] don't matter, so many implementations zero them here) + * copy chunk into first 16 words w[0..15] of the message schedule array + */ + uint32_t w[64]; + const uint8_t *p = chunk; + + memset(w, 0x00, sizeof w); + for (i = 0; i < 16; i++) { + w[i] = (uint32_t) p[0] << 24 | (uint32_t) p[1] << 16 | + (uint32_t) p[2] << 8 | (uint32_t) p[3]; + p += 4; + } + + /* Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array: */ + for (i = 16; i < 64; i++) { + const uint32_t s0 = right_rot(w[i - 15], 7) ^ right_rot(w[i - 15], 18) ^ (w[i - 15] >> 3); + const uint32_t s1 = right_rot(w[i - 2], 17) ^ right_rot(w[i - 2], 19) ^ (w[i - 2] >> 10); + w[i] = w[i - 16] + s0 + w[i - 7] + s1; + } + + /* Initialize working variables to current hash value: */ + ah0 = h[0]; + ah1 = h[1]; + ah2 = h[2]; + ah3 = h[3]; + ah4 = h[4]; + ah5 = h[5]; + ah6 = h[6]; + ah7 = h[7]; + + /* Compression function main loop: */ + for (i = 0; i < 64; ) { + { + const uint32_t s1 = right_rot(ah4, 6) ^ right_rot(ah4, 11) ^ right_rot(ah4, 25); + const uint32_t ch = (ah4 & ah5) ^ (~ah4 & ah6); + const uint32_t temp1 = ah7 + s1 + ch + k[i] + w[i]; + const uint32_t s0 = right_rot(ah0, 2) ^ right_rot(ah0, 13) ^ right_rot(ah0, 22); + const uint32_t maj = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + const uint32_t temp2 = s0 + maj; + + ah7 = ah6; + ah6 = ah5; + ah5 = ah4; + ah4 = ah3 + temp1; + ah3 = ah2; + ah2 = ah1; + ah1 = ah0; + ah0 = temp1 + temp2; + i++; + } + { + const uint32_t s1 = right_rot(ah4, 6) ^ right_rot(ah4, 11) ^ right_rot(ah4, 25); + const uint32_t ch = (ah4 & ah5) ^ (~ah4 & ah6); + const uint32_t temp1 = ah7 + s1 + ch + k[i] + w[i]; + const uint32_t s0 = right_rot(ah0, 2) ^ right_rot(ah0, 13) ^ right_rot(ah0, 22); + const uint32_t maj = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + const uint32_t temp2 = s0 + maj; + + ah7 = ah6; + ah6 = ah5; + ah5 = ah4; + ah4 = ah3 + temp1; + ah3 = ah2; + ah2 = ah1; + ah1 = ah0; + ah0 = temp1 + temp2; + i++; + } + { + const uint32_t s1 = right_rot(ah4, 6) ^ right_rot(ah4, 11) ^ right_rot(ah4, 25); + const uint32_t ch = (ah4 & ah5) ^ (~ah4 & ah6); + const uint32_t temp1 = ah7 + s1 + ch + k[i] + w[i]; + const uint32_t s0 = right_rot(ah0, 2) ^ right_rot(ah0, 13) ^ right_rot(ah0, 22); + const uint32_t maj = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + const uint32_t temp2 = s0 + maj; + + ah7 = ah6; + ah6 = ah5; + ah5 = ah4; + ah4 = ah3 + temp1; + ah3 = ah2; + ah2 = ah1; + ah1 = ah0; + ah0 = temp1 + temp2; + i++; + } + { + const uint32_t s1 = right_rot(ah4, 6) ^ right_rot(ah4, 11) ^ right_rot(ah4, 25); + const uint32_t ch = (ah4 & ah5) ^ (~ah4 & ah6); + const uint32_t temp1 = ah7 + s1 + ch + k[i] + w[i]; + const uint32_t s0 = right_rot(ah0, 2) ^ right_rot(ah0, 13) ^ right_rot(ah0, 22); + const uint32_t maj = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + const uint32_t temp2 = s0 + maj; + + ah7 = ah6; + ah6 = ah5; + ah5 = ah4; + ah4 = ah3 + temp1; + ah3 = ah2; + ah2 = ah1; + ah1 = ah0; + ah0 = temp1 + temp2; + i++; + } + { + const uint32_t s1 = right_rot(ah4, 6) ^ right_rot(ah4, 11) ^ right_rot(ah4, 25); + const uint32_t ch = (ah4 & ah5) ^ (~ah4 & ah6); + const uint32_t temp1 = ah7 + s1 + ch + k[i] + w[i]; + const uint32_t s0 = right_rot(ah0, 2) ^ right_rot(ah0, 13) ^ right_rot(ah0, 22); + const uint32_t maj = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + const uint32_t temp2 = s0 + maj; + + ah7 = ah6; + ah6 = ah5; + ah5 = ah4; + ah4 = ah3 + temp1; + ah3 = ah2; + ah2 = ah1; + ah1 = ah0; + ah0 = temp1 + temp2; + i++; + } + { + const uint32_t s1 = right_rot(ah4, 6) ^ right_rot(ah4, 11) ^ right_rot(ah4, 25); + const uint32_t ch = (ah4 & ah5) ^ (~ah4 & ah6); + const uint32_t temp1 = ah7 + s1 + ch + k[i] + w[i]; + const uint32_t s0 = right_rot(ah0, 2) ^ right_rot(ah0, 13) ^ right_rot(ah0, 22); + const uint32_t maj = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + const uint32_t temp2 = s0 + maj; + + ah7 = ah6; + ah6 = ah5; + ah5 = ah4; + ah4 = ah3 + temp1; + ah3 = ah2; + ah2 = ah1; + ah1 = ah0; + ah0 = temp1 + temp2; + i++; + } + { + const uint32_t s1 = right_rot(ah4, 6) ^ right_rot(ah4, 11) ^ right_rot(ah4, 25); + const uint32_t ch = (ah4 & ah5) ^ (~ah4 & ah6); + const uint32_t temp1 = ah7 + s1 + ch + k[i] + w[i]; + const uint32_t s0 = right_rot(ah0, 2) ^ right_rot(ah0, 13) ^ right_rot(ah0, 22); + const uint32_t maj = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + const uint32_t temp2 = s0 + maj; + + ah7 = ah6; + ah6 = ah5; + ah5 = ah4; + ah4 = ah3 + temp1; + ah3 = ah2; + ah2 = ah1; + ah1 = ah0; + ah0 = temp1 + temp2; + i++; + } + { + const uint32_t s1 = right_rot(ah4, 6) ^ right_rot(ah4, 11) ^ right_rot(ah4, 25); + const uint32_t ch = (ah4 & ah5) ^ (~ah4 & ah6); + const uint32_t temp1 = ah7 + s1 + ch + k[i] + w[i]; + const uint32_t s0 = right_rot(ah0, 2) ^ right_rot(ah0, 13) ^ right_rot(ah0, 22); + const uint32_t maj = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + const uint32_t temp2 = s0 + maj; + + ah7 = ah6; + ah6 = ah5; + ah5 = ah4; + ah4 = ah3 + temp1; + ah3 = ah2; + ah2 = ah1; + ah1 = ah0; + ah0 = temp1 + temp2; + i++; + } + } + + /* Add the compressed chunk to the current hash value: */ + h[0] += ah0; + h[1] += ah1; + h[2] += ah2; + h[3] += ah3; + h[4] += ah4; + h[5] += ah5; + h[6] += ah6; + h[7] += ah7; + } + + /* Produce the final hash value (big-endian): */ + for (i = 0, j = 0; i < 8; i++) + { + hash[j++] = (uint8_t) (h[i] >> 24); + hash[j++] = (uint8_t) (h[i] >> 16); + hash[j++] = (uint8_t) (h[i] >> 8); + hash[j++] = (uint8_t) h[i]; + } +} +#endif #endif -- cgit From 38f01037de197285181c8ce1868b2a69dcf136ee Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Tue, 22 Jan 2019 22:03:49 +0100 Subject: to test memcpy one day --- test/monniaux/sha-2/sha-256.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/monniaux/sha-2/sha-256.c b/test/monniaux/sha-2/sha-256.c index f083a2e1..17ba98aa 100644 --- a/test/monniaux/sha-2/sha-256.c +++ b/test/monniaux/sha-2/sha-256.c @@ -1,5 +1,10 @@ #include #include +#if 0 /* __COMPCERT__ */ +#define my_memcpy(dst, src, size) __builtin_memcpy_aligned(dst, src, size, 1) +#else +#define my_memcpy(dst, src, size) memcpy(dst, src, size) +#endif #include "sha-256.h" @@ -66,7 +71,7 @@ static int calc_chunk(uint8_t chunk[CHUNK_SIZE], struct buffer_state * state) } if (state->len >= CHUNK_SIZE) { - memcpy(chunk, state->p, CHUNK_SIZE); + my_memcpy(chunk, state->p, CHUNK_SIZE); state->p += CHUNK_SIZE; state->len -= CHUNK_SIZE; return 1; -- cgit From 277fba5f031721197947832f0c721e43913af995 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Tue, 22 Jan 2019 22:27:21 +0100 Subject: autoincrement --- test/monniaux/sha-2/sha-256.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/monniaux/sha-2/sha-256.c b/test/monniaux/sha-2/sha-256.c index 17ba98aa..05cda24f 100644 --- a/test/monniaux/sha-2/sha-256.c +++ b/test/monniaux/sha-2/sha-256.c @@ -126,6 +126,9 @@ static int calc_chunk(uint8_t chunk[CHUNK_SIZE], struct buffer_state * state) * for bit string lengths that are not multiples of eight, and it really operates on arrays of bytes. * In particular, the len parameter is a number of bytes. */ +#define DO_NOT_UNROLL 1 +#define AUTOINCREMENT 1 + #if USE_ORIGINAL void calc_sha_256(uint8_t hash[32], const void * input, size_t len) { @@ -278,10 +281,18 @@ void calc_sha_256(uint8_t hash[32], const void * input, size_t len) ah7 = h[7]; /* Compression function main loop: */ +#if AUTOINCREMENT + const uint32_t *ki = k, *wi = w; +#endif for (i = 0; i < 64; i++) { const uint32_t s1 = right_rot(ah4, 6) ^ right_rot(ah4, 11) ^ right_rot(ah4, 25); const uint32_t ch = (ah4 & ah5) ^ (~ah4 & ah6); - const uint32_t temp1 = ah7 + s1 + ch + k[i] + w[i]; + const uint32_t temp1 = ah7 + s1 + ch + +#if AUTOINCREMENT + *(ki++) + *(wi++); +#else + k[i] + w[i]; +#endif const uint32_t s0 = right_rot(ah0, 2) ^ right_rot(ah0, 13) ^ right_rot(ah0, 22); const uint32_t maj = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); const uint32_t temp2 = s0 + maj; -- cgit From 2dfb832981583f16abd6ba17bc8a714a2803c67f Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Sat, 26 Jan 2019 10:09:53 +0100 Subject: micro bunzip --- test/monniaux/micro-bunzip/Makefile | 24 ++ test/monniaux/micro-bunzip/micro-bunzip.c | 516 ++++++++++++++++++++++++++++++ 2 files changed, 540 insertions(+) create mode 100644 test/monniaux/micro-bunzip/Makefile create mode 100644 test/monniaux/micro-bunzip/micro-bunzip.c (limited to 'test') diff --git a/test/monniaux/micro-bunzip/Makefile b/test/monniaux/micro-bunzip/Makefile new file mode 100644 index 00000000..2b89c6c1 --- /dev/null +++ b/test/monniaux/micro-bunzip/Makefile @@ -0,0 +1,24 @@ +all: testfile.txt testfile.txt.2 + cmp testfile.txt testfile.txt.2 + +micro-bunzip.k1c: micro-bunzip.c + ../../../ccomp -O3 $< -U __SIZEOF_INT128__ -D __SIZE_TYPE__='long long' -o $@ + +testfile.txt: micro-bunzip.c + cat micro-bunzip.c > $@ + sha1sum micro-bunzip.c >> $@ + cat micro-bunzip.c >> $@ + md5sum micro-bunzip.c >> $@ + cat micro-bunzip.c >> $@ + sha224sum micro-bunzip.c >> $@ + cat micro-bunzip.c >> $@ + sha256sum micro-bunzip.c >> $@ + cat micro-bunzip.c >> $@ + sha384sum micro-bunzip.c >> $@ + cat micro-bunzip.c >> $@ + sha512sum micro-bunzip.c >> $@ + cat micro-bunzip.c >> $@ + +testfile.txt.2: testfile.txt micro-bunzip.k1c + bzip2 $@ + diff --git a/test/monniaux/micro-bunzip/micro-bunzip.c b/test/monniaux/micro-bunzip/micro-bunzip.c new file mode 100644 index 00000000..ef307cef --- /dev/null +++ b/test/monniaux/micro-bunzip/micro-bunzip.c @@ -0,0 +1,516 @@ +/* vi: set sw=4 ts=4: */ +/* http://www.landley.net/code/micro-bunzip.c */ +/* micro-bunzip, a small, simple bzip2 decompression implementation. + Copyright 2003 by Rob Landley (rob@landley.net). + + Based on bzip2 decompression code by Julian R Seward (jseward@acm.org), + which also acknowledges contributions by Mike Burrows, David Wheeler, + Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten, + Robert Sedgewick, and Jon L. Bentley. + + I hereby release this code under the GNU Library General Public License + (LGPL) version 2, available at http://www.gnu.org/copyleft/lgpl.html +*/ + +#include +#include +#include +#include +#include + +/* Constants for huffman coding */ +#define MAX_GROUPS 6 +#define GROUP_SIZE 50 /* 64 would have been more efficient */ +#define MAX_HUFCODE_BITS 20 /* Longest huffman code allowed */ +#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */ +#define SYMBOL_RUNA 0 +#define SYMBOL_RUNB 1 + +/* Status return values */ +#define RETVAL_OK 0 +#define RETVAL_LAST_BLOCK (-1) +#define RETVAL_NOT_BZIP_DATA (-2) +#define RETVAL_UNEXPECTED_INPUT_EOF (-3) +#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4) +#define RETVAL_DATA_ERROR (-5) +#define RETVAL_OUT_OF_MEMORY (-6) +#define RETVAL_OBSOLETE_INPUT (-7) + +/* Other housekeeping constants */ +#define IOBUF_SIZE 4096 + +char *bunzip_errors[]={NULL,"Bad file checksum","Not bzip data", + "Unexpected input EOF","Unexpected output EOF","Data error", + "Out of memory","Obsolete (pre 0.9.5) bzip format not supported."}; + +/* This is what we know about each huffman coding group */ +struct group_data { + int limit[MAX_HUFCODE_BITS],base[MAX_HUFCODE_BITS],permute[MAX_SYMBOLS]; + char minLen, maxLen; +}; + +/* Structure holding all the housekeeping data, including IO buffers and + memory that persists between calls to bunzip */ +typedef struct { + /* For I/O error handling */ + jmp_buf jmpbuf; + /* Input stream, input buffer, input bit buffer */ + int in_fd,inbufCount,inbufPos; + unsigned char *inbuf; + unsigned int inbufBitCount, inbufBits; + /* Output buffer */ + char outbuf[IOBUF_SIZE]; + int outbufPos; + /* The CRC values stored in the block header and calculated from the data */ + unsigned int crc32Table[256],headerCRC, dataCRC, totalCRC; + /* Intermediate buffer and its size (in bytes) */ + unsigned int *dbuf, dbufSize; + /* State for interrupting output loop */ + int writePos,writeRun,writeCount,writeCurrent; + + /* These things are a bit too big to go on the stack */ + unsigned char selectors[32768]; /* nSelectors=15 bits */ + struct group_data groups[MAX_GROUPS]; /* huffman coding tables */ +} bunzip_data; + +/* Return the next nnn bits of input. All reads from the compressed input + are done through this function. All reads are big endian */ +static unsigned int get_bits(bunzip_data *bd, char bits_wanted) +{ + unsigned int bits=0; + + /* If we need to get more data from the byte buffer, do so. (Loop getting + one byte at a time to enforce endianness and avoid unaligned access.) */ + while (bd->inbufBitCountinbufPos==bd->inbufCount) { + if(!(bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE))) + longjmp(bd->jmpbuf,RETVAL_UNEXPECTED_INPUT_EOF); + bd->inbufPos=0; + } + /* Avoid 32-bit overflow (dump bit buffer to top of output) */ + if(bd->inbufBitCount>=24) { + bits=bd->inbufBits&((1<inbufBitCount)-1); + bits_wanted-=bd->inbufBitCount; + bits<<=bits_wanted; + bd->inbufBitCount=0; + } + /* Grab next 8 bits of input from buffer. */ + bd->inbufBits=(bd->inbufBits<<8)|bd->inbuf[bd->inbufPos++]; + bd->inbufBitCount+=8; + } + /* Calculate result */ + bd->inbufBitCount-=bits_wanted; + bits|=(bd->inbufBits>>bd->inbufBitCount)&((1<headerCRC=get_bits(bd,32); + /* Is this the last block (with CRC for file)? */ + if(!strcmp(mtfSymbol,"\x17\x72\x45\x38\x50\x90")) + return RETVAL_LAST_BLOCK; + /* If it's not a valid data block, barf. */ + if(strcmp(mtfSymbol,"\x31\x41\x59\x26\x53\x59")) + return RETVAL_NOT_BZIP_DATA; + + dbuf=bd->dbuf; + dbufSize=bd->dbufSize; + selectors=bd->selectors; + /* We can add support for blockRandomised if anybody complains. There was + some code for this in busybox 1.0.0-pre3, but nobody ever noticed that + it didn't actually work. */ + if(get_bits(bd,1)) return RETVAL_OBSOLETE_INPUT; + if((origPtr=get_bits(bd,24)) > dbufSize) return RETVAL_DATA_ERROR; + /* mapping table: if some byte values are never used (encoding things + like ascii text), the compression code removes the gaps to have fewer + symbols to deal with, and writes a sparse bitfield indicating which + values were present. We make a translation table to convert the symbols + back to the corresponding bytes. */ + t=get_bits(bd, 16); + memset(symToByte,0,256); + symTotal=0; + for (i=0;i<16;i++) { + if(t&(1<<(15-i))) { + k=get_bits(bd,16); + for(j=0;j<16;j++) + if(k&(1<<(15-j))) symToByte[symTotal++]=(16*i)+j; + } + } + /* How many different huffman coding groups does this block use? */ + groupCount=get_bits(bd,3); + if (groupCount<2 || groupCount>MAX_GROUPS) return RETVAL_DATA_ERROR; + /* nSelectors: Every GROUP_SIZE many symbols we select a new huffman coding + group. Read in the group selector list, which is stored as MTF encoded + bit runs. */ + if(!(nSelectors=get_bits(bd, 15))) return RETVAL_DATA_ERROR; + for(i=0; i=groupCount) return RETVAL_DATA_ERROR; + /* Decode MTF to get the next selector */ + uc = mtfSymbol[j]; + memmove(mtfSymbol+1,mtfSymbol,j); + mtfSymbol[0]=selectors[i]=uc; + } + /* Read the huffman coding tables for each group, which code for symTotal + literal symbols, plus two run symbols (RUNA, RUNB) */ + symCount=symTotal+2; + for (j=0; j MAX_HUFCODE_BITS) return RETVAL_DATA_ERROR; + if(!get_bits(bd, 1)) break; + if(!get_bits(bd, 1)) t++; + else t--; + } + length[i] = t; + } + /* Find largest and smallest lengths in this group */ + minLen=maxLen=length[0]; + for(i = 1; i < symCount; i++) { + if(length[i] > maxLen) maxLen = length[i]; + else if(length[i] < minLen) minLen = length[i]; + } + /* Calculate permute[], base[], and limit[] tables from length[]. + * + * permute[] is the lookup table for converting huffman coded symbols + * into decoded symbols. base[] is the amount to subtract from the + * value of a huffman symbol of a given length when using permute[]. + * + * limit[] indicates the largest numerical value a symbol with a given + * number of bits can have. It lets us know when to stop reading. + * + * To use these, keep reading bits until value<=limit[bitcount] or + * you've read over 20 bits (error). Then the decoded symbol + * equals permute[hufcode_value-base[hufcode_bitcount]]. + */ + hufGroup=bd->groups+j; + hufGroup->minLen = minLen; + hufGroup->maxLen = maxLen; + /* Note that minLen can't be smaller than 1, so we adjust the base + and limit array pointers so we're not always wasting the first + entry. We do this again when using them (during symbol decoding).*/ + base=hufGroup->base-1; + limit=hufGroup->limit-1; + /* Calculate permute[] */ + pp = 0; + for(i=minLen;i<=maxLen;i++) + for(t=0;tpermute[pp++] = t; + /* Count cumulative symbols coded for at each bit length */ + for (i=minLen;i<=maxLen;i++) temp[i]=limit[i]=0; + for (i=0;i=nSelectors) return RETVAL_DATA_ERROR; + hufGroup=bd->groups+selectors[selector++]; + base=hufGroup->base-1; + limit=hufGroup->limit-1; + } + /* Read next huffman-coded symbol */ + i = hufGroup->minLen; + j=get_bits(bd, i); + for(;;) { + if (i > hufGroup->maxLen) return RETVAL_DATA_ERROR; + if (j <= limit[i]) break; + i++; + + j = (j << 1) | get_bits(bd,1); + } + /* Huffman decode nextSym (with bounds checking) */ + j-=base[i]; + if (j < 0 || j >= MAX_SYMBOLS) return RETVAL_DATA_ERROR; + nextSym = hufGroup->permute[j]; + /* If this is a repeated run, loop collecting data */ + if (nextSym == SYMBOL_RUNA || nextSym == SYMBOL_RUNB) { + /* If this is the start of a new run, zero out counter */ + if(!runPos) { + runPos = 1; + t = 0; + } + /* Neat trick that saves 1 symbol: instead of or-ing 0 or 1 at + each bit position, add 1 or 2 instead. For example, + 1011 is 1<<0 + 1<<1 + 2<<2. 1010 is 2<<0 + 2<<1 + 1<<2. + You can make any bit pattern that way using 1 less symbol than + the basic or 0/1 method (except all bits 0, which would use no + symbols, but a run of length 0 doesn't mean anything in this + context). Thus space is saved. */ + if (nextSym == SYMBOL_RUNA) t += runPos; + else t += 2*runPos; + runPos <<= 1; + continue; + } + /* When we hit the first non-run symbol after a run, we now know + how many times to repeat the last literal, so append that many + copies to our buffer of decoded symbols (dbuf) now. (The last + literal used is the one at the head of the mtfSymbol array.) */ + if(runPos) { + runPos=0; + if(dbufCount+t>=dbufSize) return RETVAL_DATA_ERROR; + + uc = symToByte[mtfSymbol[0]]; + byteCount[uc] += t; + while(t--) dbuf[dbufCount++]=uc; + } + /* Is this the terminating symbol? */ + if(nextSym>symTotal) break; + /* At this point, the symbol we just decoded indicates a new literal + character. Subtract one to get the position in the MTF array + at which this literal is currently to be found. (Note that the + result can't be -1 or 0, because 0 and 1 are RUNA and RUNB. + Another instance of the first symbol in the mtf array, position 0, + would have been handled as part of a run.) */ + if(dbufCount>=dbufSize) return RETVAL_DATA_ERROR; + i = nextSym - 1; + uc = mtfSymbol[i]; + memmove(mtfSymbol+1,mtfSymbol,i); + mtfSymbol[0] = uc; + uc=symToByte[uc]; + /* We have our literal byte. Save it into dbuf. */ + byteCount[uc]++; + dbuf[dbufCount++] = (unsigned int)uc; + } + /* At this point, we've finished reading huffman-coded symbols and + compressed runs from the input stream. There are dbufCount many of + them in dbuf[]. Now undo the Burrows-Wheeler transform on dbuf. + See http://dogma.net/markn/articles/bwt/bwt.htm + */ + + /* Now we know what dbufCount is, do a better sanity check on origPtr. */ + if (origPtr<0 || origPtr>=dbufCount) return RETVAL_DATA_ERROR; + /* Turn byteCount into cumulative occurrence counts of 0 to n-1. */ + j=0; + for(i=0;i<256;i++) { + k=j+byteCount[i]; + byteCount[i] = j; + j=k; + } + /* Figure out what order dbuf would be in if we sorted it. */ + for (i=0;idataCRC = 0xffffffffL; + /* Decode first byte by hand to initialize "previous" byte. Note that it + doesn't get output, and if the first three characters are identical + it doesn't qualify as a run (hence uc=255, which will either wrap + to 1 or get reset). */ + if(dbufCount) { + bd->writePos=dbuf[origPtr]; + bd->writeCurrent=(unsigned char)(bd->writePos&0xff); + bd->writePos>>=8; + bd->writeRun=-1; + } + bd->writeCount=dbufCount; + + return RETVAL_OK; +} + +/* Flush output buffer to disk */ +extern void flush_bunzip_outbuf(bunzip_data *bd, int out_fd) +{ + if(bd->outbufPos) { + if(write(out_fd, bd->outbuf, bd->outbufPos) != bd->outbufPos) + longjmp(bd->jmpbuf,RETVAL_UNEXPECTED_OUTPUT_EOF); + bd->outbufPos=0; + } +} + + +/* Undo burrows-wheeler transform on intermediate buffer to produce output. + If !len, write up to len bytes of data to buf. Otherwise write to out_fd. + Returns len ? bytes written : RETVAL_OK. Notice all errors negative #'s. */ +extern int write_bunzip_data(bunzip_data *bd, int out_fd, char *outbuf, int len) +{ + unsigned int *dbuf=bd->dbuf; + int count,pos,current, run,copies,outbyte,previous,gotcount=0; + + for(;;) { + /* If last read was short due to end of file, return last block now */ + if(bd->writeCount<0) return bd->writeCount; + /* If we need to refill dbuf, do it. */ + if(!bd->writeCount) { + int i=read_bunzip_data(bd); + if(i) { + if(i==RETVAL_LAST_BLOCK) { + bd->writeCount=i; + return gotcount; + } else return i; + } + } + /* Loop generating output */ + count=bd->writeCount; + pos=bd->writePos; + current=bd->writeCurrent; + run=bd->writeRun; + while(count) { + /* If somebody (like busybox tar) wants a certain number of bytes of + data from memory instead of written to a file, humor them */ + if(len && bd->outbufPos>=len) goto dataus_interruptus; + count--; + /* Follow sequence vector to undo Burrows-Wheeler transform */ + previous=current; + pos=dbuf[pos]; + current=pos&0xff; + pos>>=8; + /* Whenever we see 3 consecutive copies of the same byte, + the 4th is a repeat count */ + if(run++==3) { + copies=current; + outbyte=previous; + current=-1; + } else { + copies=1; + outbyte=current; + } + /* Output bytes to buffer, flushing to file if necessary */ + while(copies--) { + if(bd->outbufPos == IOBUF_SIZE) flush_bunzip_outbuf(bd,out_fd); + bd->outbuf[bd->outbufPos++] = outbyte; + bd->dataCRC = (bd->dataCRC << 8) + ^ bd->crc32Table[(bd->dataCRC >> 24) ^ outbyte]; + } + if(current!=previous) run=0; + } + /* Decompression of this block completed successfully */ + bd->dataCRC=~(bd->dataCRC); + bd->totalCRC=((bd->totalCRC << 1) | (bd->totalCRC >> 31)) ^ bd->dataCRC; + /* If this block had a CRC error, force file level CRC error. */ + if(bd->dataCRC!=bd->headerCRC) { + bd->totalCRC=bd->headerCRC+1; + return RETVAL_LAST_BLOCK; + } +dataus_interruptus: + bd->writeCount=count; + if(len) { + gotcount+=bd->outbufPos; + memcpy(outbuf,bd->outbuf,len); + /* If we got enough data, checkpoint loop state and return */ + if((len-=bd->outbufPos)<1) { + bd->outbufPos-=len; + if(bd->outbufPos) + memmove(bd->outbuf,bd->outbuf+len,bd->outbufPos); + bd->writePos=pos; + bd->writeCurrent=current; + bd->writeRun=run; + return gotcount; + } + } + } +} + +/* Allocate the structure, read file header. If !len, src_fd contains + filehandle to read from. Else inbuf contains data. */ +extern int start_bunzip(bunzip_data **bdp, int src_fd, char *inbuf, int len) +{ + bunzip_data *bd; + unsigned int i,j,c; + + /* Figure out how much data to allocate */ + i=sizeof(bunzip_data); + if(!len) i+=IOBUF_SIZE; + /* Allocate bunzip_data. Most fields initialize to zero. */ + if(!(bd=*bdp=malloc(i))) return RETVAL_OUT_OF_MEMORY; + memset(bd,0,sizeof(bunzip_data)); + if(len) { + bd->inbuf=inbuf; + bd->inbufCount=len; + bd->in_fd=-1; + } else { + bd->inbuf=(char *)(bd+1); + bd->in_fd=src_fd; + } + /* Init the CRC32 table (big endian) */ + for(i=0;i<256;i++) { + c=i<<24; + for(j=8;j;j--) + c=c&0x80000000 ? (c<<1)^0x04c11db7 : (c<<1); + bd->crc32Table[i]=c; + } + /* Setup for I/O error handling via longjmp */ + i=setjmp(bd->jmpbuf); + if(i) return i; + /* Ensure that file starts with "BZh" */ + for(i=0;i<3;i++) if(get_bits(bd,8)!="BZh"[i]) return RETVAL_NOT_BZIP_DATA; + /* Next byte ascii '1'-'9', indicates block size in units of 100k of + uncompressed data. Allocate intermediate buffer for block. */ + i=get_bits(bd,8); + if (i<'1' || i>'9') return RETVAL_NOT_BZIP_DATA; + bd->dbufSize=100000*(i-'0'); + if(!(bd->dbuf=malloc(bd->dbufSize * sizeof(int)))) + return RETVAL_OUT_OF_MEMORY; + return RETVAL_OK; +} + +/* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip data, + not end of file.) */ +extern char *uncompressStream(int src_fd, int dst_fd) +{ + bunzip_data *bd; + int i; + + if(!(i=start_bunzip(&bd,src_fd,0,0))) { + i=write_bunzip_data(bd,dst_fd,0,0); + if(i==RETVAL_LAST_BLOCK && bd->headerCRC==bd->totalCRC) i=RETVAL_OK; + } + flush_bunzip_outbuf(bd,dst_fd); + if(bd->dbuf) free(bd->dbuf); + free(bd); + return bunzip_errors[-i]; +} + +/* Dumb little test thing, decompress stdin to stdout */ +int main(int argc, char *argv[]) +{ + char *c=uncompressStream(0,1); + fprintf(stderr,"\n%s\n", c ? c : "Completed OK"); +} -- cgit From 86629431ce8f49d192bd5b55c7ff346e1a1d98cb Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Sat, 26 Jan 2019 11:06:26 +0100 Subject: micro bunzip --- test/monniaux/clock.c | 15 +++++++++++ test/monniaux/clock.h | 5 ++++ test/monniaux/cycles.h | 6 ++--- test/monniaux/micro-bunzip/Makefile | 41 ++++++++++++++++++++----------- test/monniaux/micro-bunzip/micro-bunzip.c | 13 ++++++++-- 5 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 test/monniaux/clock.c create mode 100644 test/monniaux/clock.h (limited to 'test') diff --git a/test/monniaux/clock.c b/test/monniaux/clock.c new file mode 100644 index 00000000..506dadc3 --- /dev/null +++ b/test/monniaux/clock.c @@ -0,0 +1,15 @@ +#include "cycles.h" + +static cycle_t total_clock, last_start; + +void clock_start(void) { + last_start = get_cycle(); +} + +void clock_stop(void) { + total_clock += get_cycle() - last_start; +} + +cycle_t get_total_clock(void) { + return total_clock; +} diff --git a/test/monniaux/clock.h b/test/monniaux/clock.h new file mode 100644 index 00000000..768985b4 --- /dev/null +++ b/test/monniaux/clock.h @@ -0,0 +1,5 @@ +typedef unsigned long long cycle_t; + +void clock_stop(void); +void clock_start(void); +cycle_t get_total_clock(void); diff --git a/test/monniaux/cycles.h b/test/monniaux/cycles.h index 212e65fc..34f5bae5 100644 --- a/test/monniaux/cycles.h +++ b/test/monniaux/cycles.h @@ -1,17 +1,17 @@ -typedef uint64_t cycle_t; +typedef unsigned long long cycle_t; #ifdef __K1C__ #include static inline void cycle_count_config(void) { /* config pmc for cycle count */ - uint64_t pmc_value = __builtin_k1_get(K1_SFR_PMC); + cycle_t pmc_value = __builtin_k1_get(K1_SFR_PMC); pmc_value &= ~(0xfULL); __builtin_k1_set(K1_SFR_PMC, pmc_value); } -static inline uint64_t get_cycle(void) +static inline cycle_t get_cycle(void) { return __builtin_k1_get(K1_SFR_PM0); } diff --git a/test/monniaux/micro-bunzip/Makefile b/test/monniaux/micro-bunzip/Makefile index 2b89c6c1..8916d61f 100644 --- a/test/monniaux/micro-bunzip/Makefile +++ b/test/monniaux/micro-bunzip/Makefile @@ -1,24 +1,35 @@ -all: testfile.txt testfile.txt.2 - cmp testfile.txt testfile.txt.2 +all: testfile.txt testfile.txt.2ccomp testfile.txt.2gcc + cmp testfile.txt testfile.txt.2ccomp + cmp testfile.txt testfile.txt.2gcc -micro-bunzip.k1c: micro-bunzip.c - ../../../ccomp -O3 $< -U __SIZEOF_INT128__ -D __SIZE_TYPE__='long long' -o $@ +../clock.gcc.k1c.o : ../clock.c ../cycles.h + k1-mbr-gcc -c -Wall -O3 $< -o $@ + +micro-bunzip.ccomp.k1c: micro-bunzip.c ../clock.gcc.k1c.o + ../../../ccomp -Wall -O3 $+ -U __SIZEOF_INT128__ -D __SIZE_TYPE__='unsigned long long' -o $@ + +# TODO: -O3 buggy?? +micro-bunzip.gcc.k1c: micro-bunzip.c ../clock.gcc.k1c.o + k1-mbr-gcc -Wall -O2 $+ -o $@ testfile.txt: micro-bunzip.c cat micro-bunzip.c > $@ sha1sum micro-bunzip.c >> $@ cat micro-bunzip.c >> $@ md5sum micro-bunzip.c >> $@ - cat micro-bunzip.c >> $@ - sha224sum micro-bunzip.c >> $@ - cat micro-bunzip.c >> $@ - sha256sum micro-bunzip.c >> $@ - cat micro-bunzip.c >> $@ - sha384sum micro-bunzip.c >> $@ - cat micro-bunzip.c >> $@ - sha512sum micro-bunzip.c >> $@ - cat micro-bunzip.c >> $@ +# cat micro-bunzip.c >> $@ +# sha224sum micro-bunzip.c >> $@ +# cat micro-bunzip.c >> $@ +# sha256sum micro-bunzip.c >> $@ +# cat micro-bunzip.c >> $@ +# sha384sum micro-bunzip.c >> $@ +# cat micro-bunzip.c >> $@ +# sha512sum micro-bunzip.c >> $@ +#x cat micro-bunzip.c >> $@ + +testfile.txt.2ccomp: testfile.txt micro-bunzip.ccomp.k1c + bzip2 $@ -testfile.txt.2: testfile.txt micro-bunzip.k1c - bzip2 $@ +testfile.txt.2gcc: testfile.txt micro-bunzip.gcc.k1c + bzip2 $@ diff --git a/test/monniaux/micro-bunzip/micro-bunzip.c b/test/monniaux/micro-bunzip/micro-bunzip.c index ef307cef..32a4a7a8 100644 --- a/test/monniaux/micro-bunzip/micro-bunzip.c +++ b/test/monniaux/micro-bunzip/micro-bunzip.c @@ -12,6 +12,8 @@ (LGPL) version 2, available at http://www.gnu.org/copyleft/lgpl.html */ +#include "../clock.h" + #include #include #include @@ -84,8 +86,10 @@ static unsigned int get_bits(bunzip_data *bd, char bits_wanted) while (bd->inbufBitCountinbufPos==bd->inbufCount) { + clock_stop(); if(!(bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE))) longjmp(bd->jmpbuf,RETVAL_UNEXPECTED_INPUT_EOF); + clock_start(); bd->inbufPos=0; } /* Avoid 32-bit overflow (dump bit buffer to top of output) */ @@ -359,8 +363,10 @@ extern int read_bunzip_data(bunzip_data *bd) extern void flush_bunzip_outbuf(bunzip_data *bd, int out_fd) { if(bd->outbufPos) { + clock_stop(); if(write(out_fd, bd->outbuf, bd->outbufPos) != bd->outbufPos) longjmp(bd->jmpbuf,RETVAL_UNEXPECTED_OUTPUT_EOF); + clock_start(); bd->outbufPos=0; } } @@ -498,11 +504,13 @@ extern char *uncompressStream(int src_fd, int dst_fd) bunzip_data *bd; int i; + clock_start(); if(!(i=start_bunzip(&bd,src_fd,0,0))) { i=write_bunzip_data(bd,dst_fd,0,0); if(i==RETVAL_LAST_BLOCK && bd->headerCRC==bd->totalCRC) i=RETVAL_OK; } flush_bunzip_outbuf(bd,dst_fd); + clock_stop(); if(bd->dbuf) free(bd->dbuf); free(bd); return bunzip_errors[-i]; @@ -511,6 +519,7 @@ extern char *uncompressStream(int src_fd, int dst_fd) /* Dumb little test thing, decompress stdin to stdout */ int main(int argc, char *argv[]) { - char *c=uncompressStream(0,1); - fprintf(stderr,"\n%s\n", c ? c : "Completed OK"); + char *c=uncompressStream(0,1); + fprintf(stderr, "%s\ncycles=%llu\n", c ? c : "Completed OK", get_total_clock()); + return 0; } -- cgit From 47165c526b865d0f0a1b33fa02e7eccda010c821 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Sat, 26 Jan 2019 11:35:07 +0100 Subject: clock cycles etc. --- test/monniaux/micro-bunzip/Makefile | 10 +++++----- test/monniaux/micro-bunzip/NOTES.txt | 5 +++++ test/monniaux/micro-bunzip/micro-bunzip.c | 4 +++- 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 test/monniaux/micro-bunzip/NOTES.txt (limited to 'test') diff --git a/test/monniaux/micro-bunzip/Makefile b/test/monniaux/micro-bunzip/Makefile index 8916d61f..46a4ec77 100644 --- a/test/monniaux/micro-bunzip/Makefile +++ b/test/monniaux/micro-bunzip/Makefile @@ -1,4 +1,4 @@ -all: testfile.txt testfile.txt.2ccomp testfile.txt.2gcc +all: testfile.txt testfile.txt.2ccomp testfile.txt.2gcc testfile.txt.ccomp.out testfile.txt.gcc.out cmp testfile.txt testfile.txt.2ccomp cmp testfile.txt testfile.txt.2gcc @@ -27,9 +27,9 @@ testfile.txt: micro-bunzip.c # sha512sum micro-bunzip.c >> $@ #x cat micro-bunzip.c >> $@ -testfile.txt.2ccomp: testfile.txt micro-bunzip.ccomp.k1c - bzip2 $@ +testfile.txt.2ccomp testfile.txt.ccomp.out: testfile.txt micro-bunzip.ccomp.k1c + bzip2 testfile.txt.2ccomp 2> testfile.txt.ccomp.out -testfile.txt.2gcc: testfile.txt micro-bunzip.gcc.k1c - bzip2 $@ +testfile.txt.2gcc testfile.txt.gcc.out: testfile.txt micro-bunzip.gcc.k1c + bzip2 testfile.txt.2gcc 2> testfile.txt.gcc.out diff --git a/test/monniaux/micro-bunzip/NOTES.txt b/test/monniaux/micro-bunzip/NOTES.txt new file mode 100644 index 00000000..96ac2432 --- /dev/null +++ b/test/monniaux/micro-bunzip/NOTES.txt @@ -0,0 +1,5 @@ +gcc segfault -O3 + +stdout/stderr in thread-local stuff that does not get correctly handled + +fdopen not available?! diff --git a/test/monniaux/micro-bunzip/micro-bunzip.c b/test/monniaux/micro-bunzip/micro-bunzip.c index 32a4a7a8..33144ba5 100644 --- a/test/monniaux/micro-bunzip/micro-bunzip.c +++ b/test/monniaux/micro-bunzip/micro-bunzip.c @@ -520,6 +520,8 @@ extern char *uncompressStream(int src_fd, int dst_fd) int main(int argc, char *argv[]) { char *c=uncompressStream(0,1); - fprintf(stderr, "%s\ncycles=%llu\n", c ? c : "Completed OK", get_total_clock()); + extern FILE *fdopen(int fd, const char *mode); + FILE *err = fdopen(2, "w"); + fprintf(err, "%s\ncycles=%llu\n", c ? c : "Completed OK", get_total_clock()); return 0; } -- cgit From c6fd1131142f6733d7f49b409bab08443af4365f Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Sat, 26 Jan 2019 11:46:30 +0100 Subject: to test --- test/monniaux/micro-bunzip/Makefile | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test') diff --git a/test/monniaux/micro-bunzip/Makefile b/test/monniaux/micro-bunzip/Makefile index 46a4ec77..a9776b6c 100644 --- a/test/monniaux/micro-bunzip/Makefile +++ b/test/monniaux/micro-bunzip/Makefile @@ -5,6 +5,9 @@ all: testfile.txt testfile.txt.2ccomp testfile.txt.2gcc testfile.txt.ccomp.out t ../clock.gcc.k1c.o : ../clock.c ../cycles.h k1-mbr-gcc -c -Wall -O3 $< -o $@ +micro-bunzip.host: micro-bunzip.c ../clock.c + $(CC) $+ -o $@ + micro-bunzip.ccomp.k1c: micro-bunzip.c ../clock.gcc.k1c.o ../../../ccomp -Wall -O3 $+ -U __SIZEOF_INT128__ -D __SIZE_TYPE__='unsigned long long' -o $@ @@ -33,3 +36,6 @@ testfile.txt.2ccomp testfile.txt.ccomp.out: testfile.txt micro-bunzip.ccomp.k1c testfile.txt.2gcc testfile.txt.gcc.out: testfile.txt micro-bunzip.gcc.k1c bzip2 testfile.txt.2gcc 2> testfile.txt.gcc.out +testfile.txt.2host: testfile.txt micro-bunzip.host + bzip2 testfile.txt.2host + -- cgit From 4ef8259d18add24bb589a185d050f4a524385f1f Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Sun, 27 Jan 2019 16:09:47 +0100 Subject: picosat induces bug in register allocation --- test/monniaux/picosat-965/LICENSE | 20 + test/monniaux/picosat-965/NEWS | 162 + test/monniaux/picosat-965/README | 5 + test/monniaux/picosat-965/VERSION | 1 + test/monniaux/picosat-965/app.c | 1210 ++++ test/monniaux/picosat-965/configure.sh | 150 + test/monniaux/picosat-965/dm_configure.sh | 1 + test/monniaux/picosat-965/main.c | 7 + test/monniaux/picosat-965/make.log | 554 ++ test/monniaux/picosat-965/makefile.in | 59 + test/monniaux/picosat-965/mkconfig.sh | 35 + test/monniaux/picosat-965/picogcnf.c | 165 + test/monniaux/picosat-965/picomcs.c | 334 ++ test/monniaux/picosat-965/picomus.c | 407 ++ test/monniaux/picosat-965/picosat.c | 8506 +++++++++++++++++++++++++++++ test/monniaux/picosat-965/picosat.h | 658 +++ test/monniaux/picosat-965/version.c | 14 + 17 files changed, 12288 insertions(+) create mode 100644 test/monniaux/picosat-965/LICENSE create mode 100644 test/monniaux/picosat-965/NEWS create mode 100644 test/monniaux/picosat-965/README create mode 100644 test/monniaux/picosat-965/VERSION create mode 100644 test/monniaux/picosat-965/app.c create mode 100755 test/monniaux/picosat-965/configure.sh create mode 100755 test/monniaux/picosat-965/dm_configure.sh create mode 100644 test/monniaux/picosat-965/main.c create mode 100644 test/monniaux/picosat-965/make.log create mode 100644 test/monniaux/picosat-965/makefile.in create mode 100755 test/monniaux/picosat-965/mkconfig.sh create mode 100644 test/monniaux/picosat-965/picogcnf.c create mode 100644 test/monniaux/picosat-965/picomcs.c create mode 100644 test/monniaux/picosat-965/picomus.c create mode 100644 test/monniaux/picosat-965/picosat.c create mode 100644 test/monniaux/picosat-965/picosat.h create mode 100644 test/monniaux/picosat-965/version.c (limited to 'test') diff --git a/test/monniaux/picosat-965/LICENSE b/test/monniaux/picosat-965/LICENSE new file mode 100644 index 00000000..96739de2 --- /dev/null +++ b/test/monniaux/picosat-965/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2006 - 2014, Armin Biere, Johannes Kepler University. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. + diff --git a/test/monniaux/picosat-965/NEWS b/test/monniaux/picosat-965/NEWS new file mode 100644 index 00000000..7ad60b53 --- /dev/null +++ b/test/monniaux/picosat-965/NEWS @@ -0,0 +1,162 @@ +news for release 965 since 959 +------------------------------ + +* ADC code works again (spotted by Himanshu Jain) +* include into R projects (with Christoph Muessel) (--rcode) +* fixed 'undefined' + 'ptrdiff_' issues (thanks to Christoph Muessel) +* added 'picosat_set_interrupt' and '-a ' command line option +* fixed various issues pointed out by Stefan Hengelein: + - fixed incremental usage of 'picosat_adjust' + - added CPP fixes (STATS, NO_BINARY_CLAUSE versus TRACE mix-ups) + - removed redundant explicit set to zero on reset +* fixed various usage bugs with 'picomus' (thanks to Stefan Hengelein) +* removed '-fno-strict-aliasing' (thanks to Jerry James) + +news for release 959 since 953 +------------------------------ + +* fixed header comments + +* fixed minor compilation issues + +* fixed unitialized memory access problem for 'picosat_deref_partial' + and another issue with partial models + +* added 'picosat_add_arg' and 'picosat_add_lits' + +* '--plain' and 'picosat_set_plain' to disable failed literal probing + +* new '#define PICOSAT_REENTRANT_API' in 'picosat.h' + +* added manager so no more global variables + (allows multiple instances, requires manager object) + +news for release 951 since 941 +------------------------------ + +* cleaned up code (based on comments by Donald Knuth) + +* lreduce=O(conflicts^.5) + +* added 'picosat_visits' and 'picosat_decisions' + +* added '--partial' command line option + +* added 'picosat_deref_partial' and 'picosat_save_original_clauses' + +* added 'picomcs' as example for MSS computation + +news for release 941 since 936 +------------------------------ + +* added 'picogcnf' + +* added All-SAT mode ('--all' command line option) + +* statistics include time spent in failed literal preprocessing (probing) + +* 'picosat_failed_context' for 'push & pop' + (and tested failed assumptions for 'push & pop') + +* 'picosat_simplify' for forced garbage collection + +* undefined NFL, defined NADC (= failed literals on, ADC's off) + +* 'picosat_push' and 'picosat_pop' (beta version) + +* fixed some issues related to binary clause handling and + generating list of failed assumptions + +news for release 936 since 935 +------------------------------ + +* simple minimal unsatisfiable core (MUS) extractor 'picomus' + (example for using 'picosat_mus_assumptions' and 'picosat_coreclause') + +* added 'picosat_mus_assumptions' + +* added 'picosat_{set_}propagations' + +* new 'int' return value for 'picosat_enable_trace_generation' to + check for trace code being compiled + +news for release 935 since 926 +------------------------------ + +* added 'picosat_failed_assumptions' (plural) + +* new '-A ' command line option + +* fixed failed assumption issues + +* added 'picosat_remove_learned' + +* added 'picosat_reset_{phases,scores}' + +* added 'picosat_set_less_important_lit' + +* added 'picosat_res' + +news for release 926 since 846 +------------------------------ + +* random initial phase (API of 'picosat_set_default_phase' changed) + +* fixed accumulative failed assumption (multiple times) + +* fixed missing original clause in core generation with assumptions + +* fixed debugging code for memory allocation + +* shared library in addition to static library + +* removed potential UNKNOWN result without decision limit + +* added picosat_set_more_important_lit + +* added picosat_coreclause + +* propagation of binary clauses until completion + +* fixed API usage 'assume;sat;sat' + +* literals move to front (LMTF) during traversal of visited clauses + +* switched from inner/outer to Luby style restart scheduling + +* less agressive reduce schedule + +* replaced watched literals with head and tail pointers + +* add 'picosat_failed_assumption', which allows to avoid tracing and core + generation, if one is only interested in assumptions in the core + +* fixed a BUG in the generic iterator code of clauses + (should rarely happen unless you use a very sophisticated malloc lib) + +news for release 846 since 632 +------------------------------ + +* cleaned up assumption handling (actually removed buggy optimization) + +* incremental core generation + +* experimental 'all different constraint' handling as in our FMCAD'08 paper + +* new API calls: + + - picosat_add_ado_lit (add all different object literal) + - picosat_deref_top_level (deref top level assignment) + - picosat_changed (check whether extension was possible) + - picosat_measure_all_calls (per default do not measure adding time) + - picosat_set_prefix (set prefix for messages) + +* 64 bit port (and compilation options) + +* optional NVSIDS visualization code + +* resource controlled failed literal implementation + +* disconnect long clauses satisfied at lower decision level + +* controlling restarts diff --git a/test/monniaux/picosat-965/README b/test/monniaux/picosat-965/README new file mode 100644 index 00000000..05b84396 --- /dev/null +++ b/test/monniaux/picosat-965/README @@ -0,0 +1,5 @@ +These are the sources of the PicoSAT solver. +The preprocessor is not included. +To compile run './configure.sh && make'. +The API is document in 'picosat.h'. +See also 'NEWS' and 'LICENSE'. diff --git a/test/monniaux/picosat-965/VERSION b/test/monniaux/picosat-965/VERSION new file mode 100644 index 00000000..aa5bea4e --- /dev/null +++ b/test/monniaux/picosat-965/VERSION @@ -0,0 +1 @@ +965 diff --git a/test/monniaux/picosat-965/app.c b/test/monniaux/picosat-965/app.c new file mode 100644 index 00000000..19409b61 --- /dev/null +++ b/test/monniaux/picosat-965/app.c @@ -0,0 +1,1210 @@ +#include "picosat.h" + +#include +#include +#include +#include +#include +#include +#include + +#define GUNZIP "gunzip -c %s" +#define BUNZIP2 "bzcat %s" +#define GZIP "gzip -c -f > %s" + +#define NALARM + +FILE * popen (const char *, const char*); +int pclose (FILE *); + +static PicoSAT * picosat; + +static int lineno; +static FILE *input; +static int inputid; +static FILE *output; +static int verbose; +static int sargc; +static char ** sargv; +static char buffer[100]; +static char *bhead = buffer; +static const char *eob = buffer + 80; +static FILE * incremental_rup_file; +static signed char * sol; + +extern void picosat_enter (PicoSAT *); +extern void picosat_leave (PicoSAT *); + +static int +next (void) +{ + int res = getc (input); + if (res == '\n') + lineno++; + + return res; +} + +static const char * +parse (PicoSAT * picosat, int force) +{ + int ch, sign, lit, vars, clauses; + + lineno = 1; + inputid = fileno (input); + +SKIP_COMMENTS: + ch = next (); + if (ch == 'c') + { + while ((ch = next ()) != EOF && ch != '\n') + ; + goto SKIP_COMMENTS; + } + + if (isspace (ch)) + goto SKIP_COMMENTS; + + if (ch != 'p') +INVALID_HEADER: + return "missing or invalid 'p cnf ' header"; + + if (!isspace (next ())) + goto INVALID_HEADER; + + while (isspace (ch = next ())) + ; + + if (ch != 'c' || next () != 'n' || next () != 'f' || !isspace (next ())) + goto INVALID_HEADER; + + while (isspace (ch = next ())) + ; + + if (!isdigit (ch)) + goto INVALID_HEADER; + + vars = ch - '0'; + while (isdigit (ch = next ())) + vars = 10 * vars + (ch - '0'); + + if (!isspace (ch)) + goto INVALID_HEADER; + + while (isspace (ch = next ())) + ; + + if (!isdigit (ch)) + goto INVALID_HEADER; + + clauses = ch - '0'; + while (isdigit (ch = next ())) + clauses = 10 * clauses + (ch - '0'); + + if (!isspace (ch) && ch != '\n' ) + goto INVALID_HEADER; + + if (verbose) + { + fprintf (output, "c parsed header 'p cnf %d %d'\n", vars, clauses); + fflush (output); + } + + picosat_adjust (picosat, vars); + + if (incremental_rup_file) + picosat_set_incremental_rup_file (picosat, incremental_rup_file, vars, clauses); + + lit = 0; +READ_LITERAL: + ch = next (); + + if (ch == 'c') + { + while ((ch = next ()) != EOF && ch != '\n') + ; + goto READ_LITERAL; + } + + if (ch == EOF) + { + if (lit) + return "trailing 0 missing"; + + if (clauses && !force) + return "clause missing"; + + return 0; + } + + if (isspace (ch)) + goto READ_LITERAL; + + sign = 1; + if (ch == '-') + { + sign = -1; + ch = next (); + } + + if (!isdigit (ch)) + return "expected number"; + + lit = ch - '0'; + while (isdigit (ch = next ())) + lit = 10 * lit + (ch - '0'); + + if (!clauses && !force) + return "too many clauses"; + + if (lit) + { + if (lit > vars && !force) + return "maximal variable index exceeded"; + + lit *= sign; + } + else + clauses--; + + picosat_add (picosat, lit); + + goto READ_LITERAL; +} + +static void +bflush (void) +{ + *bhead = 0; + fputs (buffer, output); + fputc ('\n', output); + bhead = buffer; +} + +static void +printi (int i) +{ + char *next; + int l; + +REENTER: + if (bhead == buffer) + *bhead++ = 'v'; + + l = sprintf (bhead, " %d", i); + next = bhead + l; + + if (next >= eob) + { + bflush (); + goto REENTER; + } + else + bhead = next; +} + +static void +printa (PicoSAT * picosat, int partial) +{ + int max_idx = picosat_variables (picosat), i, lit, val; + + assert (bhead == buffer); + + for (i = 1; i <= max_idx; i++) + { + if (partial) + { + val = picosat_deref_partial (picosat, i); + if (!val) + continue; + } + else + val = picosat_deref (picosat, i); + lit = (val > 0) ? i : -i; + printi (lit); + } + + printi (0); + if (bhead > buffer) + bflush (); +} + +static void +blocksol (PicoSAT * picosat) +{ + int max_idx = picosat_variables (picosat), i; + + if (!sol) + { + sol = malloc (max_idx + 1); + memset (sol, 0, max_idx + 1); + } + + for (i = 1; i <= max_idx; i++) + sol[i] = (picosat_deref (picosat, i) > 0) ? 1 : -1; + + for (i = 1; i <= max_idx; i++) + picosat_add (picosat, (sol[i] < 0) ? i : -i); + + picosat_add (picosat, 0); +} + +static int +has_suffix (const char *str, const char *suffix) +{ + const char *tmp = strstr (str, suffix); + if (!tmp) + return 0; + + return str + strlen (str) - strlen (suffix) == tmp; +} + +static void +write_core_variables (PicoSAT * picosat, FILE * file) +{ + int i, max_idx = picosat_variables (picosat), count = 0; + for (i = 1; i <= max_idx; i++) + if (picosat_corelit (picosat, i)) + { + fprintf (file, "%d\n", i); + count++; + } + + if (verbose) + fprintf (output, "c found and wrote %d core variables\n", count); +} + +static int +next_assumption (int start) +{ + char * arg, c; + int res; + res = start + 1; + while (res < sargc) + { + arg = sargv[res++]; + if (!strcmp (arg, "-a")) + { + assert (res < sargc); + break; + } + + if (arg[0] == '-') { + c = arg[1]; + if (c == 'l' || c == 'i' || c == 's' || c == 'o' || c == 't' || + c == 'T' || c == 'r' || c == 'R' || c == 'c' || c == 'V' || + c == 'U' || c == 'A') res++; + } + } + if (res >= sargc) res = 0; + return res; +} + +static void +write_failed_assumptions (PicoSAT * picosat, FILE * file) +{ + int i, lit, count = 0; +#ifndef NDEBUG + int max_idx = picosat_variables (picosat); +#endif + i = 0; + while ((i = next_assumption (i))) { + lit = atoi (sargv[i]); + if (!picosat_failed_assumption (picosat, lit)) continue; + fprintf (file, "%d\n", lit); + count++; + } + if (verbose) + fprintf (output, "c found and wrote %d failed assumptions\n", count); +#ifndef NDEBUG + for (i = 1; i <= max_idx; i++) + if (picosat_failed_assumption (picosat, i)) + count--; +#endif + assert (!count); +} + +static void +write_to_file (PicoSAT * picosat, + const char *name, + const char *type, + void (*writer) (PicoSAT *, FILE *)) +{ + int pclose_file, zipped = has_suffix (name, ".gz"); + FILE *file; + char *cmd; + + if (zipped) + { +#if ZIP + cmd = malloc (strlen (GZIP) + strlen (name)); + sprintf (cmd, GZIP, name); + file = popen (cmd, "w"); + free (cmd); + pclose_file = 1; +#else + file = NULL; +#endif + } + else + { + file = fopen (name, "w"); + pclose_file = 0; + } + + if (file) + { + if (verbose) + fprintf (output, + "c\nc writing %s%s to '%s'\n", + zipped ? "gzipped " : "", type, name); + + writer (picosat, file); + + if (pclose_file) + pclose (file); + else + fclose (file); + } + else + fprintf (output, "*** picosat: can not write to '%s'\n", name); +} + +static int catched; + +static void (*sig_int_handler); +static void (*sig_segv_handler); +static void (*sig_abrt_handler); +static void (*sig_term_handler); +#ifndef NALLSIGNALS +static void (*sig_kill_handler); +static void (*sig_xcpu_handler); +static void (*sig_xfsz_handler); +#endif + +static void +resetsighandlers (void) +{ + (void) signal (SIGINT, sig_int_handler); + (void) signal (SIGSEGV, sig_segv_handler); + (void) signal (SIGABRT, sig_abrt_handler); + (void) signal (SIGTERM, sig_term_handler); +#ifndef NALLSIGNALS + (void) signal (SIGKILL, sig_kill_handler); + (void) signal (SIGXCPU, sig_xcpu_handler); + (void) signal (SIGXFSZ, sig_xfsz_handler); +#endif +} + +static int time_limit_in_seconds; +static void (*sig_alarm_handler); +static int ought_to_be_interrupted, interrupt_notified; + +static void +alarm_triggered (int sig) +{ + (void) sig; + assert (sig == SIGALRM); + assert (time_limit_in_seconds); + assert (!ought_to_be_interrupted); + ought_to_be_interrupted = 1; + assert (!interrupt_notified); +} + +static int +interrupt_call_back (void * dummy) +{ + (void) dummy; + if (!ought_to_be_interrupted) + return 0; + if (!interrupt_notified) + { + if (verbose) + { + picosat_message (picosat, 1, ""); + picosat_message (picosat, 1, + "*** TIME LIMIT OF %d SECONDS REACHED ***", + time_limit_in_seconds); + picosat_message (picosat, 1, ""); + } + interrupt_notified = 1; + } + return 1; +} + +static void +setalarm () +{ +#ifndef NALARM + assert (time_limit_in_seconds > 0); + sig_alarm_handler = signal (SIGALRM, alarm_triggered); + alarm (time_limit_in_seconds); + assert (picosat); + picosat_set_interrupt (picosat, 0, interrupt_call_back); +#endif +} + +static void +resetalarm () +{ + assert (time_limit_in_seconds > 0); + (void) signal (SIGALRM, sig_term_handler); +} + +static void +message (int sig) +{ + picosat_message (picosat, 1, ""); + picosat_message (picosat, 1, "*** CAUGHT SIGNAL %d ***", sig); + picosat_message (picosat, 1, ""); +} + +static void +catch (int sig) +{ + if (!catched) + { + message (sig); + catched = 1; + picosat_stats (picosat); + message (sig); + } + + resetsighandlers (); + raise (sig); +} + +static void +setsighandlers (void) +{ + sig_int_handler = signal (SIGINT, catch); + sig_segv_handler = signal (SIGSEGV, catch); + sig_abrt_handler = signal (SIGABRT, catch); + sig_term_handler = signal (SIGTERM, catch); +#ifndef NALLSIGNALS + sig_kill_handler = signal (SIGKILL, catch); + sig_xcpu_handler = signal (SIGXCPU, catch); + sig_xfsz_handler = signal (SIGXFSZ, catch); +#endif +} + +#define USAGE \ +"usage: picosat [