From f9a0dd579dc72b09c4ebb036df0b59891412163d Mon Sep 17 00:00:00 2001 From: David Monniaux 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 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