diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-07-13 20:56:26 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-07-13 20:56:26 +0300 |
commit | ae9e103995c1d809be7b8717905593e7dbbf9d17 (patch) | |
tree | 0ceaf6ee66e1d67bb8d0b9dd6f37b5687e4c2f09 | |
parent | e618924df98d4ee5037db86c768a8c8014e49c4c (diff) | |
download | ejit-ae9e103995c1d809be7b8717905593e7dbbf9d17.tar.gz ejit-ae9e103995c1d809be7b8717905593e7dbbf9d17.zip |
bytecode tests pass
99 files changed, 2188 insertions, 1839 deletions
@@ -1,3 +1,5 @@ + Check in compiler backend that nobody accidentally uses 64bit values on 32bit systems + (MAYBE) Check that there aren't duplicate destinations in operand list? ++ Darn, the return type doesn't really work with 32bit systems, should fix that +somehow diff --git a/include/ejit/ejit.h b/include/ejit/ejit.h index eeac089..ce7260b 100644 --- a/include/ejit/ejit.h +++ b/include/ejit/ejit.h @@ -309,6 +309,7 @@ void ejit_escapei(struct ejit_func *s, ejit_escape_t f, size_t argc, void ejit_escapei_f(struct ejit_func *s, ejit_escape_f_t f, size_t argc, const struct ejit_operand args[argc]); +void ejit_ret(struct ejit_func *s); void ejit_retr(struct ejit_func *s, struct ejit_gpr r0); void ejit_retr_f(struct ejit_func *s, struct ejit_fpr r0); void ejit_reti(struct ejit_func *s, long i); @@ -319,6 +320,7 @@ void ejit_retval_f(struct ejit_func *s, struct ejit_fpr r0); /* move from r1 to r0 */ void ejit_movi(struct ejit_func *s, struct ejit_gpr r0, int64_t i); +void ejit_movi_f(struct ejit_func *s, struct ejit_fpr f0, double i); void ejit_movr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1); void ejit_movr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1); @@ -465,11 +467,6 @@ void ejit_sti_16(struct ejit_func *s, struct ejit_gpr r0, void *p); void ejit_sti_32(struct ejit_func *s, struct ejit_gpr r0, void *p); void ejit_sti_64(struct ejit_func *s, struct ejit_gpr r0, void *p); -void ejit_sti_u8(struct ejit_func *s, struct ejit_gpr r0, void *p); -void ejit_sti_u16(struct ejit_func *s, struct ejit_gpr r0, void *p); -void ejit_sti_u32(struct ejit_func *s, struct ejit_gpr r0, void *p); -void ejit_sti_u64(struct ejit_func *s, struct ejit_gpr r0, void *p); - void ejit_sti_f(struct ejit_func *s, struct ejit_fpr r0, void *p); void ejit_sti_d(struct ejit_func *s, struct ejit_fpr r0, void *p); @@ -517,6 +514,24 @@ static inline void ejit_stxi_ptr(struct ejit_func *s, struct ejit_gpr r0, double: ejit_stxi_d, \ default: ejit_stxi_ptr)((f), (r0), (r1), (o)) +void ejit_stxr_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2); + +void ejit_stxr_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2); + +void ejit_stxr_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2); + +void ejit_stxr_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2); + +void ejit_stxr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, + struct ejit_gpr r2); + +void ejit_stxr_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, + struct ejit_gpr r2); + void ejit_extr_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1); void ejit_extr_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1); void ejit_extr_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1); @@ -556,28 +571,54 @@ void ejit_divr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, void ejit_divr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1, struct ejit_fpr r2); +void ejit_remr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2); + +void ejit_remr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2); + void ejit_lshi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o); void ejit_lshr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2); void ejit_rshi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o); +void ejit_rshi_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + int64_t o); void ejit_rshr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2); +void ejit_rshr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2); void ejit_andr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2); void ejit_andi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o); -void ejit_comr(struct ejit_func *f, struct ejit_gpr r0, struct ejit_gpr r1); +void ejit_orr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2); +void ejit_ori(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + int64_t o); + +void ejit_xori(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + int64_t o); +void ejit_xorr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2); + +void ejit_comr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1); void ejit_negr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1); +void ejit_negr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1); void ejit_eqr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2); void ejit_eqr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, struct ejit_fpr r2); +void ejit_ner(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2); +void ejit_ner_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, + struct ejit_fpr r2); + void ejit_gtr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2); void ejit_gtr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, @@ -604,6 +645,11 @@ void ejit_ler(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, void ejit_ler_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, struct ejit_fpr r2); +void ejit_truncr_d_32(struct ejit_func *s, struct ejit_gpr r0, + struct ejit_fpr r1); +void ejit_truncr_d_64(struct ejit_func *s, struct ejit_gpr r0, + struct ejit_fpr r1); + struct ejit_reloc ejit_bltr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1); struct ejit_reloc ejit_bner(struct ejit_func *s, struct ejit_gpr r0, diff --git a/scripts/gen-tests b/scripts/gen-tests index 542bb7b..f014a30 100755 --- a/scripts/gen-tests +++ b/scripts/gen-tests @@ -1,6 +1,6 @@ #!/bin/sh -PREFIX=JIT_TEST +PREFIX=JIT_TESTS for s in ${@} do src="${s#*/}" diff --git a/src/common.h b/src/common.h index e9f0b69..1e08961 100644 --- a/src/common.h +++ b/src/common.h @@ -6,6 +6,7 @@ enum ejit_opcode { MOVI, + MOVI_F, MOVR, MOVR_F, @@ -46,10 +47,6 @@ enum ejit_opcode { STI16, STI32, STI64, - STIU8, - STIU16, - STIU32, - STIU64, STIF, STID, @@ -57,13 +54,16 @@ enum ejit_opcode { STXI16, STXI32, STXI64, - STXIU8, - STXIU16, - STXIU32, - STXIU64, STXIF, STXID, + STXR8, + STXR16, + STXR32, + STXR64, + STXRF, + STXRD, + EXTR8, EXTR16, EXTR32, @@ -88,17 +88,32 @@ enum ejit_opcode { DIVR_U, DIVR_F, - NEGR, + REMR, + REMR_U, + COMR, + NEGR, + NEGR_F, LSHI, LSHR, RSHI, + RSHI_U, RSHR, + RSHR_U, ANDR, ANDI, + ORR, + ORI, + + XORR, + XORI, + + TRUNCR_D_32, + TRUNCR_D_64, + EQR, NER, GTR, @@ -197,6 +197,36 @@ void ejit_retval_f(struct ejit_func *s, struct ejit_fpr r0) emit_insn_i(s, RETVAL_F, r0.f, 0, 0); } +void ejit_sti_8(struct ejit_func *s, struct ejit_gpr r0, void *p) +{ + emit_insn_p(s, STI8, r0.r, 0, p); +} + +void ejit_sti_16(struct ejit_func *s, struct ejit_gpr r0, void *p) +{ + emit_insn_p(s, STI16, r0.r, 0, p); +} + +void ejit_sti_32(struct ejit_func *s, struct ejit_gpr r0, void *p) +{ + emit_insn_p(s, STI32, r0.r, 0, p); +} + +void ejit_sti_64(struct ejit_func *s, struct ejit_gpr r0, void *p) +{ + emit_insn_p(s, STI64, r0.r, 0, p); +} + +void ejit_sti_f(struct ejit_func *s, struct ejit_fpr r0, void *p) +{ + emit_insn_p(s, STIF, r0.f, 0, p); +} + +void ejit_sti_d(struct ejit_func *s, struct ejit_fpr r0, void *p) +{ + emit_insn_p(s, STID, r0.f, 0, p); +} + void ejit_stxi_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { @@ -233,6 +263,42 @@ void ejit_stxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, emit_insn_i(s, STXID, r0.f, r1.r, o); } +void ejit_stxr_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, STXR8, r0.r, r1.r, r2.r); +} + +void ejit_stxr_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, STXR16, r0.r, r1.r, r2.r); +} + +void ejit_stxr_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, STXR32, r0.r, r1.r, r2.r); +} + +void ejit_stxr_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, STXR64, r0.r, r1.r, r2.r); +} + +void ejit_stxr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, STXRF, r0.f, r1.r, r2.r); +} + +void ejit_stxr_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, STXRD, r0.f, r1.r, r2.r); +} + void ejit_ldi_i8(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_p(s, LDI8, r0.r, 0, p); @@ -403,6 +469,11 @@ void ejit_ldxr_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, emit_insn_r(s, LDXRD, r0.f, r1.r, r2.r); } +void ejit_ret(struct ejit_func *s) +{ + emit_insn_i(s, END, 0, 0, 0); +} + void ejit_retr(struct ejit_func *s, struct ejit_gpr r0) { emit_insn_r(s, RETR, r0.r, 0, 0); @@ -500,6 +571,12 @@ void ejit_mulr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, emit_insn_r(s, MULR, r0.r, r1.r, r2.r); } +void ejit_mulr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1, + struct ejit_fpr r2) +{ + emit_insn_r(s, MULR_F, r0.f, r1.f, r2.f); +} + void ejit_divr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { @@ -518,6 +595,18 @@ void ejit_divr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1, emit_insn_r(s, DIVR_F, r0.f, r1.f, r2.f); } +void ejit_remr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, REMR, r0.r, r1.r, r2.r); +} + +void ejit_remr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, REMR_U, r0.r, r1.r, r2.r); +} + void ejit_lshi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { @@ -536,12 +625,24 @@ void ejit_rshi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, emit_insn_i(s, RSHI, r0.r, r1.r, o); } +void ejit_rshi_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + int64_t o) +{ + emit_insn_i(s, RSHI_U, r0.r, r1.r, o); +} + void ejit_rshr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_r(s, RSHR, r0.r, r1.r, r2.r); } +void ejit_rshr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, RSHR_U, r0.r, r1.r, r2.r); +} + void ejit_andr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { @@ -554,6 +655,30 @@ void ejit_andi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, emit_insn_i(s, ANDI, r0.r, r1.r, o); } +void ejit_orr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, ORR, r0.r, r1.r, r2.r); +} + +void ejit_ori(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + int64_t o) +{ + emit_insn_i(s, ORI, r0.r, r1.r, o); +} + +void ejit_xorr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, XORR, r0.r, r1.r, r2.r); +} + +void ejit_xori(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + int64_t o) +{ + emit_insn_i(s, XORI, r0.r, r1.r, o); +} + void ejit_comr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { emit_insn_i(s, COMR, r0.r, r1.r, 0); @@ -564,11 +689,21 @@ void ejit_negr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) emit_insn_i(s, NEGR, r0.r, r1.r, 0); } +void ejit_negr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1) +{ + emit_insn_i(s, NEGR_F, r0.f, r1.f, 0); +} + void ejit_movi(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { emit_insn_i(s, MOVI, r0.r, 0, o); } +void ejit_movi_f(struct ejit_func *s, struct ejit_fpr r0, double o) +{ + emit_insn_f(s, MOVI_F, r0.f, 0, o); +} + void ejit_movr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { if (r0.r == r1.r) @@ -577,6 +712,14 @@ void ejit_movr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) emit_insn_i(s, MOVR, r0.r, r1.r, 0); } +void ejit_movr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1) +{ + if (r0.f == r1.f) + return; + + emit_insn_i(s, MOVR_F, r0.f, r1.f, 0); +} + void ejit_eqr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { @@ -589,6 +732,18 @@ void ejit_eqr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, emit_insn_r(s, EQR_F, r0.r, r1.f, r2.f); } +void ejit_ner(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, NER, r0.r, r1.r, r2.r); +} + +void ejit_ner_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, + struct ejit_fpr r2) +{ + emit_insn_r(s, NER_F, r0.r, r1.f, r2.f); +} + void ejit_gtr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { @@ -610,19 +765,19 @@ void ejit_gtr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, void ejit_ltr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { - emit_insn_r(s, GER, r0.r, r2.r, r1.r); + emit_insn_r(s, GTR, r0.r, r2.r, r1.r); } void ejit_ltr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { - emit_insn_r(s, GER_U, r0.r, r2.r, r1.r); + emit_insn_r(s, GTR_U, r0.r, r2.r, r1.r); } void ejit_ltr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, struct ejit_fpr r2) { - emit_insn_r(s, GER_F, r0.r, r2.f, r1.f); + emit_insn_r(s, GTR_F, r0.r, r2.f, r1.f); } void ejit_ger(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, @@ -646,19 +801,31 @@ void ejit_ger_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, void ejit_ler(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { - emit_insn_r(s, GTR, r0.r, r2.r, r1.r); + emit_insn_r(s, GER, r0.r, r2.r, r1.r); } void ejit_ler_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { - emit_insn_r(s, GTR_U, r0.r, r2.r, r1.r); + emit_insn_r(s, GER_U, r0.r, r2.r, r1.r); } void ejit_ler_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, struct ejit_fpr r2) { - emit_insn_r(s, GTR_F, r0.r, r2.f, r1.f); + emit_insn_r(s, GER_F, r0.r, r2.f, r1.f); +} + +void ejit_truncr_d_32(struct ejit_func *s, struct ejit_gpr r0, + struct ejit_fpr r1) +{ + emit_insn_i(s, TRUNCR_D_32, r0.r, r1.f, 0); +} + +void ejit_truncr_d_64(struct ejit_func *s, struct ejit_gpr r0, + struct ejit_fpr r1) +{ + emit_insn_i(s, TRUNCR_D_64, r0.r, r1.f, 0); } struct ejit_reloc ejit_bner(struct ejit_func *s, struct ejit_gpr r0, @@ -942,12 +1109,13 @@ long ejit_run_interp(struct ejit_func *f, size_t argc, return ejit_interp(f, argc, args, state, true, NULL).r; } -long ejit_run_func(struct ejit_func *f, size_t argc, struct ejit_arg args[argc]) +int64_t ejit_run_func(struct ejit_func *f, size_t argc, + struct ejit_arg args[argc]) { assert(f->size && "trying to run a function that hasn't been compiled"); assert(f->rtype == EJIT_VOID || ejit_int_type(f->rtype)); if (f->arena) - return ((ejit_escape_t)f->arena)(argc, args); + return (int64_t)((ejit_escape_t)f->arena)(argc, args); struct interp_state state = create_interp_state(); long r = ejit_interp(f, argc, args, &state, true, NULL).r; diff --git a/src/interp.c b/src/interp.c index 30a7672..a86b754 100644 --- a/src/interp.c +++ b/src/interp.c @@ -10,6 +10,7 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, { static void *labels[OPCODE_COUNT] = { [MOVI] = &&MOVI, + [MOVI_F] = &&MOVI_F, [MOVR] = &&MOVR, [MOVR_F] = &&MOVR_F, @@ -31,21 +32,34 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, [SUBI] = &&SUBI, [MULR] = &&MULR, + [MULR_F] = &&MULR_F, [DIVR] = &&DIVR, [DIVR_U] = &&DIVR_U, [DIVR_F] = &&DIVR_F, + [REMR] = &&REMR, + [REMR_U] = &&REMR_U, + [LSHI] = &&LSHI, [LSHR] = &&LSHR, [RSHI] = &&RSHI, [RSHR] = &&RSHR, + [RSHI_U] = &&RSHI_U, + [RSHR_U] = &&RSHR_U, [ANDR] = &&ANDR, [ANDI] = &&ANDI, + [ORR] = &&ORR, + [ORI] = &&ORI, + + [XORR] = &&XORR, + [XORI] = &&XORI, + [COMR] = &&COMR, [NEGR] = &&NEGR, + [NEGR_F] = &&NEGR_F, [EQR] = &&EQR, [EQR_F] = &&EQR_F, @@ -61,6 +75,13 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, [GER_U] = &&GER_U, [GER_F] = &&GER_F, + [STI8] = &&STI8, + [STI16] = &&STI16, + [STI32] = &&STI32, + [STI64] = &&STI64, + [STIF] = &&STIF, + [STID] = &&STID, + [STXI8] = &&STXI8, [STXI16] = &&STXI16, [STXI32] = &&STXI32, @@ -68,6 +89,13 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, [STXIF] = &&STXIF, [STXID] = &&STXID, + [STXR8] = &&STXR8, + [STXR16] = &&STXR16, + [STXR32] = &&STXR32, + [STXR64] = &&STXR64, + [STXRF] = &&STXRF, + [STXRD] = &&STXRD, + [LDI8] = &&LDI8, [LDI16] = &&LDI16, [LDI32] = &&LDI32, @@ -101,6 +129,9 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, [LDXRF] = &&LDXRF, [LDXRD] = &&LDXRD, + [TRUNCR_D_32] = &&TRUNCR_D_32, + [TRUNCR_D_64] = &&TRUNCR_D_64, + [BNER] = &&BNER, [BNEI] = &&BNEI, [BNER_F] = &&BNER_F, @@ -202,6 +233,10 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, gpr[i.r0] = i.o; DISPATCH(); + DO(MOVI_F); + fpr[i.r0] = i.d; + DISPATCH(); + DO(MOVR); gpr[i.r0] = gpr[i.r1]; DISPATCH(); @@ -266,6 +301,10 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, gpr[i.r0] = gpr[i.r1] * gpr[i.r2]; DISPATCH(); + DO(MULR_F); + fpr[i.r0] = fpr[i.r1] * fpr[i.r2]; + DISPATCH(); + DO(DIVR); gpr[i.r0] = gpr[i.r1] / gpr[i.r2]; DISPATCH(); @@ -274,6 +313,14 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, gpr[i.r0] = (uint64_t)gpr[i.r1] / (uint64_t)gpr[i.r2]; DISPATCH(); + DO(REMR); + gpr[i.r0] = gpr[i.r1] % gpr[i.r2]; + DISPATCH(); + + DO(REMR_U); + gpr[i.r0] = (uint64_t)gpr[i.r1] % (uint64_t)gpr[i.r2]; + DISPATCH(); + DO(DIVR_F); fpr[i.r0] = fpr[i.r1] / fpr[i.r2]; DISPATCH(); @@ -294,6 +341,14 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, gpr[i.r0] = gpr[i.r1] >> gpr[i.r2]; DISPATCH(); + DO(RSHI_U); + gpr[i.r0] = (uint64_t)gpr[i.r1] >> i.o; + DISPATCH(); + + DO(RSHR_U); + gpr[i.r0] = (uint64_t)gpr[i.r1] >> gpr[i.r2]; + DISPATCH(); + DO(ANDR); gpr[i.r0] = gpr[i.r1] & gpr[i.r2]; DISPATCH(); @@ -302,6 +357,22 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, gpr[i.r0] = gpr[i.r1] & i.o; DISPATCH(); + DO(ORR); + gpr[i.r0] = gpr[i.r1] | gpr[i.r2]; + DISPATCH(); + + DO(ORI); + gpr[i.r0] = gpr[i.r1] | i.o; + DISPATCH(); + + DO(XORR); + gpr[i.r0] = gpr[i.r1] ^ gpr[i.r2]; + DISPATCH(); + + DO(XORI); + gpr[i.r0] = gpr[i.r1] ^ i.o; + DISPATCH(); + DO(COMR); gpr[i.r0] = ~gpr[i.r1]; DISPATCH(); @@ -310,6 +381,10 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, gpr[i.r0] = -gpr[i.r1]; DISPATCH(); + DO(NEGR_F); + fpr[i.r0] = -fpr[i.r1]; + DISPATCH(); + DO(EQR); gpr[i.r0] = gpr[i.r1] == gpr[i.r2]; DISPATCH(); @@ -350,6 +425,36 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, gpr[i.r0] = fpr[i.r1] >= fpr[i.r2]; DISPATCH(); + DO(STI8); + int8_t *addr = (int8_t *)(i.p); + *addr = gpr[i.r0]; + DISPATCH(); + + DO(STI16); + int16_t *addr = (int16_t *)(i.p); + *addr = gpr[i.r0]; + DISPATCH(); + + DO(STI32); + int32_t *addr = (int32_t *)(i.p); + *addr = gpr[i.r0]; + DISPATCH(); + + DO(STI64); + int64_t *addr = (int64_t *)(i.p); + *addr = gpr[i.r0]; + DISPATCH(); + + DO(STIF); + float *addr = (float *)(i.p); + *addr = fpr[i.r0]; + DISPATCH(); + + DO(STID); + double *addr = (double *)(i.p); + *addr = fpr[i.r0]; + DISPATCH(); + DO(STXI8); int8_t *addr = (int8_t *)(gpr[i.r1] + i.o); *addr = gpr[i.r0]; @@ -380,6 +485,36 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, *addr = fpr[i.r0]; DISPATCH(); + DO(STXR8); + int8_t *addr = (int8_t *)(gpr[i.r1] + gpr[i.r2]); + *addr = gpr[i.r0]; + DISPATCH(); + + DO(STXR16); + int16_t *addr = (int16_t *)(gpr[i.r1] + gpr[i.r2]); + *addr = gpr[i.r0]; + DISPATCH(); + + DO(STXR32); + int32_t *addr = (int32_t *)(gpr[i.r1] + gpr[i.r2]); + *addr = gpr[i.r0]; + DISPATCH(); + + DO(STXR64); + int64_t *addr = (int64_t *)(gpr[i.r1] + gpr[i.r2]); + *addr = gpr[i.r0]; + DISPATCH(); + + DO(STXRF); + float *addr = (float *)(gpr[i.r1] + gpr[i.r2]); + *addr = fpr[i.r0]; + DISPATCH(); + + DO(STXRD); + double *addr = (double *)(gpr[i.r1] + gpr[i.r2]); + *addr = fpr[i.r0]; + DISPATCH(); + DO(LDI8); int8_t *addr = (int8_t *)i.p; gpr[i.r0] = *addr; @@ -530,6 +665,14 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, fpr[i.r0] = *addr; DISPATCH(); + DO(TRUNCR_D_32); + gpr[i.r0] = (int32_t)fpr[i.r1]; + DISPATCH(); + + DO(TRUNCR_D_64); + gpr[i.r0] = (int64_t)fpr[i.r1]; + DISPATCH(); + DO(BNER); if (gpr[i.r1] != gpr[i.r2]) JUMP(i.r0); diff --git a/tests/divr.c b/tests/divr.c deleted file mode 100644 index e16a8bf..0000000 --- a/tests/divr.c +++ /dev/null @@ -1,152 +0,0 @@ -#include <ejit/ejit.h> -#include <assert.h> -#include "do_jit.h" - -int main() -{ - struct ejit_operand operands[2] = { - EJIT_OPERAND_GPR(0, EJIT_TYPE(long)), - EJIT_OPERAND_GPR(1, EJIT_TYPE(long)) - }; - struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); - - ejit_divr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); - ejit_retr(f, EJIT_GPR(0)); - - ejit_select_compile_func(f, 2, 0, EJIT_USE64(long), do_jit); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x7fffffff, long), - EJIT_ARG(1, long)) == 0x7fffffff); - - assert(ejit_run_func_2(f, - EJIT_ARG(1, long), - EJIT_ARG(0x7fffffff, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x80000000, long), - EJIT_ARG(1, long)) == 0x80000000); - - assert(ejit_run_func_2(f, - EJIT_ARG(1, long), - EJIT_ARG(0x80000000, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x7fffffff, long), - EJIT_ARG(2, long)) == 0x3fffffff); - - assert(ejit_run_func_2(f, - EJIT_ARG(2, long), - EJIT_ARG(0x7fffffff, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(2, long), - EJIT_ARG(0x80000000, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x7fffffff, long), - EJIT_ARG(0x80000000, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(0, long), - EJIT_ARG(0x7fffffff, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(0xffffffff, long), - EJIT_ARG(0xffffffff, long)) == 1); - -#warning "Some 32bit handling still unclear" - /* 32bit specific stuff, unsure how this should be handled on 64bit - * systems - assert(ejit_run_func_2(f, - EJIT_ARG(0x80000000, long), - EJIT_ARG(2, long)) == 0xc0000000); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x80000000, long), - EJIT_ARG(0x7fffffff, long)) == 0xffffffff); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x7fffffff, long), - EJIT_ARG(0xffffffff, long)) == 0x80000001); - - assert(ejit_run_func_2(f, - EJIT_ARG(0xffffffff, long), - EJIT_ARG(0x7fffffff, long)) == 0); - */ - - assert(ejit_run_func_2(f, - EJIT_ARG(0x80000000, long), - EJIT_ARG(2, long)) == 0x40000000); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x80000000, long), - EJIT_ARG(0x7fffffff, long)) == 1); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x7fffffff, long), - EJIT_ARG(0xffffffff, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(0xffffffff, long), - EJIT_ARG(0x7fffffff, long)) == 2); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x7fffffffffffffff, long), - EJIT_ARG(1, long)) == 0x7fffffffffffffff); - - assert(ejit_run_func_2(f, - EJIT_ARG(1, long), - EJIT_ARG(0x7fffffffffffffff, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x8000000000000000, long), - EJIT_ARG(1, long)) - == (int64_t)0x8000000000000000); - - assert(ejit_run_func_2(f, - EJIT_ARG(1, long), - EJIT_ARG(0x8000000000000000, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x7fffffffffffffff, long), - EJIT_ARG(2, long)) - == (int64_t)0x3fffffffffffffff); - - assert(ejit_run_func_2(f, - EJIT_ARG(2, long), - EJIT_ARG(0x7fffffffffffffff, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x8000000000000000, long), - EJIT_ARG(2, long)) - == (int64_t)0xc000000000000000); - - assert(ejit_run_func_2(f, - EJIT_ARG(2, long), - EJIT_ARG(0x8000000000000000, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x7fffffffffffffff, long), - EJIT_ARG(0x8000000000000000, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x8000000000000000, long), - EJIT_ARG(0x7fffffffffffffff, long)) - == (int32_t)0xffffffffffffffff); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x7fffffffffffffff, long), - EJIT_ARG(0xffffffffffffffff, long)) - == (int32_t)0x8000000000000001); - - assert(ejit_run_func_2(f, - EJIT_ARG(0xffffffffffffffff, long), - EJIT_ARG(0x7fffffffffffffff, long)) == 0); - - assert(ejit_run_func_2(f, - EJIT_ARG(0xffffffffffffffff, long), - EJIT_ARG(0xffffffffffffffff, long)) == 1); - - ejit_destroy_func(f); -} diff --git a/tests/divr64.c b/tests/divr64.c new file mode 100644 index 0000000..33baa91 --- /dev/null +++ b/tests/divr64.c @@ -0,0 +1,151 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 2, operands); + + ejit_divr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int64_t), do_jit); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(1, int64_t)) == 0x7fffffff); + + assert(ejit_run_func_2(f, + EJIT_ARG(1, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(1, int64_t)) == 0x80000000); + + assert(ejit_run_func_2(f, + EJIT_ARG(1, int64_t), + EJIT_ARG(0x80000000, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(2, int64_t)) == 0x3fffffff); + + assert(ejit_run_func_2(f, + EJIT_ARG(2, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(2, int64_t), + EJIT_ARG(0x80000000, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0x80000000, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t)) == 1); + + /* 32bit specific stuff, unsure how this should be handled on 64bit + * systems + assert(ejit_run_func_2(f, + EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(2, int64_t)) == 0xc0000000); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 0xffffffff); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t)) == 0x80000001); + + assert(ejit_run_func_2(f, + EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 0); + */ + + assert(ejit_run_func_2(f, + EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(2, int64_t)) == 0x40000000); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 1); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 2); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(1, int64_t)) == 0x7fffffffffffffff); + + assert(ejit_run_func_2(f, + EJIT_ARG(1, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(1, int64_t)) + == (int64_t)0x8000000000000000); + + assert(ejit_run_func_2(f, + EJIT_ARG(1, int64_t), + EJIT_ARG(0x8000000000000000, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(2, int64_t)) + == (int64_t)0x3fffffffffffffff); + + assert(ejit_run_func_2(f, + EJIT_ARG(2, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(2, int64_t)) + == (int64_t)0xc000000000000000); + + assert(ejit_run_func_2(f, + EJIT_ARG(2, int64_t), + EJIT_ARG(0x8000000000000000, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0x8000000000000000, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0xffffffffffffffff, int64_t) + ) == (int64_t)0x8000000000000001); + + assert(ejit_run_func_2(f, + EJIT_ARG(0xffffffffffffffff, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0xffffffffffffffff, int64_t), + EJIT_ARG(0xffffffffffffffff, int64_t)) == 1); + + ejit_destroy_func(f); +} diff --git a/tests/divr_f.c b/tests/divr_f.c index 081c63d..980844b 100644 --- a/tests/divr_f.c +++ b/tests/divr_f.c @@ -15,13 +15,13 @@ int main() ejit_select_compile_func(f, 0, 2, EJIT_USE64(double), do_jit); - assert(ejit_run_func_2(f, - EJIT_ARG(-0.5f, double), - EJIT_ARG(0.5f, double)) == -1.0f); + assert(erff2(f, + EJIT_ARG(-0.5f, double), + EJIT_ARG(0.5f, double)) == -1.0f); - assert(ejit_run_func_2(f, - EJIT_ARG(1.25f, double), - EJIT_ARG(0.5f, double)) == 2.5f); + assert(erff2(f, + EJIT_ARG(1.25f, double), + EJIT_ARG(0.5f, double)) == 2.5f); ejit_destroy_func(f); } diff --git a/tests/ldxi_f.c b/tests/ldxi_f.c index eb2ad58..955ef13 100644 --- a/tests/ldxi_f.c +++ b/tests/ldxi_f.c @@ -12,7 +12,7 @@ int main() struct ejit_func *f = ejit_create_func(EJIT_TYPE(float), 1, operands); - ejit_ldxi_d(f, EJIT_FPR(0), EJIT_GPR(0), (uintptr_t)data); + ejit_ldxi_f(f, EJIT_FPR(0), EJIT_GPR(0), (uintptr_t)data); ejit_retr_f(f, EJIT_FPR(0)); ejit_select_compile_func(f, 1, 1, EJIT_USE64(long), do_jit); diff --git a/tests/ldxi_i16.c b/tests/ldxi_i16.c index e2af936..8fd1d0a 100644 --- a/tests/ldxi_i16.c +++ b/tests/ldxi_i16.c @@ -16,9 +16,9 @@ int main() ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit); - assert(erf1(f, EJIT_ARG(0, long)) == -1); - assert(erf1(f, EJIT_ARG(1, long)) == 0); - assert(erf1(f, EJIT_ARG(2, long)) == 0x4242); + assert(erf1(f, EJIT_ARG(sizeof(int16_t) * 0, long)) == -1); + assert(erf1(f, EJIT_ARG(sizeof(int16_t) * 1, long)) == 0); + assert(erf1(f, EJIT_ARG(sizeof(int16_t) * 2, long)) == 0x4242); ejit_destroy_func(f); } diff --git a/tests/ldxi_i64.c b/tests/ldxi_i64.c index 72112dd..c4b50c7 100644 --- a/tests/ldxi_i64.c +++ b/tests/ldxi_i64.c @@ -16,10 +16,10 @@ int main() ejit_select_compile_func(f, 1, 0, true, do_jit); - assert(erf1(f, EJIT_ARG(sizeof(int32_t) * 0, long)) == -1); - assert(erf1(f, EJIT_ARG(sizeof(int32_t) * 1, long)) == 0); - assert((uint64_t)erf1(f, - EJIT_ARG(sizeof(int32_t) * 2, long)) == data[2]); + assert(erf1(f, EJIT_ARG(sizeof(int64_t) * 0, long)) == -1); + assert(erf1(f, EJIT_ARG(sizeof(int64_t) * 1, long)) == 0); + assert(erf1(f, EJIT_ARG(sizeof(int64_t) * 2, long) + ) == (int64_t)data[2]); ejit_destroy_func(f); } diff --git a/tests/ldxi_u16.c b/tests/ldxi_u16.c index a5d8fca..6d98944 100644 --- a/tests/ldxi_u16.c +++ b/tests/ldxi_u16.c @@ -11,14 +11,14 @@ int main() }; struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands); - ejit_ldxi_i16(f, EJIT_GPR(0), EJIT_GPR(0), (uintptr_t)&data); + ejit_ldxi_u16(f, EJIT_GPR(0), EJIT_GPR(0), (uintptr_t)&data); ejit_retr(f, EJIT_GPR(0)); ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit); - assert(erf1(f, EJIT_ARG(0, long)) == 0xffff); - assert(erf1(f, EJIT_ARG(1, long)) == 0); - assert(erf1(f, EJIT_ARG(2, long)) == 0x4242); + assert(erf1(f, EJIT_ARG(sizeof(int16_t) * 0, long)) == 0xffff); + assert(erf1(f, EJIT_ARG(sizeof(int16_t) * 1, long)) == 0); + assert(erf1(f, EJIT_ARG(sizeof(int16_t) * 2, long)) == 0x4242); ejit_destroy_func(f); } diff --git a/tests/ldxi_u64.c b/tests/ldxi_u64.c index 193fcf3..84f6dd1 100644 --- a/tests/ldxi_u64.c +++ b/tests/ldxi_u64.c @@ -16,11 +16,14 @@ int main() ejit_select_compile_func(f, 1, 0, true, do_jit); - assert((uint64_t)erf1(f, - EJIT_ARG(sizeof(int32_t) * 0, long)) == data[0]); - assert((uint64_t)erf1(f, EJIT_ARG(sizeof(int32_t) * 1, long)) == 0); - assert((uint64_t)erf1(f, - EJIT_ARG(sizeof(int32_t) * 2, long)) == data[2]); + assert(erf1(f, EJIT_ARG(sizeof(int64_t) * 0, long) + ) == (int64_t)data[0]); + + assert(erf1(f, EJIT_ARG(sizeof(int64_t) * 1, long) + ) == 0); + + assert(erf1(f, EJIT_ARG(sizeof(int64_t) * 2, long) + ) == (int64_t)data[2]); ejit_destroy_func(f); } diff --git a/tests/ldxr_i8.c b/tests/ldxr_i8.c index c5de17e..6fe910d 100644 --- a/tests/ldxr_i8.c +++ b/tests/ldxr_i8.c @@ -17,9 +17,17 @@ int main() ejit_select_compile_func(f, 2, 0, false, do_jit); - assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(0, unsigned)) == -1); - assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(4, unsigned)) == 0); - assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(8, unsigned)) == 0x42); + assert(erf2(f, EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int8_t) * 0, unsigned) + ) == -1); + + assert(erf2(f, EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int8_t) * 1, unsigned) + ) == 0); + + assert(erf2(f, EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int8_t) * 2, unsigned) + ) == 0x42); ejit_destroy_func(f); } diff --git a/tests/ldxr_u8.c b/tests/ldxr_u8.c index d1f5023..83a0d36 100644 --- a/tests/ldxr_u8.c +++ b/tests/ldxr_u8.c @@ -17,9 +17,17 @@ int main() ejit_select_compile_func(f, 2, 0, false, do_jit); - assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(0, unsigned)) == 0xff); - assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(4, unsigned)) == 0); - assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(8, unsigned)) == 0x42); + assert(erf2(f, EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int8_t) * 0, unsigned) + ) == 0xff); + + assert(erf2(f, EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int8_t) * 1, unsigned) + ) == 0); + + assert(erf2(f, EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int8_t) * 2, unsigned) + ) == 0x42); ejit_destroy_func(f); } diff --git a/tests/ler.c b/tests/ler.c deleted file mode 100644 index 90c4c4c..0000000 --- a/tests/ler.c +++ /dev/null @@ -1,30 +0,0 @@ -#include <ejit/ejit.h> -#include <assert.h> -#include "do_jit.h" - -int main() -{ - struct ejit_operand operands[2] = { - EJIT_OPERAND_GPR(0, EJIT_TYPE(long)), - EJIT_OPERAND_GPR(1, EJIT_TYPE(long)) - }; - - struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); - - ejit_ler(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); - ejit_retr(f, EJIT_GPR(0)); - - ejit_select_compile_func(f, 2, 0, EJIT_USE64(long), do_jit); - - assert(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(1, long)) == 1); - assert(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(0, long)) == 1); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x0fffffffffffffff, long), - EJIT_ARG(0x0ffffffffffffff0, long)) == 1); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x7fffffffffffffff, long), - EJIT_ARG(0x6fffffffffffffff, long)) == 0); - ejit_destroy_func(f); -} diff --git a/tests/ler64.c b/tests/ler64.c new file mode 100644 index 0000000..322314c --- /dev/null +++ b/tests/ler64.c @@ -0,0 +1,32 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int64_t)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 2, operands); + + ejit_ler(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int64_t), do_jit); + + assert(ejit_run_func_2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(1, int64_t)) == 1); + assert(ejit_run_func_2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x0fffffffffffffff, int64_t), + EJIT_ARG(0x0ffffffffffffff0, int64_t)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0x6fffffffffffffff, int64_t)) == 0); + ejit_destroy_func(f); +} diff --git a/tests/ler_f.c b/tests/ler_f.c index ecb4b3f..fa08b24 100644 --- a/tests/ler_f.c +++ b/tests/ler_f.c @@ -9,22 +9,16 @@ int main() EJIT_OPERAND_FPR(1, EJIT_TYPE(double)) }; - struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 2, operands); + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); ejit_ler_f(f, EJIT_GPR(0), EJIT_FPR(0), EJIT_FPR(1)); ejit_retr(f, EJIT_GPR(0)); - ejit_select_compile_func(f, 1, 2, EJIT_USE64(long), do_jit); + ejit_select_compile_func(f, 1, 2, EJIT_USE64(double), do_jit); - assert(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(1, long)) == 1); - assert(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(0, long)) == 1); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x0fffffffffffffff, long), - EJIT_ARG(0x0ffffffffffffff0, long)) == 1); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x7fffffffffffffff, long), - EJIT_ARG(0x6fffffffffffffff, long)) == 0); + assert(erf2(f, EJIT_ARG(1, double), EJIT_ARG(1, double)) == 1); + assert(erf2(f, EJIT_ARG(1, double), EJIT_ARG(0, double)) == 0); + assert(erf2(f, EJIT_ARG(-1, double), EJIT_ARG(0, double)) == 1); + assert(erf2(f, EJIT_ARG(-1, double), EJIT_ARG(-1, double)) == 1); ejit_destroy_func(f); } diff --git a/tests/ltr.c b/tests/ltr.c index 85f7af0..310362c 100644 --- a/tests/ltr.c +++ b/tests/ltr.c @@ -17,11 +17,11 @@ int main() ejit_select_compile_func(f, 2, 0, EJIT_USE64(long), do_jit); assert(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(1, long)) == 0); - assert(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(0, long)) == 1); + assert(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(0, long)) == 0); assert(ejit_run_func_2(f, EJIT_ARG(0x0fffffffffffffff, long), - EJIT_ARG(0x0ffffffffffffff0, long)) == 1); + EJIT_ARG(0x0ffffffffffffff0, long)) == 0); assert(ejit_run_func_2(f, EJIT_ARG(0x7fffffffffffffff, long), diff --git a/tests/ltr_f.c b/tests/ltr_f.c index f925c4f..20fadac 100644 --- a/tests/ltr_f.c +++ b/tests/ltr_f.c @@ -16,17 +16,10 @@ int main() ejit_select_compile_func(f, 1, 2, EJIT_USE64(long), do_jit); - assert(ejit_run_func_2(f, EJIT_ARG(1, double), - EJIT_ARG(1, double)) == 0); - assert(ejit_run_func_2(f, EJIT_ARG(1, double), - EJIT_ARG(0, double)) == 1); + assert(erf2(f, EJIT_ARG(1, double), EJIT_ARG(1, double)) == 0); + assert(erf2(f, EJIT_ARG(1, double), EJIT_ARG(0, double)) == 0); + assert(erf2(f, EJIT_ARG(-1, double), EJIT_ARG(0, double)) == 1); + assert(erf2(f, EJIT_ARG(-1, double), EJIT_ARG(-1, double)) == 0); - assert(ejit_run_func_2(f, - EJIT_ARG(0x0fffffffffffffff, double), - EJIT_ARG(0x0ffffffffffffff0, double)) == 1); - - assert(ejit_run_func_2(f, - EJIT_ARG(0x7fffffffffffffff, double), - EJIT_ARG(0x6fffffffffffffff, double)) == 0); ejit_destroy_func(f); } diff --git a/tests/makefile b/tests/makefile index 3ab921a..21f68dd 100644 --- a/tests/makefile +++ b/tests/makefile @@ -12,11 +12,11 @@ COMPILE_JIT_TEST := $(COMPILER) $(CFLAGS) $(INCLUDE_FLAGS) COMPILE_BCODE_TEST := $(COMPILER) $(CFLAGS) $(INCLUDE_FLAGS) -DFORCE_BCODE=1 .PHONY: check -check: $(BCODE_TESTS) $(JIT_TESTS) +check: check-bcode check-jit echo "Success!" .PHONY: check-bcode -check-bcode: +check-bcode: $(BCODE_TESTS) @echo "Running bytecode tests..." @set -e; for test in $(BCODE_TESTS); do \ echo "Testing: $$test"; \ @@ -24,7 +24,7 @@ check-bcode: done .PHONY: check-jit -check-jit: +check-jit: $(JIT_TESTS) @echo "Running jit tests..." @set -e; for test in $(JIT_TESTS); do \ echo "Testing: $$test"; \ diff --git a/tests/movi.c b/tests/movi.c index 1282b6f..9854088 100644 --- a/tests/movi.c +++ b/tests/movi.c @@ -1,22 +1,14 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int), 0, NULL); + ejit_movi(f, EJIT_GPR(0), 0xa500a500); + ejit_retr(f, EJIT_GPR(0)); + ejit_select_compile_func(f, 1, 0, EJIT_USE64(int), do_jit); - jit_movi(j, JIT_R0, 0xa500a500); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - jit_uword_t (*f)(void) = jit_end(j, NULL); - - ASSERT(f() == 0xa500a500); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + assert(ejit_run_func(f, 0, NULL) == 0xa500a500); + ejit_destroy_func(f); } diff --git a/tests/movi_f.c b/tests/movi_f.c index 82e2d0a..73d22e3 100644 --- a/tests/movi_f.c +++ b/tests/movi_f.c @@ -1,22 +1,14 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); + struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 0, NULL); + ejit_movi_f(f, EJIT_FPR(0), 3.14159f); + ejit_retr_f(f, EJIT_FPR(0)); + ejit_select_compile_func(f, 0, 1, EJIT_USE64(double), do_jit); - jit_movi_f(j, JIT_F0, 3.14159f); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr_f(j, JIT_F0); - - float (*f)(void) = jit_end(j, NULL); - - ASSERT(f() == 3.14159f); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + assert(ejit_run_func_f(f, 0, NULL) == 3.14159f); + ejit_destroy_func(f); } diff --git a/tests/movr.c b/tests/movr.c new file mode 100644 index 0000000..e9a0c9d --- /dev/null +++ b/tests/movr.c @@ -0,0 +1,17 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[1] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int), 1, operands); + ejit_movr(f, EJIT_GPR(1), EJIT_GPR(0)); + ejit_retr(f, EJIT_GPR(1)); + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int), do_jit); + + assert(ejit_run_func_1(f, EJIT_ARG(42, int)) == 42); + ejit_destroy_func(f); +} diff --git a/tests/movr_f.c b/tests/movr_f.c new file mode 100644 index 0000000..8fa19a2 --- /dev/null +++ b/tests/movr_f.c @@ -0,0 +1,17 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[1] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 1, operands); + ejit_movr_f(f, EJIT_FPR(1), EJIT_FPR(0)); + ejit_retr_f(f, EJIT_FPR(1)); + ejit_select_compile_func(f, 0, 2, EJIT_USE64(double), do_jit); + + assert(ejit_run_func_f_1(f, EJIT_ARG(42., double)) == 42.); + ejit_destroy_func(f); +} diff --git a/tests/mulr.c b/tests/mulr.c deleted file mode 100644 index 3f0a6f8..0000000 --- a/tests/mulr.c +++ /dev/null @@ -1,64 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1)); - - jit_mulr(j, JIT_R0, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - size_t size = 0; - void* ret = jit_end(j, &size); - - jit_word_t (*f)(jit_word_t, jit_word_t) = ret; - - ASSERT(f(0x7fffffff, 1) == 0x7fffffff); - ASSERT(f(1, 0x7fffffff) == 0x7fffffff); - ASSERT(f(0x80000000, 1) == 0x80000000); - ASSERT(f(1, 0x80000000) == 0x80000000); - ASSERT(f(0x7fffffff, 2) == 0xfffffffe); - ASSERT(f(2, 0x7fffffff) == 0xfffffffe); - ASSERT(f(0x7fffffff, 0) == 0); - ASSERT(f(0, 0x7fffffff) == 0); -#if EJIT_WORDSIZE == 32 - ASSERT(f(0x80000000, 2) == 0); - ASSERT(f(2, 0x80000000) == 0); - ASSERT(f(0x7fffffff, 0x80000000) == 0x80000000); - ASSERT(f(0x80000000, 0x7fffffff) == 0x80000000); - ASSERT(f(0x7fffffff, 0xffffffff) == 0x80000001); - ASSERT(f(0xffffffff, 0x7fffffff) == 0x80000001); - ASSERT(f(0xffffffff, 0xffffffff) == 1); -#else - ASSERT(f(0x80000000, 2) == 0x100000000); - ASSERT(f(2, 0x80000000) == 0x100000000); - ASSERT(f(0x7fffffff, 0x80000000) == 0x3fffffff80000000); - ASSERT(f(0x80000000, 0x7fffffff) == 0x3fffffff80000000); - ASSERT(f(0x7fffffff, 0xffffffff) == 0x7ffffffe80000001); - ASSERT(f(0xffffffff, 0x7fffffff) == 0x7ffffffe80000001); - ASSERT(f(0xffffffff, 0xffffffff) == 0xfffffffe00000001); - ASSERT(f(0x7fffffffffffffff, 1) == 0x7fffffffffffffff); - ASSERT(f(1, 0x7fffffffffffffff) == 0x7fffffffffffffff); - ASSERT(f(0x8000000000000000, 1) == 0x8000000000000000); - ASSERT(f(1, 0x8000000000000000) == 0x8000000000000000); - ASSERT(f(0x7fffffffffffffff, 2) == 0xfffffffffffffffe); - ASSERT(f(2, 0x7fffffffffffffff) == 0xfffffffffffffffe); - ASSERT(f(0x8000000000000000, 2) == 0); - ASSERT(f(2, 0x8000000000000000) == 0); - ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == 0x8000000000000000); - ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == 0x8000000000000000); - ASSERT(f(0x7fffffffffffffff, 0xffffffffffffffff) == 0x8000000000000001); - ASSERT(f(0xffffffffffffffff, 0x7fffffffffffffff) == 0x8000000000000001); - ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 1); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/mulr64.c b/tests/mulr64.c new file mode 100644 index 0000000..4b51745 --- /dev/null +++ b/tests/mulr64.c @@ -0,0 +1,122 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 2, operands); + + ejit_mulr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int64_t), do_jit); + + assert(erf2(f, EJIT_ARG(1, int64_t), EJIT_ARG(0x7fffffff, int64_t) + ) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(1, int64_t), EJIT_ARG(0x80000000, int64_t) + ) == 0x80000000); + + assert(erf2(f, EJIT_ARG(2, int64_t), EJIT_ARG(0x7fffffff, int64_t) + ) == 0xfffffffe); + + assert(erf2(f, EJIT_ARG(0, int64_t), EJIT_ARG(0x7fffffff, int64_t) + ) == 0); + + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), EJIT_ARG(1, int64_t) + ) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), EJIT_ARG(1, int64_t) + ) == 0x80000000); + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), EJIT_ARG(2, int64_t) + ) == 0xfffffffe); + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), EJIT_ARG(0, int64_t) + ) == 0); + + assert(erf2(f, EJIT_ARG(2, int64_t), EJIT_ARG(0x80000000, int64_t) + ) == 0x100000000); + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == 0x7fffffffffffffff); + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x8000000000000000, int64_t) + ) == (int64_t)0x8000000000000000); + + assert(erf2(f, EJIT_ARG(2, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == (int64_t)0xfffffffffffffffe); + + assert(erf2(f, EJIT_ARG(2, int64_t), + EJIT_ARG(0x8000000000000000, int64_t) + ) == 0); + + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), EJIT_ARG(2, int64_t) + ) == (int64_t)0x100000000); + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0x80000000, int64_t) + ) == (int64_t)0x3fffffff80000000); + + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(0x7fffffff, int64_t) + ) == (int64_t)0x3fffffff80000000); + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t) + ) == (int64_t)0x7ffffffe80000001); + + assert(erf2(f, EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0x7fffffff, int64_t) + ) == (int64_t)0x7ffffffe80000001); + + assert(erf2(f, EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t) + ) == (int64_t)0xfffffffe00000001); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(1, int64_t) + ) == (int64_t)0x7fffffffffffffff); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(1, int64_t) + ) == (int64_t)0x8000000000000000); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(2, int64_t) + ) == (int64_t)0xfffffffffffffffe); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(2, int64_t) + ) == 0); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0x8000000000000000, int64_t) + ) == (int64_t)0x8000000000000000); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == (int64_t)0x8000000000000000); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0xffffffffffffffff, int64_t) + ) == (int64_t)0x8000000000000001); + + assert(erf2(f, EJIT_ARG(0xffffffffffffffff, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == (int64_t)0x8000000000000001); + + assert(erf2(f, EJIT_ARG(0xffffffffffffffff, int64_t), + EJIT_ARG(0xffffffffffffffff, int64_t) + ) == 1); + + ejit_destroy_func(f); +} diff --git a/tests/mulr_f.c b/tests/mulr_f.c index 5e5f46a..44d6030 100644 --- a/tests/mulr_f.c +++ b/tests/mulr_f.c @@ -1,27 +1,24 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0), - jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F1)); + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)), + EJIT_OPERAND_FPR(1, EJIT_TYPE(double)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 2, operands); - jit_mulr_f(j, JIT_F0, JIT_F0, JIT_F1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr_f(j, JIT_F0); + ejit_mulr_f(f, EJIT_FPR(0), EJIT_FPR(0), EJIT_FPR(1)); + ejit_retr_f(f, EJIT_FPR(0)); - size_t size = 0; - void* ret = jit_end(j, &size); + ejit_select_compile_func(f, 0, 2, EJIT_USE64(double), do_jit); - float (*f)(float, float) = ret; - ASSERT(f(-0.5f, 0.5f) == -0.25f); - ASSERT(f(0.25f, 0.75f) == 0.1875f); -} + assert(erff2(f, EJIT_ARG(-0.5f, double), + EJIT_ARG(0.50f, double)) == -0.25f); + assert(erff2(f, EJIT_ARG(0.25f, double), + EJIT_ARG(0.75f, double)) == 0.1875f); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + ejit_destroy_func(f); } diff --git a/tests/negr.c b/tests/negr.c index db65f3c..4e3b34c 100644 --- a/tests/negr.c +++ b/tests/negr.c @@ -1,39 +1,39 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0)); + struct ejit_operand operands[1] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 1, operands); - jit_negr(j, JIT_R0, JIT_R0); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); + ejit_negr(f, EJIT_GPR(0), EJIT_GPR(0)); + ejit_retr(f, EJIT_GPR(0)); - jit_word_t (*f)(jit_word_t) = jit_end(j, NULL); + ejit_select_compile_func(f, 1, 0, EJIT_USE64(int64_t), do_jit); - ASSERT(f(0) == 0); -#if EJIT_WORDSIZE == 32 - ASSERT(f(1) == 0xffffffff); - ASSERT(f(0xffffffff) == 1); - ASSERT(f(0x80000000) == 0x80000000); - ASSERT(f(0x7fffffff) == 0x80000001); - ASSERT(f(0x80000001) == 0x7fffffff); -#else - ASSERT(f(1) == 0xffffffffffffffff); - ASSERT(f(0xffffffff) == 0xffffffff00000001); - ASSERT(f(0x80000000) == 0xffffffff80000000); - ASSERT(f(0x7fffffff) == 0xffffffff80000001); - ASSERT(f(0x80000001) == 0xffffffff7fffffff); - ASSERT(f(0xffffffffffffffff) == 1); - ASSERT(f(0x8000000000000000) == 0x8000000000000000); - ASSERT(f(0x7fffffffffffffff) == 0x8000000000000001); -#endif -} + assert(erf1(f, EJIT_ARG(0, int64_t)) == 0); + assert(erf1(f, EJIT_ARG(1, int64_t)) == (int64_t)0xffffffffffffffff); + assert(erf1(f, + EJIT_ARG(0xffffffff, + int64_t)) == (int64_t)0xffffffff00000001); + assert(erf1(f, + EJIT_ARG(0x80000000, + int64_t)) == (int64_t)0xffffffff80000000); + assert(erf1(f, + EJIT_ARG(0x7fffffff, + int64_t)) == (int64_t)0xffffffff80000001); + assert(erf1(f, + EJIT_ARG(0x80000001, + int64_t)) == (int64_t)0xffffffff7fffffff); + assert(erf1(f, EJIT_ARG(0xffffffffffffffff, int64_t)) == 1); + assert(erf1(f, EJIT_ARG(0x8000000000000000, int64_t)) + == (int64_t)0x8000000000000000); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + assert(erf1(f, EJIT_ARG(0x7fffffffffffffff, int64_t)) + == (int64_t)0x8000000000000001); + + ejit_destroy_func(f); } diff --git a/tests/negr_f.c b/tests/negr_f.c index 08b6364..d6fee7b 100644 --- a/tests/negr_f.c +++ b/tests/negr_f.c @@ -1,26 +1,23 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0)); + struct ejit_operand operands[1] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 1, operands); - jit_negr_f(j, JIT_F0, JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr_f(j, JIT_F0); + ejit_negr_f(f, EJIT_FPR(0), EJIT_FPR(0)); + ejit_retr_f(f, EJIT_FPR(0)); - float (*f)(float) = jit_end(j, NULL); + ejit_select_compile_func(f, 0, 1, EJIT_USE64(double), do_jit); - ASSERT(f(0.0f) == -0.0f); - ASSERT(f(0.5f) == -0.5f); - ASSERT(f(1.0f / 0.0f) == -1.0f / 0.0f); - ASSERT(f(-1.25f) == 1.25f); -} + assert(erff1(f, EJIT_ARG(0.0f, double)) == -0.0f); + assert(erff1(f, EJIT_ARG(0.5f, double)) == -0.5f); + assert(erff1(f, EJIT_ARG(1.0f / 0.0f, double)) == -1.0f / 0.0f); + assert(erff1(f, EJIT_ARG(-1.25f, double)) == 1.25f); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + ejit_destroy_func(f); } diff --git a/tests/ner.c b/tests/ner.c index ca615d0..b83ccf3 100644 --- a/tests/ner.c +++ b/tests/ner.c @@ -5,7 +5,7 @@ int main() { struct ejit_operand operands[2] = { - EJIT_OPERAND_GPR(0, EJIT_TYPE(long)) + EJIT_OPERAND_GPR(0, EJIT_TYPE(long)), EJIT_OPERAND_GPR(1, EJIT_TYPE(long)) }; diff --git a/tests/ner_f.c b/tests/ner_f.c new file mode 100644 index 0000000..73bab90 --- /dev/null +++ b/tests/ner_f.c @@ -0,0 +1,25 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)), + EJIT_OPERAND_FPR(1, EJIT_TYPE(double)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); + + ejit_ner_f(f, EJIT_GPR(0), EJIT_FPR(0), EJIT_FPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 1, 2, EJIT_USE64(long), do_jit); + + assert(ejit_run_func_2(f, EJIT_ARG(1, double), + EJIT_ARG(1, double)) == 0); + assert(ejit_run_func_2(f, EJIT_ARG(1, double), + EJIT_ARG(0, double)) == 1); + + ejit_destroy_func(f); +} diff --git a/tests/ori.c b/tests/ori.c deleted file mode 100644 index 27f7b2c..0000000 --- a/tests/ori.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0)); - - jit_ori(j, JIT_R0, JIT_R0, 1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - size_t size = 0; - void* ret = jit_end(j, &size); - - jit_word_t (*f)(jit_word_t) = ret; - - ASSERT(f(0x7fffffff) == 0x7fffffff); - ASSERT(f(0x80000000) == 0x80000001); -#if EJIT_WORDSIZE == 64 - ASSERT(f(0x7fffffffffffffff) == 0x7fffffffffffffff); - ASSERT(f(0x8000000000000000) == 0x8000000000000001); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/ori64.c b/tests/ori64.c new file mode 100644 index 0000000..352923e --- /dev/null +++ b/tests/ori64.c @@ -0,0 +1,26 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[1] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 1, operands); + + ejit_ori(f, EJIT_GPR(0), EJIT_GPR(0), 1); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 1, 0, EJIT_USE64(int64_t), do_jit); + + assert(erf1(f, EJIT_ARG(0x7fffffff, int64_t)) == 0x7fffffff); + assert(erf1(f, EJIT_ARG(0x80000000, int64_t)) == 0x80000001); + assert(erf1(f, EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == 0x7fffffffffffffff); + + assert(erf1(f, EJIT_ARG(0x8000000000000000, int64_t) + ) == (int64_t)0x8000000000000001); + + ejit_destroy_func(f); +} diff --git a/tests/orr.c b/tests/orr.c deleted file mode 100644 index af8e141..0000000 --- a/tests/orr.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1)); - - jit_orr(j, JIT_R0, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - size_t size = 0; - void* ret = jit_end(j, &size); - - jit_word_t (*f)(jit_word_t, jit_word_t) = ret; - - ASSERT(f(0x7fffffff, 1) == 0x7fffffff); - ASSERT(f(1, 0x7fffffff) == 0x7fffffff); - ASSERT(f(0x80000000, 1) == 0x80000001); - ASSERT(f(1, 0x80000000) == 0x80000001); - ASSERT(f(0x7fffffff, 0x80000000) == 0xffffffff); - ASSERT(f(0x80000000, 0x7fffffff) == 0xffffffff); - ASSERT(f(0x7fffffff, 0xffffffff) == 0xffffffff); - ASSERT(f(0xffffffff, 0x7fffffff) == 0xffffffff); - ASSERT(f(0xffffffff, 0xffffffff) == 0xffffffff); - ASSERT(f(0x7fffffff, 0) == 0x7fffffff); - ASSERT(f(0, 0x7fffffff) == 0x7fffffff); -#if EJIT_WORDSIZE == 64 - ASSERT(f(0x7fffffffffffffff, 1) == 0x7fffffffffffffff); - ASSERT(f(1, 0x7fffffffffffffff) == 0x7fffffffffffffff); - ASSERT(f(0x8000000000000000, 1) == 0x8000000000000001); - ASSERT(f(1, 0x8000000000000000) == 0x8000000000000001); - ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == 0xffffffffffffffff); - ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == 0xffffffffffffffff); - ASSERT(f(0x7fffffffffffffff, 0xffffffffffffffff) == 0xffffffffffffffff); - ASSERT(f(0xffffffffffffffff, 0x7fffffffffffffff) == 0xffffffffffffffff); - ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 0xffffffffffffffff); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/orr64.c b/tests/orr64.c new file mode 100644 index 0000000..d113cec --- /dev/null +++ b/tests/orr64.c @@ -0,0 +1,86 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 2, operands); + + ejit_orr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int64_t), do_jit); + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x80000000, int64_t)) == 0x80000001); + + assert(erf2(f, EJIT_ARG(0, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(1, int64_t)) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(1, int64_t)) == 0x80000001); + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0, int64_t)) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0x80000000, int64_t)) == 0xffffffff); + + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 0xffffffff); + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t)) == 0xffffffff); + + assert(erf2(f, EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 0xffffffff); + + assert(erf2(f, EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t)) == 0xffffffff); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(1, int64_t)) == 0x7fffffffffffffff); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(1, int64_t)) == (int64_t)0x8000000000000001); + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == (int64_t)0x7fffffffffffffff); + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x8000000000000000, int64_t) + ) == (int64_t)0x8000000000000001); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0x8000000000000000, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0xffffffffffffffff, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(erf2(f, EJIT_ARG(0xffffffffffffffff, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(erf2(f, EJIT_ARG(0xffffffffffffffff, int64_t), + EJIT_ARG(0xffffffffffffffff, int64_t) + ) == (int64_t)0xffffffffffffffff); + + ejit_destroy_func(f); +} diff --git a/tests/remr.c b/tests/remr.c deleted file mode 100644 index cd5bf4f..0000000 --- a/tests/remr.c +++ /dev/null @@ -1,60 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1)); - - jit_remr(j, JIT_R0, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - size_t size = 0; - void* ret = jit_end(j, &size); - - jit_word_t (*f)(jit_word_t, jit_word_t) = ret; - - ASSERT(f(0x7fffffff, 1) == 0); - ASSERT(f(1, 0x7fffffff) == 1); - ASSERT(f(0x80000000, 1) == 0); - ASSERT(f(1, 0x80000000) == 1); - ASSERT(f(0x7fffffff, 2) == 1); - ASSERT(f(2, 0x7fffffff) == 2); - ASSERT(f(0x80000000, 2) == 0); - ASSERT(f(2, 0x80000000) == 2); - ASSERT(f(0x7fffffff, 0x80000000) == 0x7fffffff); - ASSERT(f(0, 0x7fffffff) == 0); - ASSERT(f(0xffffffff, 0xffffffff) == 0); - -#if EJIT_WORDSIZE == 32 - ASSERT(f(0x80000000, 0x7fffffff) == 0xffffffff); - ASSERT(f(0x7fffffff, 0xffffffff) == 0); - ASSERT(f(0xffffffff, 0x7fffffff) == 0xffffffff); -#else - ASSERT(f(0x80000000, 0x7fffffff) == 1); - ASSERT(f(0x7fffffff, 0xffffffff) == 0x7fffffff); - ASSERT(f(0xffffffff, 0x7fffffff) == 1); - ASSERT(f(0x7fffffffffffffff, 1) == 0); - ASSERT(f(1, 0x7fffffffffffffff) == 1); - ASSERT(f(0x8000000000000000, 1) == 0); - ASSERT(f(1, 0x8000000000000000) == 1); - ASSERT(f(0x7fffffffffffffff, 2) == 1); - ASSERT(f(2, 0x7fffffffffffffff) == 2); - ASSERT(f(0x8000000000000000, 2) == 0); - ASSERT(f(2, 0x8000000000000000) == 2); - ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == 0x7fffffffffffffff); - ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == 0xffffffffffffffff); - ASSERT(f(0x7fffffffffffffff, 0xffffffffffffffff) == 0); - ASSERT(f(0xffffffffffffffff, 0x7fffffffffffffff) == 0xffffffffffffffff); - ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 0); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/remr64.c b/tests/remr64.c new file mode 100644 index 0000000..c9c97aa --- /dev/null +++ b/tests/remr64.c @@ -0,0 +1,100 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 2, operands); + + ejit_remr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int64_t), do_jit); + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x80000000, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(2, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 2); + assert(erf2(f, EJIT_ARG(2, int64_t), + EJIT_ARG(0x80000000, int64_t)) == 2); + assert(erf2(f, EJIT_ARG(0, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 0); + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(1, int64_t)) == 0); + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(1, int64_t)) == 0); + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(2, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(2, int64_t)) == 0); + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0x80000000, int64_t) + ) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t) + ) == 0); + + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(0x7fffffff, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t) + ) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0x7fffffff, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t)) == 1); + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x8000000000000000, int64_t)) == 1); + + assert(erf2(f, EJIT_ARG(2, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t)) == 2); + + assert(erf2(f, EJIT_ARG(2, int64_t), + EJIT_ARG(0x8000000000000000, int64_t)) == 2); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(1, int64_t)) == 0); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(1, int64_t)) == 0); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(2, int64_t)) == 1); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(2, int64_t)) == 0); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0x8000000000000000, int64_t) + ) == 0x7fffffffffffffff); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0xffffffffffffffff, int64_t) + ) == 0); + + assert(erf2(f, EJIT_ARG(0xffffffffffffffff, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(erf2(f, EJIT_ARG(0xffffffffffffffff, int64_t), + EJIT_ARG(0xffffffffffffffff, int64_t) + ) == 0); + + ejit_destroy_func(f); +} diff --git a/tests/remr_u.c b/tests/remr_u.c deleted file mode 100644 index ba015c1..0000000 --- a/tests/remr_u.c +++ /dev/null @@ -1,56 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1)); - - jit_remr_u(j, JIT_R0, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - size_t size = 0; - void* ret = jit_end(j, &size); - - jit_word_t (*f)(jit_word_t, jit_word_t) = ret; - - ASSERT(f(0x7fffffff, 1) == 0); - ASSERT(f(1, 0x7fffffff) == 1); - ASSERT(f(0x80000000, 1) == 0); - ASSERT(f(1, 0x80000000) == 1); - ASSERT(f(0x7fffffff, 2) == 1); - ASSERT(f(2, 0x7fffffff) == 2); - ASSERT(f(0x80000000, 2) == 0); - ASSERT(f(2, 0x80000000) == 2); - ASSERT(f(0x7fffffff, 0x80000000) == 0x7fffffff); - ASSERT(f(0x80000000, 0x7fffffff) == 1); - ASSERT(f(0, 0x7fffffff) == 0); - ASSERT(f(0x7fffffff, 0xffffffff) == 0x7fffffff); - ASSERT(f(0xffffffff, 0x7fffffff) == 1); - ASSERT(f(0xffffffff, 0xffffffff) == 0); - -#if EJIT_WORDSIZE != 32 - ASSERT(f(0x7fffffffffffffff, 1) == 0); - ASSERT(f(1, 0x7fffffffffffffff) == 1); - ASSERT(f(0x8000000000000000, 1) == 0); - ASSERT(f(1, 0x8000000000000000) == 1); - ASSERT(f(0x7fffffffffffffff, 2) == 1); - ASSERT(f(2, 0x7fffffffffffffff) == 2); - ASSERT(f(0x8000000000000000, 2) == 0); - ASSERT(f(2, 0x8000000000000000) == 2); - ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == 0x7fffffffffffffff); - ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == 1); - ASSERT(f(0x7fffffffffffffff, 0xffffffffffffffff) == 0x7fffffffffffffff); - ASSERT(f(0xffffffffffffffff, 0x7fffffffffffffff) == 1); - ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 0); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/remr_u64.c b/tests/remr_u64.c new file mode 100644 index 0000000..c414ef7 --- /dev/null +++ b/tests/remr_u64.c @@ -0,0 +1,95 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 2, operands); + + ejit_remr_u(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int64_t), do_jit); + + assert(erf2(f, EJIT_ARG(0, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 0); + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x80000000, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(2, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 2); + assert(erf2(f, EJIT_ARG(2, int64_t), + EJIT_ARG(0x80000000, int64_t)) == 2); + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(1, int64_t)) == 0); + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(1, int64_t)) == 0); + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(2, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(2, int64_t)) == 0); + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0x80000000, int64_t) + ) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(0x7fffffff, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t) + ) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0x7fffffff, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t) + ) == 0); + + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x8000000000000000, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(2, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t)) == 2); + assert(erf2(f, EJIT_ARG(2, int64_t), + EJIT_ARG(0x8000000000000000, int64_t)) == 2); + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(1, int64_t)) == 0); + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(1, int64_t)) == 0); + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(2, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(2, int64_t)) == 0); + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0x8000000000000000, int64_t) + ) == 0x7fffffffffffffff); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0xffffffffffffffff, int64_t) + ) == 0x7fffffffffffffff); + + assert(erf2(f, EJIT_ARG(0xffffffffffffffff, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0xffffffffffffffff, int64_t), + EJIT_ARG(0xffffffffffffffff, int64_t) + ) == 0); + + + ejit_destroy_func(f); +} diff --git a/tests/rshi.c b/tests/rshi.c deleted file mode 100644 index ab5438a..0000000 --- a/tests/rshi.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0)); - - jit_rshi(j, JIT_R0, JIT_R0, 31); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - jit_word_t (*f)(jit_word_t) = jit_end(j, NULL); - -#if EJIT_WORDSIZE == 32 - ASSERT(f(0x80000000) == -1); -#else - ASSERT(f(0x80000000) == 1); - ASSERT(f(0x8000000000000000) == 0xffffffff00000000); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/rshi64.c b/tests/rshi64.c new file mode 100644 index 0000000..b5279e9 --- /dev/null +++ b/tests/rshi64.c @@ -0,0 +1,22 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[1] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 1, operands); + + ejit_rshi(f, EJIT_GPR(0), EJIT_GPR(0), 31); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 1, 0, EJIT_USE64(int64_t), do_jit); + + assert(erf1(f, EJIT_ARG(0x80000000, int64_t)) == 1); + assert(erf1(f, EJIT_ARG(0x8000000000000000, int64_t) + ) == (int64_t)0xffffffff00000000); + + ejit_destroy_func(f); +} diff --git a/tests/rshi_u.c b/tests/rshi_u.c deleted file mode 100644 index aa02206..0000000 --- a/tests/rshi_u.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0)); - - jit_rshi_u(j, JIT_R0, JIT_R0, 31); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - jit_word_t (*f)(jit_word_t) = jit_end(j, NULL); - -#if EJIT_WORDSIZE == 32 - ASSERT(f(0x80000000) == 1); -#else - ASSERT(f(0x80000000) == 1); - ASSERT(f(0x8000000000000000) == 0x100000000); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/rshi_u64.c b/tests/rshi_u64.c new file mode 100644 index 0000000..4b6d5a9 --- /dev/null +++ b/tests/rshi_u64.c @@ -0,0 +1,21 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[1] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 1, operands); + + ejit_rshi_u(f, EJIT_GPR(0), EJIT_GPR(0), 31); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 1, 0, EJIT_USE64(int64_t), do_jit); + + assert(erf1(f, EJIT_ARG(0x80000000, int64_t)) == 1); + assert(erf1(f, EJIT_ARG(0x8000000000000000, int64_t)) == 0x100000000); + + ejit_destroy_func(f); +} diff --git a/tests/rshr.c b/tests/rshr.c deleted file mode 100644 index d14f64f..0000000 --- a/tests/rshr.c +++ /dev/null @@ -1,63 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1)); - - jit_rshr(j, JIT_R0, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - size_t size = 0; - void* ret = jit_end(j, &size); - - jit_word_t (*f)(jit_word_t, jit_word_t) = ret; - - ASSERT(f(0xfe, 1) == 0x7f); - ASSERT(f(0x1fffc, 2) == 0x7fff); - ASSERT(f(0x40000000, 30) == 1); - ASSERT(f(0x20000000, 29) == 1); - ASSERT(f(0x10000000, 28) == 1); - ASSERT(f(0x810000, 16) == 0x81); - ASSERT(f(0x20000, 17) == 1); - ASSERT(f(0x40000, 18) == 1); - ASSERT(f(0x7f8000, 15) == 0xff); - ASSERT(f(0x1000000, 24) == 1); - ASSERT(f(0x7fffffff, 0) == 0x7fffffff); -#if EJIT_WORDSIZE == 32 - ASSERT(f(0xfffffff8, 3) == 0xffffffff); - ASSERT(f(0x80000000, 31) == 0xffffffff); - ASSERT(f(0xffffff00, 8) == 0xffffffff); -#else - ASSERT(f(0x3fffffff8, 3) == 0x7fffffff); - ASSERT(f(0xffffffc080000000, 31) == 0xffffffffffffff81); - ASSERT(f(0xffffff00, 8) == 0xffffff); - ASSERT(f(0xfe00000000, 33) == 0x7f); - ASSERT(f(0x1ffffc00000000, 34) == 0x7ffff); - ASSERT(f(0xfffffff800000000, 29) == 0xffffffffffffffc0); - ASSERT(f(0x8000000000000000, 63) == 0xffffffffffffffff); - ASSERT(f(0x4000000000000000, 62) == 1); - ASSERT(f(0x2000000000000000, 61) == 1); - ASSERT(f(0x1000000000000000, 60) == 1); - ASSERT(f(0x81000000000000, 48) == 0x81); - ASSERT(f(0x2000000000000, 49) == 1); - ASSERT(f(0x10000000000, 40) == 1); - ASSERT(f(0x7f800000000000, 47) == 0xff); - ASSERT(f(0x100000000000000, 56) == 1); - ASSERT(f(0xffffff0000000000, 40) == 0xffffffffffffffff); - ASSERT(f(0xfffffffe00000000, 33) == 0xffffffffffffffff); - ASSERT(f(0x8000000000000001, 63) == 0xffffffffffffffff); - ASSERT(f(0x1000000000000, 48) == 1); - ASSERT(f(0xffff800000000000, 47) == 0xffffffffffffffff); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/rshr64.c b/tests/rshr64.c new file mode 100644 index 0000000..03cfae7 --- /dev/null +++ b/tests/rshr64.c @@ -0,0 +1,115 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 2, operands); + + ejit_rshr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int64_t), do_jit); + + assert(erf2(f, EJIT_ARG(0xfe, int64_t), EJIT_ARG(1, int64_t)) == 0x7f); + assert(erf2(f, EJIT_ARG(0x1fffc, int64_t), + EJIT_ARG(2, int64_t)) == 0x7fff); + assert(erf2(f, EJIT_ARG(0x40000000, int64_t), + EJIT_ARG(30, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x20000000, int64_t), + EJIT_ARG(29, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x10000000, int64_t), + EJIT_ARG(28, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x810000, int64_t), + EJIT_ARG(16, int64_t)) == 0x81); + assert(erf2(f, EJIT_ARG(0x20000, int64_t), EJIT_ARG(17, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x40000, int64_t), EJIT_ARG(18, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x7f8000, int64_t), + EJIT_ARG(15, int64_t)) == 0xff); + assert(erf2(f, EJIT_ARG(0x1000000, int64_t), + EJIT_ARG(24, int64_t)) == 1); + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), EJIT_ARG(0, int64_t) + ) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(0x3fffffff8, int64_t), EJIT_ARG(3, int64_t) + ) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(0xffffff00, int64_t), EJIT_ARG(8, int64_t) + ) == 0xffffff); + + assert(erf2(f, EJIT_ARG(0xfe00000000, int64_t), EJIT_ARG(33, int64_t) + ) == 0x7f); + + assert(erf2(f, EJIT_ARG(0x1ffffc00000000, int64_t), + EJIT_ARG(34, int64_t) + ) == 0x7ffff); + + assert(erf2(f, EJIT_ARG(0xfffffff800000000, int64_t), + EJIT_ARG(29, int64_t) + ) == (int64_t)0xffffffffffffffc0); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(63, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(erf2(f, EJIT_ARG(0x4000000000000000, int64_t), + EJIT_ARG(62, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x2000000000000000, int64_t), + EJIT_ARG(61, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x1000000000000000, int64_t), + EJIT_ARG(60, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0xffffffc080000000, int64_t), + EJIT_ARG(31, int64_t) + ) == (int64_t)0xffffffffffffff81); + + assert(erf2(f, EJIT_ARG(0x81000000000000, int64_t), + EJIT_ARG(48, int64_t) + ) == 0x81); + + assert(erf2(f, EJIT_ARG(0x2000000000000, int64_t), EJIT_ARG(49, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x10000000000, int64_t), EJIT_ARG(40, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x7f800000000000, int64_t), + EJIT_ARG(47, int64_t) + ) == 0xff); + + assert(erf2(f, EJIT_ARG(0x100000000000000, int64_t), + EJIT_ARG(56, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0xffffff0000000000, int64_t), + EJIT_ARG(40, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(erf2(f, EJIT_ARG(0xfffffffe00000000, int64_t), + EJIT_ARG(33, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(erf2(f, EJIT_ARG(0x8000000000000001, int64_t), + EJIT_ARG(63, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(erf2(f, EJIT_ARG(0x1000000000000, int64_t), EJIT_ARG(48, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0xffff800000000000, int64_t), + EJIT_ARG(47, int64_t) + ) == (int64_t)0xffffffffffffffff); + + ejit_destroy_func(f); +} diff --git a/tests/rshr_u.c b/tests/rshr_u.c deleted file mode 100644 index 082b9ed..0000000 --- a/tests/rshr_u.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1)); - - jit_rshr_u(j, JIT_R0, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - size_t size = 0; - void* ret = jit_end(j, &size); - - jit_word_t (*f)(jit_word_t, jit_word_t) = ret; - - ASSERT(f(0xfe, 1) == 0x7f); - ASSERT(f(0x1fffc, 2) == 0x7fff); - ASSERT(f(0x80000000, 31) == 1); - ASSERT(f(0x40000000, 30) == 1); - ASSERT(f(0x20000000, 29) == 1); - ASSERT(f(0x10000000, 28) == 1); - ASSERT(f(0x810000, 16) == 0x81); - ASSERT(f(0x20000, 17) == 1); - ASSERT(f(0x40000, 18) == 1); - ASSERT(f(0x7f8000, 15) == 0xff); - ASSERT(f(0x1000000, 24) == 1); - ASSERT(f(0xffffff00, 8) == 0xffffff); - ASSERT(f(0x7fffffff, 0) == 0x7fffffff); -#if EJIT_WORDSIZE == 32 - ASSERT(f(0xfffffff8, 3) == 0x1fffffff); -#else - ASSERT(f(0x3fffffff8, 3) == 0x7fffffff); - ASSERT(f(0xffffffc080000000, 31) == 0x1ffffff81); - ASSERT(f(0xfe00000000, 33) == 0x7f); - ASSERT(f(0x1ffffc00000000, 34) == 0x7ffff); - ASSERT(f(0xfffffff800000000, 29) == 0x7ffffffc0); - ASSERT(f(0x8000000000000000, 63) == 1); - ASSERT(f(0x4000000000000000, 62) == 1); - ASSERT(f(0x2000000000000000, 61) == 1); - ASSERT(f(0x1000000000000000, 60) == 1); - ASSERT(f(0x81000000000000, 48) == 0x81); - ASSERT(f(0x2000000000000, 49) == 1); - ASSERT(f(0x10000000000, 40) == 1); - ASSERT(f(0x7f800000000000, 47) == 0xff); - ASSERT(f(0x100000000000000, 56) == 1); - ASSERT(f(0xffffff0000000000, 40) == 0xffffff); - ASSERT(f(0xfffffffe00000000, 33) == 0x7fffffff); - ASSERT(f(0x8000000000000001, 63) == 1); - ASSERT(f(0x1000000000000, 48) == 1); - ASSERT(f(0xffff800000000000, 47) == 0x1ffff); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/rshr_u64.c b/tests/rshr_u64.c new file mode 100644 index 0000000..86ce416 --- /dev/null +++ b/tests/rshr_u64.c @@ -0,0 +1,113 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 2, operands); + + ejit_rshr_u(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int64_t), do_jit); + + assert(erf2(f, EJIT_ARG(0xfe, int64_t), EJIT_ARG(1, int64_t)) == 0x7f); + assert(erf2(f, EJIT_ARG(0x1fffc, int64_t), + EJIT_ARG(2, int64_t)) == 0x7fff); + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(31, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x40000000, int64_t), + EJIT_ARG(30, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x20000000, int64_t), + EJIT_ARG(29, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x10000000, int64_t), + EJIT_ARG(28, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x810000, int64_t), + EJIT_ARG(16, int64_t)) == 0x81); + assert(erf2(f, EJIT_ARG(0x20000, int64_t), EJIT_ARG(17, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x40000, int64_t), EJIT_ARG(18, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0x7f8000, int64_t), + EJIT_ARG(15, int64_t)) == 0xff); + assert(erf2(f, EJIT_ARG(0x1000000, int64_t), + EJIT_ARG(24, int64_t)) == 1); + assert(erf2(f, EJIT_ARG(0xffffff00, int64_t), + EJIT_ARG(8, int64_t)) == 0xffffff); + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0, int64_t)) == 0x7fffffff); + assert(erf2(f, EJIT_ARG(0x3fffffff8, int64_t), EJIT_ARG(3, int64_t) + ) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(0xffffffc080000000, int64_t), + EJIT_ARG(31, int64_t) + ) == 0x1ffffff81); + + assert(erf2(f, EJIT_ARG(0xfe00000000, int64_t), EJIT_ARG(33, int64_t) + ) == 0x7f); + + assert(erf2(f, EJIT_ARG(0x1ffffc00000000, int64_t), + EJIT_ARG(34, int64_t) + ) == 0x7ffff); + + assert(erf2(f, EJIT_ARG(0xfffffff800000000, int64_t), + EJIT_ARG(29, int64_t) + ) == 0x7ffffffc0); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(63, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x4000000000000000, int64_t), + EJIT_ARG(62, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x2000000000000000, int64_t), + EJIT_ARG(61, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x1000000000000000, int64_t), + EJIT_ARG(60, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x81000000000000, int64_t), + EJIT_ARG(48, int64_t) + ) == 0x81); + + assert(erf2(f, EJIT_ARG(0x2000000000000, int64_t), EJIT_ARG(49, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x10000000000, int64_t), EJIT_ARG(40, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x7f800000000000, int64_t), + EJIT_ARG(47, int64_t) + ) == 0xff); + + assert(erf2(f, EJIT_ARG(0x100000000000000, int64_t), + EJIT_ARG(56, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0xffffff0000000000, int64_t), + EJIT_ARG(40, int64_t) + ) == 0xffffff); + + assert(erf2(f, EJIT_ARG(0xfffffffe00000000, int64_t), + EJIT_ARG(33, int64_t) + ) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(0x8000000000000001, int64_t), + EJIT_ARG(63, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0x1000000000000, int64_t), EJIT_ARG(48, int64_t) + ) == 1); + + assert(erf2(f, EJIT_ARG(0xffff800000000000, int64_t), + EJIT_ARG(47, int64_t) + ) == 0x1ffff); + + ejit_destroy_func(f); +} diff --git a/tests/sti_16.c b/tests/sti_16.c new file mode 100644 index 0000000..f2edbea --- /dev/null +++ b/tests/sti_16.c @@ -0,0 +1,28 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint16_t data[] = { 0x1212, 0x0000, 0x3434 }; + +int main() +{ + struct ejit_operand operands[1] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int16_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 1, operands); + + ejit_sti_16(f, EJIT_GPR(0), &data[1]); + ejit_ret(f); + + ejit_select_compile_func(f, 1, 0, EJIT_USE64(int16_t), do_jit); + + assert(data[0] == 0x1212); + assert(data[1] == 0x00); + assert(data[2] == 0x3434); + erf1(f, EJIT_ARG(-1, int16_t)); + assert(data[0] == 0x1212); + assert(data[1] == 0xffff); + assert(data[2] == 0x3434); + + ejit_destroy_func(f); +} diff --git a/tests/sti_32.c b/tests/sti_32.c new file mode 100644 index 0000000..12b2d7c --- /dev/null +++ b/tests/sti_32.c @@ -0,0 +1,28 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint32_t data[] = { 0x12121212, 0x00000000, 0x34343434 }; + +int main() +{ + struct ejit_operand operands[1] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int32_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 1, operands); + + ejit_sti_32(f, EJIT_GPR(0), &data[1]); + ejit_ret(f); + + ejit_select_compile_func(f, 1, 0, EJIT_USE64(int32_t), do_jit); + + assert(data[0] == 0x12121212); + assert(data[1] == 0x00); + assert(data[2] == 0x34343434); + erf1(f, EJIT_ARG(-1, int32_t)); + assert(data[0] == 0x12121212); + assert(data[1] == 0xffffffff); + assert(data[2] == 0x34343434); + + ejit_destroy_func(f); +} diff --git a/tests/sti_64.c b/tests/sti_64.c new file mode 100644 index 0000000..8985d2d --- /dev/null +++ b/tests/sti_64.c @@ -0,0 +1,28 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint64_t data[] = { 0x1212121212121212, 0, 0x3434343434343434 }; + +int main() +{ + struct ejit_operand operands[1] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 1, operands); + + ejit_sti_64(f, EJIT_GPR(0), &data[1]); + ejit_ret(f); + + ejit_select_compile_func(f, 1, 0, EJIT_USE64(int64_t), do_jit); + + assert(data[0] == 0x1212121212121212); + assert(data[1] == 0x00); + assert(data[2] == 0x3434343434343434); + erf1(f, EJIT_ARG(-1, int64_t)); + assert(data[0] == 0x1212121212121212); + assert(data[1] == 0xffffffffffffffff); + assert(data[2] == 0x3434343434343434); + + ejit_destroy_func(f); +} diff --git a/tests/sti_8.c b/tests/sti_8.c new file mode 100644 index 0000000..5603c35 --- /dev/null +++ b/tests/sti_8.c @@ -0,0 +1,28 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint8_t data[] = { 0x12, 0x00, 0x34 }; + +int main() +{ + struct ejit_operand operands[1] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int8_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 1, operands); + + ejit_sti_8(f, EJIT_GPR(0), &data[1]); + ejit_ret(f); + + ejit_select_compile_func(f, 1, 0, EJIT_USE64(int8_t), do_jit); + + assert(data[0] == 0x12); + assert(data[1] == 0x00); + assert(data[2] == 0x34); + erf1(f, EJIT_ARG(-1, int8_t)); + assert(data[0] == 0x12); + assert(data[1] == 0xff); + assert(data[2] == 0x34); + + ejit_destroy_func(f); +} diff --git a/tests/sti_c.c b/tests/sti_c.c deleted file mode 100644 index e323b37..0000000 --- a/tests/sti_c.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "test.h" - -static uint8_t data[] = { 0x12, 0x00, 0x34 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_INT8, JIT_R1)); - - jit_sti_c(j, &data[1], JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(int8_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x12); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x34); - f(-1); - ASSERT(data[0] == 0x12); - ASSERT(data[1] == 0xff); - ASSERT(data[2] == 0x34); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/sti_d.c b/tests/sti_d.c index 9fce200..157e24d 100644 --- a/tests/sti_d.c +++ b/tests/sti_d.c @@ -1,31 +1,28 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" static double data[] = { -1.0, 0.0, 0.5 }; -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_fpr (JIT_OPERAND_ABI_DOUBLE, JIT_F0)); + struct ejit_operand operands[1] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 1, operands); - jit_sti_d(j, &data[1], JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); + ejit_sti_d(f, EJIT_FPR(0), &data[1]); + ejit_ret(f); - void (*f)(double) = jit_end(j, NULL); + ejit_select_compile_func(f, 0, 1, EJIT_USE64(double), do_jit); - ASSERT(data[0] == -1.0); - ASSERT(data[1] == 0.0); - ASSERT(data[2] == 0.5); - f(42.5); - ASSERT(data[0] == -1.0); - ASSERT(data[1] == 42.5); - ASSERT(data[2] == 0.5); -} + assert(data[0] == -1.0); + assert(data[1] == 0.0); + assert(data[2] == 0.5); + erf1(f, EJIT_ARG(42.5, double)); + assert(data[0] == -1.0); + assert(data[1] == 42.5); + assert(data[2] == 0.5); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + ejit_destroy_func(f); } diff --git a/tests/sti_f.c b/tests/sti_f.c index 67a0c38..6292353 100644 --- a/tests/sti_f.c +++ b/tests/sti_f.c @@ -1,31 +1,28 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" static float data[] = { -1.0, 0.0, 0.5 }; -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0)); + struct ejit_operand operands[1] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(float)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 1, operands); - jit_sti_f(j, &data[1], JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); + ejit_sti_f(f, EJIT_FPR(0), &data[1]); + ejit_ret(f); - void (*f)(float) = jit_end(j, NULL); + ejit_select_compile_func(f, 0, 1, EJIT_USE64(float), do_jit); - ASSERT(data[0] == -1.0f); - ASSERT(data[1] == 0.0f); - ASSERT(data[2] == 0.5f); - f(42.5f); - ASSERT(data[0] == -1.0f); - ASSERT(data[1] == 42.5f); - ASSERT(data[2] == 0.5f); -} + assert(data[0] == -1.0); + assert(data[1] == 0.0); + assert(data[2] == 0.5); + erf1(f, EJIT_ARG(42.5, float)); + assert(data[0] == -1.0); + assert(data[1] == 42.5); + assert(data[2] == 0.5); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + ejit_destroy_func(f); } diff --git a/tests/sti_i.c b/tests/sti_i.c deleted file mode 100644 index 1f014fd..0000000 --- a/tests/sti_i.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "test.h" - -static uint32_t data[] = { 0x12121212, 0x00000000, 0x34343434 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_INT32, JIT_R1)); - - jit_sti_i(j, &data[1], JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(int32_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x12121212); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x34343434); - f(-1); - ASSERT(data[0] == 0x12121212); - ASSERT(data[1] == 0xffffffff); - ASSERT(data[2] == 0x34343434); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/sti_l.c b/tests/sti_l.c deleted file mode 100644 index 36cca18..0000000 --- a/tests/sti_l.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ -#if EJIT_WORDSIZE > 32 - static uint64_t data[] = { 0x1212121212121212, 0, 0x3434343434343434 }; - - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_INT64, JIT_R1)); - - jit_sti_l(j, &data[1], JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(int64_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x1212121212121212); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x3434343434343434); - f(-1); - ASSERT(data[0] == 0x1212121212121212); - ASSERT(data[1] == 0xffffffffffffffff); - ASSERT(data[2] == 0x3434343434343434); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/sti_s.c b/tests/sti_s.c deleted file mode 100644 index 00941ea..0000000 --- a/tests/sti_s.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "test.h" - -static uint16_t data[] = { 0x1212, 0x0000, 0x3434 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_INT16, JIT_R1)); - - jit_sti_s(j, &data[1], JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(int16_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x1212); - ASSERT(data[1] == 0); - ASSERT(data[2] == 0x3434); - f(-1); - ASSERT(data[0] == 0x1212); - ASSERT(data[1] == 0xffff); - ASSERT(data[2] == 0x3434); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/str_atomic.c b/tests/str_atomic.c deleted file mode 100644 index 5086078..0000000 --- a/tests/str_atomic.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -static long data[] = { 0x12121212, 0x00000000, 0x34343434 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_INT32, JIT_R1)); - - jit_str_atomic(j, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(void*, int32_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x12121212); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x34343434); - f(&data[1], 0x0f0f0f0f); - ASSERT(data[0] == 0x12121212); - ASSERT(data[1] == 0x0f0f0f0f); - ASSERT(data[2] == 0x34343434); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/str_c.c b/tests/str_c.c deleted file mode 100644 index 492cc73..0000000 --- a/tests/str_c.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -static uint8_t data[] = { 0x12, 0x00, 0x34 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_INT8, JIT_R1)); - - jit_str_c(j, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(void*, int8_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x12); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x34); - f(&data[1], -1); - ASSERT(data[0] == 0x12); - ASSERT(data[1] == 0xff); - ASSERT(data[2] == 0x34); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/str_d.c b/tests/str_d.c deleted file mode 100644 index 41db4fd..0000000 --- a/tests/str_d.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -static double data[] = { -1.0, 0.0, 0.5 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_fpr (JIT_OPERAND_ABI_DOUBLE, JIT_F0)); - - jit_str_d(j, JIT_R0, JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(void*, double) = jit_end(j, NULL); - - ASSERT(data[0] == -1.0); - ASSERT(data[1] == 0.0); - ASSERT(data[2] == 0.5); - f(&data[1], 42.5); - ASSERT(data[0] == -1.0); - ASSERT(data[1] == 42.5); - ASSERT(data[2] == 0.5); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/str_f.c b/tests/str_f.c deleted file mode 100644 index 7b394ae..0000000 --- a/tests/str_f.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -static float data[] = { -1.0, 0.0, 0.5 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0)); - - jit_str_f(j, JIT_R0, JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(void*, float) = jit_end(j, NULL); - - ASSERT(data[0] == -1.0f); - ASSERT(data[1] == 0.0f); - ASSERT(data[2] == 0.5f); - f(&data[1], 42.5f); - ASSERT(data[0] == -1.0f); - ASSERT(data[1] == 42.5f); - ASSERT(data[2] == 0.5f); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/str_i.c b/tests/str_i.c deleted file mode 100644 index 39e88b9..0000000 --- a/tests/str_i.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -static uint32_t data[] = { 0x12121212, 0x00000000, 0x34343434 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_INT32, JIT_R1)); - - jit_str_i(j, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(void*, int32_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x12121212); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x34343434); - f(&data[1], -1); - ASSERT(data[0] == 0x12121212); - ASSERT(data[1] == 0xffffffff); - ASSERT(data[2] == 0x34343434); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/str_l.c b/tests/str_l.c deleted file mode 100644 index c3338ff..0000000 --- a/tests/str_l.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ -#if EJIT_WORDSIZE > 32 - static uint64_t data[] = { 0x1212121212121212, 0, 0x3434343434343434 }; - - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_INT64, JIT_R1)); - - jit_str_l(j, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(void*, int64_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x1212121212121212); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x3434343434343434); - f(&data[1], -1); - ASSERT(data[0] == 0x1212121212121212); - ASSERT(data[1] == 0xffffffffffffffff); - ASSERT(data[2] == 0x3434343434343434); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/str_s.c b/tests/str_s.c deleted file mode 100644 index d2e7e45..0000000 --- a/tests/str_s.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -static uint16_t data[] = { 0x1212, 0x0000, 0x3434 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_INT16, JIT_R1)); - - jit_str_s(j, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(void*, int16_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x1212); - ASSERT(data[1] == 0); - ASSERT(data[2] == 0x3434); - f(&data[1], -1); - ASSERT(data[0] == 0x1212); - ASSERT(data[1] == 0xffff); - ASSERT(data[2] == 0x3434); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/stxi_16.c b/tests/stxi_16.c new file mode 100644 index 0000000..eeec55c --- /dev/null +++ b/tests/stxi_16.c @@ -0,0 +1,29 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint16_t data[] = { 0x1212, 0x0000, 0x3434 }; + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int16_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 2, operands); + + ejit_stxi_16(f, EJIT_GPR(1), EJIT_GPR(0), (uintptr_t)data); + ejit_ret(f); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int), do_jit); + + assert(data[0] == 0x1212); + assert(data[1] == 0); + assert(data[2] == 0x3434); + erf2(f, EJIT_ARG(sizeof(int16_t), int), EJIT_ARG(-1, int16_t)); + assert(data[0] == 0x1212); + assert(data[1] == 0xffff); + assert(data[2] == 0x3434); + + ejit_destroy_func(f); +} diff --git a/tests/stxi_32.c b/tests/stxi_32.c new file mode 100644 index 0000000..b853679 --- /dev/null +++ b/tests/stxi_32.c @@ -0,0 +1,29 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint32_t data[] = { 0x12121212, 0x00000000, 0x34343434 }; + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int32_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 2, operands); + + ejit_stxi_32(f, EJIT_GPR(1), EJIT_GPR(0), (uintptr_t)data); + ejit_ret(f); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int32_t), do_jit); + + assert(data[0] == 0x12121212); + assert(data[1] == 0x00); + assert(data[2] == 0x34343434); + erf2(f, EJIT_ARG(sizeof(int32_t), int), EJIT_ARG(-1, int32_t)); + assert(data[0] == 0x12121212); + assert(data[1] == 0xffffffff); + assert(data[2] == 0x34343434); + + ejit_destroy_func(f); +} diff --git a/tests/stxi_64.c b/tests/stxi_64.c new file mode 100644 index 0000000..83d3aae --- /dev/null +++ b/tests/stxi_64.c @@ -0,0 +1,29 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint64_t data[] = { 0x1212121212121212, 0, 0x3434343434343434 }; + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 2, operands); + + ejit_stxi_64(f, EJIT_GPR(1), EJIT_GPR(0), (uintptr_t)data); + ejit_ret(f); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int64_t), do_jit); + + assert(data[0] == 0x1212121212121212); + assert(data[1] == 0x00); + assert(data[2] == 0x3434343434343434); + erf2(f, EJIT_ARG(sizeof(int64_t), int), EJIT_ARG(-1, int64_t)); + assert(data[0] == 0x1212121212121212); + assert(data[1] == 0xffffffffffffffff); + assert(data[2] == 0x3434343434343434); + + ejit_destroy_func(f); +} diff --git a/tests/stxi_8.c b/tests/stxi_8.c new file mode 100644 index 0000000..c83d75d --- /dev/null +++ b/tests/stxi_8.c @@ -0,0 +1,29 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint8_t data[] = { 0x12, 0x00, 0x34 }; + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int8_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 2, operands); + + ejit_stxi_8(f, EJIT_GPR(1), EJIT_GPR(0), (uintptr_t)data); + ejit_ret(f); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int), do_jit); + + assert(data[0] == 0x12); + assert(data[1] == 0x00); + assert(data[2] == 0x34); + erf2(f, EJIT_ARG(sizeof(int8_t), int), EJIT_ARG(-1, int8_t)); + assert(data[0] == 0x12); + assert(data[1] == 0xff); + assert(data[2] == 0x34); + + ejit_destroy_func(f); +} diff --git a/tests/stxi_c.c b/tests/stxi_c.c deleted file mode 100644 index 828a9d4..0000000 --- a/tests/stxi_c.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -static uint8_t data[] = { 0x12, 0x00, 0x34 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2), - jit_operand_gpr (JIT_OPERAND_ABI_INT8, JIT_R1)); - - jit_stxi_c(j, (uintptr_t)data, JIT_R2, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(jit_word_t, int8_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x12); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x34); - f(1, -1); - ASSERT(data[0] == 0x12); - ASSERT(data[1] == 0xff); - ASSERT(data[2] == 0x34); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/stxi_d.c b/tests/stxi_d.c index 85b3a4a..6de76f8 100644 --- a/tests/stxi_d.c +++ b/tests/stxi_d.c @@ -1,32 +1,29 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" static double data[] = { -1.0, 0.0, 0.5 }; -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2), - jit_operand_fpr (JIT_OPERAND_ABI_DOUBLE, JIT_F0)); + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int)), + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 2, operands); - jit_stxi_d(j, (uintptr_t)data, JIT_R2, JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); + ejit_stxi_d(f, EJIT_FPR(0), EJIT_GPR(0), (uintptr_t)data); + ejit_ret(f); - void (*f)(jit_word_t, double) = jit_end(j, NULL); + ejit_select_compile_func(f, 1, 1, EJIT_USE64(double), do_jit); - ASSERT(data[0] == -1.0); - ASSERT(data[1] == 0.0); - ASSERT(data[2] == 0.5); - f(8, 42.5); - ASSERT(data[0] == -1.0); - ASSERT(data[1] == 42.5); - ASSERT(data[2] == 0.5); -} + assert(data[0] == -1.0f); + assert(data[1] == 0.0f); + assert(data[2] == 0.5f); + erf2(f, EJIT_ARG(sizeof(double), int), EJIT_ARG(42.5, double)); + assert(data[0] == -1.0f); + assert(data[1] == 42.5); + assert(data[2] == 0.5f); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + ejit_destroy_func(f); } diff --git a/tests/stxi_f.c b/tests/stxi_f.c index 7325b3c..0b700fe 100644 --- a/tests/stxi_f.c +++ b/tests/stxi_f.c @@ -1,32 +1,29 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" static float data[] = { -1.0, 0.0, 0.5 }; -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2), - jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0)); + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int)), + EJIT_OPERAND_FPR(0, EJIT_TYPE(float)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 2, operands); - jit_stxi_f(j, (uintptr_t)data, JIT_R2, JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); + ejit_stxi_f(f, EJIT_FPR(0), EJIT_GPR(0), (uintptr_t)data); + ejit_ret(f); - void (*f)(jit_word_t, float) = jit_end(j, NULL); + ejit_select_compile_func(f, 1, 1, EJIT_USE64(float), do_jit); - ASSERT(data[0] == -1.0f); - ASSERT(data[1] == 0.0f); - ASSERT(data[2] == 0.5f); - f(4, 42.5f); - ASSERT(data[0] == -1.0f); - ASSERT(data[1] == 42.5f); - ASSERT(data[2] == 0.5f); -} + assert(data[0] == -1.0); + assert(data[1] == 0.0); + assert(data[2] == 0.5); + erf2(f, EJIT_ARG(sizeof(float), int), EJIT_ARG(42.5, float)); + assert(data[0] == -1.0); + assert(data[1] == 42.5); + assert(data[2] == 0.5); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + ejit_destroy_func(f); } diff --git a/tests/stxi_i.c b/tests/stxi_i.c deleted file mode 100644 index 37bfd8f..0000000 --- a/tests/stxi_i.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -static uint32_t data[] = { 0x12121212, 0x00000000, 0x34343434 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2), - jit_operand_gpr (JIT_OPERAND_ABI_INT32, JIT_R1)); - - jit_stxi_i(j, (uintptr_t)data, JIT_R2, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(jit_word_t, int32_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x12121212); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x34343434); - f(4, -1); - ASSERT(data[0] == 0x12121212); - ASSERT(data[1] == 0xffffffff); - ASSERT(data[2] == 0x34343434); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/stxi_l.c b/tests/stxi_l.c deleted file mode 100644 index a758fa9..0000000 --- a/tests/stxi_l.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ -#if EJIT_WORDSIZE > 32 - static uint64_t data[] = { 0x1212121212121212, 0, 0x3434343434343434 }; - - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2), - jit_operand_gpr (JIT_OPERAND_ABI_INT64, JIT_R1)); - - jit_stxi_l(j, (uintptr_t)data, JIT_R2, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(jit_word_t, int64_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x1212121212121212); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x3434343434343434); - f(8, -1); - ASSERT(data[0] == 0x1212121212121212); - ASSERT(data[1] == 0xffffffffffffffff); - ASSERT(data[2] == 0x3434343434343434); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/stxi_s.c b/tests/stxi_s.c deleted file mode 100644 index d3aebc3..0000000 --- a/tests/stxi_s.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -static uint16_t data[] = { 0x1212, 0x0000, 0x3434 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2), - jit_operand_gpr (JIT_OPERAND_ABI_INT16, JIT_R1)); - - jit_stxi_s(j, (uintptr_t)data, JIT_R2, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(jit_word_t, int16_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x1212); - ASSERT(data[1] == 0); - ASSERT(data[2] == 0x3434); - f(2, -1); - ASSERT(data[0] == 0x1212); - ASSERT(data[1] == 0xffff); - ASSERT(data[2] == 0x3434); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/stxr_16.c b/tests/stxr_16.c new file mode 100644 index 0000000..865eda0 --- /dev/null +++ b/tests/stxr_16.c @@ -0,0 +1,35 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint16_t data[] = { 0x1212, 0x0000, 0x3434 }; + +int main() +{ + struct ejit_operand operands[3] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(void *)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int)), + EJIT_OPERAND_GPR(2, EJIT_TYPE(int16_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 3, operands); + + ejit_stxr_16(f, EJIT_GPR(2), EJIT_GPR(0), EJIT_GPR(1)); + ejit_ret(f); + + ejit_select_compile_func(f, 3, 0, EJIT_USE64(void *), do_jit); + + assert(data[0] == 0x1212); + assert(data[1] == 0); + assert(data[2] == 0x3434); + struct ejit_arg args[3] = { + EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int16_t), int), + EJIT_ARG(-1, int16_t) + }; + ejit_run_func(f, 3, args); + assert(data[0] == 0x1212); + assert(data[1] == 0xffff); + assert(data[2] == 0x3434); + + ejit_destroy_func(f); +} diff --git a/tests/stxr_32.c b/tests/stxr_32.c new file mode 100644 index 0000000..f23b902 --- /dev/null +++ b/tests/stxr_32.c @@ -0,0 +1,35 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint32_t data[] = { 0x12121212, 0x00000000, 0x34343434 }; + +int main() +{ + struct ejit_operand operands[3] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(void *)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int)), + EJIT_OPERAND_GPR(2, EJIT_TYPE(int32_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 3, operands); + + ejit_stxr_32(f, EJIT_GPR(2), EJIT_GPR(0), EJIT_GPR(1)); + ejit_ret(f); + + ejit_select_compile_func(f, 3, 0, EJIT_USE64(void *), do_jit); + + assert(data[0] == 0x12121212); + assert(data[1] == 0x00); + assert(data[2] == 0x34343434); + struct ejit_arg args[3] = { + EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int32_t), int), + EJIT_ARG(-1, int32_t) + }; + ejit_run_func(f, 3, args); + assert(data[0] == 0x12121212); + assert(data[1] == 0xffffffff); + assert(data[2] == 0x34343434); + + ejit_destroy_func(f); +} diff --git a/tests/stxr_64.c b/tests/stxr_64.c new file mode 100644 index 0000000..ae0a25c --- /dev/null +++ b/tests/stxr_64.c @@ -0,0 +1,35 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint64_t data[] = { 0x1212121212121212, 0, 0x3434343434343434 }; + +int main() +{ + struct ejit_operand operands[3] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(void *)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int)), + EJIT_OPERAND_GPR(2, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 3, operands); + + ejit_stxr_64(f, EJIT_GPR(2), EJIT_GPR(0), EJIT_GPR(1)); + ejit_ret(f); + + ejit_select_compile_func(f, 3, 0, EJIT_USE64(int64_t), do_jit); + + assert(data[0] == 0x1212121212121212); + assert(data[1] == 0x00); + assert(data[2] == 0x3434343434343434); + struct ejit_arg args[3] = { + EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int64_t), int), + EJIT_ARG(-1, int64_t) + }; + ejit_run_func(f, 3, args); + assert(data[0] == 0x1212121212121212); + assert(data[1] == 0xffffffffffffffff); + assert(data[2] == 0x3434343434343434); + + ejit_destroy_func(f); +} diff --git a/tests/stxr_8.c b/tests/stxr_8.c new file mode 100644 index 0000000..ede62d0 --- /dev/null +++ b/tests/stxr_8.c @@ -0,0 +1,35 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint8_t data[] = { 0x12, 0x00, 0x34 }; + +int main() +{ + struct ejit_operand operands[3] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(void *)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int)), + EJIT_OPERAND_GPR(2, EJIT_TYPE(int8_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 3, operands); + + ejit_stxr_8(f, EJIT_GPR(2), EJIT_GPR(0), EJIT_GPR(1)); + ejit_ret(f); + + ejit_select_compile_func(f, 3, 0, EJIT_USE64(void *), do_jit); + + assert(data[0] == 0x12); + assert(data[1] == 0x00); + assert(data[2] == 0x34); + struct ejit_arg args[3] = { + EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int8_t), int), + EJIT_ARG(-1, int8_t) + }; + ejit_run_func(f, 3, args); + assert(data[0] == 0x12); + assert(data[1] == 0xff); + assert(data[2] == 0x34); + + ejit_destroy_func(f); +} diff --git a/tests/stxr_c.c b/tests/stxr_c.c deleted file mode 100644 index 329083b..0000000 --- a/tests/stxr_c.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "test.h" - -static uint8_t data[] = { 0x12, 0x00, 0x34 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_3(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2), - jit_operand_gpr (JIT_OPERAND_ABI_INT8, JIT_R1)); - - jit_stxr_c(j, JIT_R0, JIT_R2, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(void*, jit_word_t, int8_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x12); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x34); - f(data, 1, -1); - ASSERT(data[0] == 0x12); - ASSERT(data[1] == 0xff); - ASSERT(data[2] == 0x34); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/stxr_d.c b/tests/stxr_d.c index ee6e86a..fe21a2a 100644 --- a/tests/stxr_d.c +++ b/tests/stxr_d.c @@ -1,33 +1,35 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" static double data[] = { -1.0, 0.0, 0.5 }; -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_3(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2), - jit_operand_fpr (JIT_OPERAND_ABI_DOUBLE, JIT_F0)); + struct ejit_operand operands[3] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(void *)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int)), + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 3, operands); - jit_stxr_d(j, JIT_R0, JIT_R2, JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); + ejit_stxr_d(f, EJIT_FPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_ret(f); - void (*f)(void*, jit_word_t, double) = jit_end(j, NULL); + ejit_select_compile_func(f, 2, 1, EJIT_USE64(void *), do_jit); - ASSERT(data[0] == -1.0); - ASSERT(data[1] == 0.0); - ASSERT(data[2] == 0.5); - f(data, 8, 42.5); - ASSERT(data[0] == -1.0); - ASSERT(data[1] == 42.5); - ASSERT(data[2] == 0.5); -} + assert(data[0] == -1.0); + assert(data[1] == 0.0); + assert(data[2] == 0.5); + struct ejit_arg args[3] = { + EJIT_ARG(data, void *), + EJIT_ARG(sizeof(double), int), + EJIT_ARG(42.5, double) + }; + ejit_run_func(f, 3, args); + assert(data[0] == -1.0); + assert(data[1] == 42.5); + assert(data[2] == 0.5); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + ejit_destroy_func(f); } diff --git a/tests/stxr_f.c b/tests/stxr_f.c index d5bf9bf..6b43c83 100644 --- a/tests/stxr_f.c +++ b/tests/stxr_f.c @@ -1,33 +1,35 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" static float data[] = { -1.0, 0.0, 0.5 }; -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_3(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2), - jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0)); + struct ejit_operand operands[3] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(void *)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int)), + EJIT_OPERAND_FPR(0, EJIT_TYPE(float)) + }; + struct ejit_func *f = ejit_create_func(EJIT_VOID, 3, operands); - jit_stxr_f(j, JIT_R0, JIT_R2, JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); + ejit_stxr_f(f, EJIT_FPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_ret(f); - void (*f)(void*, jit_word_t, float) = jit_end(j, NULL); + ejit_select_compile_func(f, 2, 1, EJIT_USE64(void *), do_jit); - ASSERT(data[0] == -1.0f); - ASSERT(data[1] == 0.0f); - ASSERT(data[2] == 0.5f); - f(data, 4, 42.5f); - ASSERT(data[0] == -1.0f); - ASSERT(data[1] == 42.5f); - ASSERT(data[2] == 0.5f); -} + assert(data[0] == -1.0); + assert(data[1] == 0.0); + assert(data[2] == 0.5); + struct ejit_arg args[3] = { + EJIT_ARG(data, void *), + EJIT_ARG(sizeof(float), int), + EJIT_ARG(42.5, float) + }; + ejit_run_func(f, 3, args); + assert(data[0] == -1.0); + assert(data[1] == 42.5); + assert(data[2] == 0.5); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + ejit_destroy_func(f); } diff --git a/tests/stxr_i.c b/tests/stxr_i.c deleted file mode 100644 index 5ee69e7..0000000 --- a/tests/stxr_i.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "test.h" - -static uint32_t data[] = { 0x12121212, 0x00000000, 0x34343434 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_3(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2), - jit_operand_gpr (JIT_OPERAND_ABI_INT32, JIT_R1)); - - jit_stxr_i(j, JIT_R0, JIT_R2, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(void*, jit_word_t, int32_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x12121212); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x34343434); - f(data, 4, -1); - ASSERT(data[0] == 0x12121212); - ASSERT(data[1] == 0xffffffff); - ASSERT(data[2] == 0x34343434); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/stxr_l.c b/tests/stxr_l.c deleted file mode 100644 index 6562dda..0000000 --- a/tests/stxr_l.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ -#if EJIT_WORDSIZE > 32 - static uint64_t data[] = { 0x1212121212121212, 0, 0x3434343434343434 }; - - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_3(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2), - jit_operand_gpr (JIT_OPERAND_ABI_INT64, JIT_R1)); - - jit_stxr_l(j, JIT_R0, JIT_R2, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(void*, jit_word_t, int64_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x1212121212121212); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x3434343434343434); - f(data, 8, -1); - ASSERT(data[0] == 0x1212121212121212); - ASSERT(data[1] == 0xffffffffffffffff); - ASSERT(data[2] == 0x3434343434343434); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/stxr_s.c b/tests/stxr_s.c deleted file mode 100644 index 8505892..0000000 --- a/tests/stxr_s.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "test.h" - -static uint16_t data[] = { 0x1212, 0x0000, 0x3434 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_3(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2), - jit_operand_gpr (JIT_OPERAND_ABI_INT16, JIT_R1)); - - jit_stxr_s(j, JIT_R0, JIT_R2, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(void*, jit_word_t, int16_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x1212); - ASSERT(data[1] == 0); - ASSERT(data[2] == 0x3434); - f(data, 2, -1); - ASSERT(data[0] == 0x1212); - ASSERT(data[1] == 0xffff); - ASSERT(data[2] == 0x3434); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/subr.c b/tests/subr.c index e2c22bc..62ac130 100644 --- a/tests/subr.c +++ b/tests/subr.c @@ -1,26 +1,21 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1)); + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(long)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(long)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); - jit_subr(j, JIT_R0, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); + ejit_subr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); - size_t size = 0; - void* ret = jit_end(j, &size); + ejit_select_compile_func(f, 2, 0, EJIT_USE64(long), do_jit); - int (*f)(int, int) = ret; - ASSERT(f(42, 69) == -27); -} + assert(erf2(f, EJIT_ARG(42, long), EJIT_ARG(69, long)) == -27); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + ejit_destroy_func(f); } diff --git a/tests/subr_f.c b/tests/subr_f.c index 3fdf071..02cb1c9 100644 --- a/tests/subr_f.c +++ b/tests/subr_f.c @@ -1,27 +1,25 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0), - jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F1)); + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)), + EJIT_OPERAND_FPR(1, EJIT_TYPE(double)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 2, operands); - jit_subr_f(j, JIT_F0, JIT_F0, JIT_F1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr_f(j, JIT_F0); + ejit_subr_f(f, EJIT_FPR(0), EJIT_FPR(0), EJIT_FPR(1)); + ejit_retr_f(f, EJIT_FPR(0)); - size_t size = 0; - void* ret = jit_end(j, &size); + ejit_select_compile_func(f, 0, 2, EJIT_USE64(double), do_jit); - float (*f)(float, float) = ret; - ASSERT(f(42.f, 69.f) == -27.f); - ASSERT(f(42.0f, 69.5f) == -27.5f); -} + assert(erff2(f, EJIT_ARG(42., double), EJIT_ARG(69., double) + ) == -27.); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + assert(erff2(f, EJIT_ARG(42.5, double), EJIT_ARG(69., double) + ) == -26.5); + + ejit_destroy_func(f); } diff --git a/tests/swap_atomic.c b/tests/swap_atomic.c deleted file mode 100644 index 5803164..0000000 --- a/tests/swap_atomic.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -static long data[] = { 0x12121212, 0x00000000, 0x34343434 }; - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_INT32, JIT_R1)); - - jit_swap_atomic(j, JIT_R0, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_ret(j); - - void (*f)(void*, int32_t) = jit_end(j, NULL); - - ASSERT(data[0] == 0x12121212); - ASSERT(data[1] == 0x00); - ASSERT(data[2] == 0x34343434); - f(&data[1], 0x0f0f0f0f); - ASSERT(data[0] == 0x12121212); - ASSERT(data[1] == 0x0f0f0f0f); - ASSERT(data[2] == 0x34343434); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/truncr_d_32.c b/tests/truncr_d_32.c new file mode 100644 index 0000000..b7109b4 --- /dev/null +++ b/tests/truncr_d_32.c @@ -0,0 +1,27 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int32_t), 1, operands); + + ejit_truncr_d_32(f, EJIT_GPR(0), EJIT_FPR(0)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 1, 1, EJIT_TYPE(int32_t), do_jit); + + assert(erf1(f, EJIT_ARG(0.0, double)) == 0); + assert(erf1(f, EJIT_ARG(-0.0, double)) == 0); + assert(erf1(f, EJIT_ARG(0.5, double)) == 0); + assert(erf1(f, EJIT_ARG(-0.5, double)) == 0); + assert(erf1(f, EJIT_ARG(1.5, double)) == 1); + assert(erf1(f, EJIT_ARG(-1.5, double)) == -1); + assert(erf1(f, EJIT_ARG(2.5, double)) == 2); + assert(erf1(f, EJIT_ARG(-2.5, double)) == -2); + + ejit_destroy_func(f); +} diff --git a/tests/truncr_d_64.c b/tests/truncr_d_64.c new file mode 100644 index 0000000..fad0ae9 --- /dev/null +++ b/tests/truncr_d_64.c @@ -0,0 +1,27 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 1, operands); + + ejit_truncr_d_64(f, EJIT_GPR(0), EJIT_FPR(0)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 1, 1, EJIT_TYPE(int64_t), do_jit); + + assert(erf1(f, EJIT_ARG(0.0, double)) == 0); + assert(erf1(f, EJIT_ARG(-0.0, double)) == 0); + assert(erf1(f, EJIT_ARG(0.5, double)) == 0); + assert(erf1(f, EJIT_ARG(-0.5, double)) == 0); + assert(erf1(f, EJIT_ARG(1.5, double)) == 1); + assert(erf1(f, EJIT_ARG(-1.5, double)) == -1); + assert(erf1(f, EJIT_ARG(2.5, double)) == 2); + assert(erf1(f, EJIT_ARG(-2.5, double)) == -2); + + ejit_destroy_func(f); +} diff --git a/tests/truncr_d_i.c b/tests/truncr_d_i.c deleted file mode 100644 index 09e163e..0000000 --- a/tests/truncr_d_i.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_fpr (JIT_OPERAND_ABI_DOUBLE, JIT_F0)); - - jit_truncr_d_i(j, JIT_R0, JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - int (*f)(double) = jit_end(j, NULL); - - ASSERT(f(0.0) == 0); - ASSERT(f(-0.0) == 0); - ASSERT(f(0.5) == 0); - ASSERT(f(-0.5) == 0); - ASSERT(f(1.5) == 1); - ASSERT(f(-1.5) == -1); - ASSERT(f(2.5) == 2); - ASSERT(f(-2.5) == -2); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/truncr_d_l.c b/tests/truncr_d_l.c deleted file mode 100644 index ee9b477..0000000 --- a/tests/truncr_d_l.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ -#if EJIT_WORDSIZE > 32 - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_fpr (JIT_OPERAND_ABI_DOUBLE, JIT_F0)); - - jit_truncr_d_l(j, JIT_R0, JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - int64_t (*f)(double) = jit_end(j, NULL); - - ASSERT(f(0.0) == 0); - ASSERT(f(-0.0) == 0); - ASSERT(f(0.5) == 0); - ASSERT(f(-0.5) == 0); - ASSERT(f(1.5) == 1); - ASSERT(f(-1.5) == -1); - ASSERT(f(2.5) == 2); - ASSERT(f(-2.5) == -2); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/truncr_f_i.c b/tests/truncr_f_i.c deleted file mode 100644 index 0314753..0000000 --- a/tests/truncr_f_i.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0)); - - jit_truncr_f_i(j, JIT_R0, JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - int (*f)(float) = jit_end(j, NULL); - - ASSERT(f(0.0) == 0); - ASSERT(f(-0.0) == 0); - ASSERT(f(0.5) == 0); - ASSERT(f(-0.5) == 0); - ASSERT(f(1.5) == 1); - ASSERT(f(-1.5) == -1); - ASSERT(f(2.5) == 2); - ASSERT(f(-2.5) == -2); -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/truncr_f_l.c b/tests/truncr_f_l.c deleted file mode 100644 index ad95744..0000000 --- a/tests/truncr_f_l.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ -#if EJIT_WORDSIZE > 32 - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0)); - - jit_truncr_f_l(j, JIT_R0, JIT_F0); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - int64_t (*f)(float) = jit_end(j, NULL); - - ASSERT(f(0.0) == 0); - ASSERT(f(-0.0) == 0); - ASSERT(f(0.5) == 0); - ASSERT(f(-0.5) == 0); - ASSERT(f(1.5) == 1); - ASSERT(f(-1.5) == -1); - ASSERT(f(2.5) == 2); - ASSERT(f(-2.5) == -2); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/xori.c b/tests/xori.c deleted file mode 100644 index 16197ce..0000000 --- a/tests/xori.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0)); - - jit_xori(j, JIT_R0, JIT_R0, 1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - size_t size = 0; - void* ret = jit_end(j, &size); - - jit_word_t (*f)(jit_word_t) = ret; - - ASSERT(f(0x7fffffff) == 0x7ffffffe); - ASSERT(f(0x80000000) == 0x80000001); -#if EJIT_WORDSIZE == 64 - ASSERT(f(0x7fffffffffffffff) == 0x7ffffffffffffffe); - ASSERT(f(0x8000000000000000) == 0x8000000000000001); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/xori64.c b/tests/xori64.c new file mode 100644 index 0000000..6f3984f --- /dev/null +++ b/tests/xori64.c @@ -0,0 +1,26 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[1] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int), 1, operands); + + ejit_xori(f, EJIT_GPR(0), EJIT_GPR(0), 1); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 1, 0, EJIT_USE64(int64_t), do_jit); + + assert(erf1(f, EJIT_ARG(0x7fffffff, int64_t)) == 0x7ffffffe); + assert(erf1(f, EJIT_ARG(0x80000000, int64_t)) == 0x80000001); + assert(erf1(f, + EJIT_ARG(0x7fffffffffffffff, + int64_t)) == 0x7ffffffffffffffe); + assert(erf1(f, EJIT_ARG(0x8000000000000000, int64_t) + ) == (int64_t)0x8000000000000001); + + ejit_destroy_func(f); +} diff --git a/tests/xorr.c b/tests/xorr.c deleted file mode 100644 index 123bfb7..0000000 --- a/tests/xorr.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0), - jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1)); - - jit_xorr(j, JIT_R0, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - size_t size = 0; - void* ret = jit_end(j, &size); - - jit_word_t (*f)(jit_word_t, jit_word_t) = ret; - - ASSERT(f(0x7fffffff, 1) == 0x7ffffffe); - ASSERT(f(1, 0x7fffffff) == 0x7ffffffe); - ASSERT(f(0x80000000, 1) == 0x80000001); - ASSERT(f(1, 0x80000000) == 0x80000001); - ASSERT(f(0x7fffffff, 0x80000000) == 0xffffffff); - ASSERT(f(0x80000000, 0x7fffffff) == 0xffffffff); - ASSERT(f(0x7fffffff, 0xffffffff) == 0x80000000); - ASSERT(f(0xffffffff, 0x7fffffff) == 0x80000000); - ASSERT(f(0xffffffff, 0xffffffff) == 0); - ASSERT(f(0x7fffffff, 0) == 0x7fffffff); - ASSERT(f(0, 0x7fffffff) == 0x7fffffff); -#if EJIT_WORDSIZE == 64 - ASSERT(f(0x7fffffffffffffff, 1) == 0x7ffffffffffffffe); - ASSERT(f(1, 0x7fffffffffffffff) == 0x7ffffffffffffffe); - ASSERT(f(0x8000000000000000, 1) == 0x8000000000000001); - ASSERT(f(1, 0x8000000000000000) == 0x8000000000000001); - ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == 0xffffffffffffffff); - ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == 0xffffffffffffffff); - ASSERT(f(0x7fffffffffffffff, 0xffffffffffffffff) == 0x8000000000000000); - ASSERT(f(0xffffffffffffffff, 0x7fffffffffffffff) == 0x8000000000000000); - ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 0); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} diff --git a/tests/xorr64.c b/tests/xorr64.c new file mode 100644 index 0000000..a553f5e --- /dev/null +++ b/tests/xorr64.c @@ -0,0 +1,89 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main() +{ + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int64_t)) + }; + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 2, operands); + + ejit_xorr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int64_t), do_jit); + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x7fffffff, int64_t)) == 0x7ffffffe); + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x80000000, int64_t)) == 0x80000001); + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(1, int64_t)) == 0x7ffffffe); + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(1, int64_t)) == 0x80000001); + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0, int64_t)) == 0x7fffffff); + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0x80000000, int64_t) + ) == 0xffffffff); + + assert(erf2(f, EJIT_ARG(0x80000000, int64_t), + EJIT_ARG(0x7fffffff, int64_t) + ) == 0xffffffff); + + assert(erf2(f, EJIT_ARG(0x7fffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t) + ) == 0x80000000); + + assert(erf2(f, EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0x7fffffff, int64_t) + ) == 0x80000000); + + assert(erf2(f, EJIT_ARG(0xffffffff, int64_t), + EJIT_ARG(0xffffffff, int64_t) + ) == 0); + + assert(erf2(f, EJIT_ARG(0, int64_t), EJIT_ARG(0x7fffffff, int64_t) + ) == 0x7fffffff); + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == 0x7ffffffffffffffe); + + assert(erf2(f, EJIT_ARG(1, int64_t), + EJIT_ARG(0x8000000000000000, int64_t) + ) == (int64_t)0x8000000000000001); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(1, int64_t) + ) == (int64_t)0x8000000000000001); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(1, int64_t) + ) == (int64_t)0x7ffffffffffffffe); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0x8000000000000000, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(erf2(f, EJIT_ARG(0x8000000000000000, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == (int64_t)0xffffffffffffffff); + + assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0xffffffffffffffff, int64_t) + ) == (int64_t)0x8000000000000000); + + assert(erf2(f, EJIT_ARG(0xffffffffffffffff, int64_t), + EJIT_ARG(0x7fffffffffffffff, int64_t) + ) == (int64_t)0x8000000000000000); + + assert(erf2(f, EJIT_ARG(0xffffffffffffffff, int64_t), + EJIT_ARG(0xffffffffffffffff, int64_t) + ) == 0); + + + ejit_destroy_func(f); +} |