diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-08-02 21:19:14 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-08-02 21:19:14 +0300 |
| commit | c671d6612be0fb28eea498246c39bb5032afa872 (patch) | |
| tree | 9b1ccb07208c5659ed865cbfd299ac40216dc6ab | |
| parent | 9251fddfdfb11b9e1b2dff643aa20ec82e9f7036 (diff) | |
| download | copyjit-c671d6612be0fb28eea498246c39bb5032afa872.tar.gz copyjit-c671d6612be0fb28eea498246c39bb5032afa872.zip | |
add some basic checks
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 9 | ||||
| -rw-r--r-- | ops/common.h | 4 | ||||
| -rwxr-xr-x | tests/check | bin | 0 -> 1261584 bytes | |||
| -rw-r--r-- | tests/check.c | 150 |
5 files changed, 160 insertions, 4 deletions
@@ -8,6 +8,7 @@ lib/decls.h lib/defns.h lib/ops.h lib/*.d +tests/*.d build copyjit !include/copyjit @@ -68,6 +68,7 @@ ARCH != uname -m LINT = $(COMPILE) $(LINTFLAGS) +TEST_OBJS != ./scripts/gen-deps --sources tests/check.c OBJS != ./scripts/gen-deps --sources "$(SOURCES)" OPS != ./scripts/gen-ops --ops "$(OP_SOURCES)" IMMS != ./scripts/gen-ops --imms "$(IMM_SOURCES)" @@ -94,8 +95,11 @@ docs: @doxygen docs/doxygen.conf .PHONY: check -check: copyjit - ./tests/check.sh +check: tests/check + ./tests/check + +tests/check: $(OBJS) $(TEST_OBJS) + $(COMPILE) build/tests/check.o build/src/copyjit.o -o tests/check copyjit: $(OBJS) $(COMPILE) $(OBJS) -o $@ @@ -111,6 +115,7 @@ copyjit: $(OBJS) clean: @$(RM) -r build copyjit lib/gen/* lib/*.bin lib/*.d lib/empty lib/prune deps.mk @$(RM) -r lib/*decls.h lib/*defns.h lib/ops.h lib/imm.h + @$(RM) tests/check .PHONY: clean_docs clean_docs: diff --git a/ops/common.h b/ops/common.h index 6b124b3..6d3119a 100644 --- a/ops/common.h +++ b/ops/common.h @@ -17,9 +17,9 @@ typedef reg_t (*op_call)(reg_t *sp, reg_t a, reg_t x, reg_t y, reg_t o); #define JUMP(target, sp, a, x, y, o) \ return CALL(target, sp, a, x, y, o); -#define BRANCH(target, cond, sp, a, x, y, o) \ +#define BRANCH(target, cond, sp, a, x, y, o) \ return ((op_call)((cond) ? (void *)(target) : (void *)&__next_op)) \ - ((sp), (a), (x), (y), (o)); \ + ((sp), (a), (x), (y), (o)); \ #define DEFINE_OP(name) reg_t _op(reg_t *sp, reg_t a, reg_t x, reg_t y, reg_t o) diff --git a/tests/check b/tests/check Binary files differnew file mode 100755 index 0000000..b079a57 --- /dev/null +++ b/tests/check diff --git a/tests/check.c b/tests/check.c new file mode 100644 index 0000000..8f4c6de --- /dev/null +++ b/tests/check.c @@ -0,0 +1,150 @@ +#include <assert.h> +#include <stddef.h> + +#include "../src/copyjit.h" + +#define IMMEDIATES 1000 + +static void check_li() +{ + // x + for (size_t i = 0; i < IMMEDIATES; ++i) { + ctx_t ctx; + compile_start(&ctx); + compile_fast_lix(&ctx, i); + compile_end(&ctx); + compile_finish(&ctx); + + assert(run(&ctx) == i); + } + + // y + for (size_t i = 0; i < IMMEDIATES; ++i) { + ctx_t ctx; + compile_start(&ctx); + // actual instruction under test + compile_fast_liy(&ctx, i); + + // juggling to get stuff into the return register x + compile_fast_lix(&ctx, 0); + compile_add(&ctx); + compile_movxa(&ctx); + + compile_end(&ctx); + compile_finish(&ctx); + + assert(run(&ctx) == i); + } + + // o + for (size_t i = 0; i < IMMEDIATES; ++i) { + ctx_t ctx; + compile_start(&ctx); + // actual instruction under test + compile_fast_lio(&ctx, i); + + // juggling to get stuff into the return register x + compile_movxo(&ctx); + + compile_end(&ctx); + compile_finish(&ctx); + + assert(run(&ctx) == i); + } + + // a + for (size_t i = 0; i < IMMEDIATES; ++i) { + ctx_t ctx; + compile_start(&ctx); + // actual instruction under test + compile_fast_lia(&ctx, i); + + // juggling to get stuff into the return register x + compile_movxa(&ctx); + + compile_end(&ctx); + compile_finish(&ctx); + + assert(run(&ctx) == i); + } +} + +static void check_add() +{ + // x + for (size_t i = 0; i < IMMEDIATES; ++i) { + ctx_t ctx; + compile_start(&ctx); + + compile_fast_lix(&ctx, 0); + compile_fast_addix(&ctx, i); + + compile_end(&ctx); + compile_finish(&ctx); + + assert(run(&ctx) == i); + } + + // y + for (size_t i = 0; i < IMMEDIATES; ++i) { + ctx_t ctx; + compile_start(&ctx); + + compile_fast_liy(&ctx, 0); + compile_fast_addiy(&ctx, i); + + compile_fast_lix(&ctx, 0); + compile_add(&ctx); + compile_movxa(&ctx); + + compile_end(&ctx); + compile_finish(&ctx); + + assert(run(&ctx) == i); + } + + // o + for (size_t i = 0; i < IMMEDIATES; ++i) { + ctx_t ctx; + compile_start(&ctx); + + compile_fast_lio(&ctx, 0); + compile_fast_addio(&ctx, i); + + compile_movxo(&ctx); + + compile_end(&ctx); + compile_finish(&ctx); + + assert(run(&ctx) == i); + } + + // a + for (size_t i = 0; i < IMMEDIATES; ++i) { + ctx_t ctx; + compile_start(&ctx); + + compile_fast_lia(&ctx, 0); + compile_fast_addia(&ctx, i); + + compile_movxa(&ctx); + + compile_end(&ctx); + compile_finish(&ctx); + + assert(run(&ctx) == i); + } +} + +static void check_branch() +{ + /* oh yeah, I don't support forward references (yet), so this is a bit + * tricky */ +} + +int main() +{ + check_li(); + check_add(); + check_branch(); +} |
