aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-06-29 14:20:07 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-06-29 14:20:07 +0300
commit49aa680ccdac46d1d2a7f9f250999b7ff7099548 (patch)
tree1de3bd5209feadfd147f7a05d1ac925f98b747b1 /include
parent29718f2e84478b296c3198ae6d35cfd5d79efb14 (diff)
downloadejit-49aa680ccdac46d1d2a7f9f250999b7ff7099548.tar.gz
ejit-49aa680ccdac46d1d2a7f9f250999b7ff7099548.zip
start adding tests
Diffstat (limited to 'include')
-rw-r--r--include/ejit/ejit.h239
1 files changed, 166 insertions, 73 deletions
diff --git a/include/ejit/ejit.h b/include/ejit/ejit.h
index 17a6034..895ce9b 100644
--- a/include/ejit/ejit.h
+++ b/include/ejit/ejit.h
@@ -27,14 +27,14 @@ enum ejit_type
struct ejit_arg {
union {
- int8_t c;
- uint8_t uc;
- int16_t s;
- uint16_t us;
- int32_t i;
- uint32_t ui;
- int64_t l;
- uint64_t ul;
+ int8_t i8;
+ uint8_t u8;
+ int16_t i16;
+ uint16_t u16;
+ int32_t i32;
+ uint32_t u32;
+ int64_t i64;
+ uint64_t u64;
float f;
double d;
void *p;
@@ -73,7 +73,7 @@ static inline bool ejit_float_type(enum ejit_type t)
return false;
}
-static inline struct ejit_arg ejit_build_arg(enum ejit_type type, long x)
+static inline struct ejit_arg ejit_build_arg(enum ejit_type type, uint64_t x)
{
assert(ejit_int_type(type));
@@ -81,14 +81,14 @@ static inline struct ejit_arg ejit_build_arg(enum ejit_type type, long x)
a.type = type;
switch (type) {
- case EJIT_INT8: a.c = x; break;
- case EJIT_INT16: a.s = x; break;
- case EJIT_INT32: a.i = x; break;
- case EJIT_INT64: a.l = x; break;
- case EJIT_UINT8: a.uc = x; break;
- case EJIT_UINT16: a.us = x; break;
- case EJIT_UINT32: a.ui = x; break;
- case EJIT_UINT64: a.ul = x; break;
+ case EJIT_INT8: a.i8 = x; break;
+ case EJIT_INT16: a.i16 = x; break;
+ case EJIT_INT32: a.i32 = x; break;
+ case EJIT_INT64: a.i64 = x; break;
+ case EJIT_UINT8: a.u8 = x; break;
+ case EJIT_UINT16: a.u16 = x; break;
+ case EJIT_UINT32: a.u32 = x; break;
+ case EJIT_UINT64: a.u64 = x; break;
case EJIT_POINTER: a.p = (void *)x; break;
default: abort();
}
@@ -141,20 +141,29 @@ struct ejit_operand {
enum ejit_type type;
union {
- long r;
- double d;
+ long r;
+ double d;
};
};
struct ejit_func;
-struct ejit_func *ejit_create_func(enum ejit_type rtype, size_t argc, const struct ejit_operand args[argc]);
+struct ejit_func *ejit_create_func(enum ejit_type rtype, size_t argc,
+ const struct ejit_operand args[argc]);
void ejit_compile_func(struct ejit_func *f, size_t gpr, size_t fpr);
-void ejit_select_compile_func(struct ejit_func *f, size_t gpr, size_t fpr, bool try_jit);
+void ejit_select_compile_func(struct ejit_func *f, size_t gpr, size_t fpr,
+ bool try_jit);
+
+long ejit_run_func(struct ejit_func *f, size_t argc,
+ struct ejit_arg args[argc]);
+double ejit_run_func_f(struct ejit_func *f, size_t argc,
+ struct ejit_arg args[argc]);
-long ejit_run_func(struct ejit_func *f, size_t argc, struct ejit_arg args[argc]);
-double ejit_run_func_f(struct ejit_func *f, size_t argc, struct ejit_arg args[argc]);
+static inline double ejit_run_func_f_1(struct ejit_func *f, struct ejit_arg a0)
+{
+ return ejit_run_func_f(f, 1, &a0);
+}
void ejit_destroy_func(struct ejit_func *s);
@@ -163,28 +172,81 @@ void ejit_destroy_func(struct ejit_func *s);
#define EJIT_ARG_POINTER(x) ((struct ejit_arg){.p = (x), .type = EJIT_POINTER})
-#define EJIT_OPERAND_GPR(x, t) ((struct ejit_operand){ .kind = EJIT_OPERAND_GPR, .r = (long)(x), .type = (t)})
-#define EJIT_OPERAND_FPR(x, t) ((struct ejit_operand){ .kind = EJIT_OPERAND_FPR, .r = (long)(x) .type =(t)})
-#define EJIT_OPERAND_IMM(x, t) ((struct ejit_operand){ .kind = EJIT_OPERAND_IMM, .r = (long)(x), .type = (t)})
-#define EJIT_OPERAND_FLT(x, t) ((struct ejit_operand){ .kind = EJIT_OPERAND_FLT, .r = (double)(x), .type = (t)})
+#define EJIT_OPERAND_GPR(x, t) \
+ ((struct ejit_operand){ .kind = EJIT_OPERAND_GPR, \
+ .r = (long)(x), \
+ .type = (t)})
+#define EJIT_OPERAND_FPR(x, t) \
+ ((struct ejit_operand){ .kind = EJIT_OPERAND_FPR, \
+ .r = (long)(x), \
+ .type =(t)})
+
+#define EJIT_OPERAND_IMM(x, t) \
+ ((struct ejit_operand){ .kind = EJIT_OPERAND_IMM, \
+ .r = (long)(x), \
+ .type = (t)})
+#define EJIT_OPERAND_FLT(x, t) \
+ ((struct ejit_operand){ .kind = EJIT_OPERAND_FLT, \
+ .r = (double)(x), \
+ .type = (t)})
+
+static inline struct ejit_arg ejit_i8(int8_t a)
+{
+ return (struct ejit_arg){.i8 = a, .type = EJIT_INT8};
+}
+
+static inline struct ejit_arg ejit_i16(int16_t a)
+{
+ return (struct ejit_arg){.i16 = a, .type = EJIT_INT16};
+}
+
+static inline struct ejit_arg ejit_i32(int32_t a)
+{
+ return (struct ejit_arg){.i32 = a, .type = EJIT_INT32};
+}
+
+static inline struct ejit_arg ejit_double(double a)
+{
+ return (struct ejit_arg){.d = a, .type = EJIT_DOUBLE};
+}
+
+#define EJIT_ARG(x) \
+ _Generic((x), \
+ int8_t: ejit_i8, \
+ int16_t: ejit_i16, \
+ int32_t: ejit_i32, \
+ int64_t: ejit_i64, \
+ uint8_t: ejit_i8, \
+ uint16_t: ejit_i16, \
+ uint32_t: ejit_i32, \
+ uint64_t: ejit_i64, \
+ float: ejit_float, \
+ double: ejit_double, \
+ default: ejit_pointer, \
+ )(x)
typedef long (*ejit_escape_t)(size_t argc, const struct ejit_arg args[argc]);
-typedef double (*ejit_escape_f_t)(size_t argc, const struct ejit_arg args[argc]);
+typedef double (*ejit_escape_f_t)(size_t argc,
+ const struct ejit_arg args[argc]);
struct ejit_label ejit_label(struct ejit_func *s);
-void ejit_calli(struct ejit_func *s, struct ejit_func *f, size_t argc, const struct ejit_operand args[argc]);
+void ejit_calli(struct ejit_func *s, struct ejit_func *f, size_t argc,
+ const struct ejit_operand args[argc]);
-void ejit_calli_f(struct ejit_func *s, struct ejit_func *f, size_t argc, const struct ejit_operand args[argc]);
+void ejit_calli_f(struct ejit_func *s, struct ejit_func *f, size_t argc,
+ const struct ejit_operand args[argc]);
-void ejit_escapei(struct ejit_func *s, ejit_escape_t f, size_t argc, const struct ejit_operand args[argc]);
+void ejit_escapei(struct ejit_func *s, ejit_escape_t f, size_t argc,
+ const struct ejit_operand args[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_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, struct ejit_gpr r0);
-void ejit_ret_f(struct ejit_func *s, struct ejit_fpr r0);
-void ejit_ret_i(struct ejit_func *s, long i);
-void ejit_ret_fi(struct ejit_func *s, double f);
+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);
+void ejit_reti_f(struct ejit_func *s, double f);
void ejit_retval(struct ejit_func *s, struct ejit_gpr r0);
void ejit_retval_f(struct ejit_func *s, struct ejit_fpr r0);
@@ -192,7 +254,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, long i);
void ejit_movr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1);
-void ejit_movr_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1);
+void ejit_movr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1);
void ejit_ldi_8(struct ejit_func *s, struct ejit_gpr r0, void *p);
void ejit_ldi_16(struct ejit_func *s, struct ejit_gpr r0, void *p);
@@ -208,18 +270,28 @@ void ejit_ldi_f(struct ejit_func *s, struct ejit_fpr r0, void *p);
void ejit_ldi_d(struct ejit_func *s, struct ejit_fpr r0, void *p);
/* from r1 + o to r0 */
-void ejit_ldxi_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-void ejit_ldxi_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-void ejit_ldxi_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-void ejit_ldxi_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-
-void ejit_ldxi_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-void ejit_ldxi_u16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-void ejit_ldxi_u32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-void ejit_ldxi_u64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-
-void ejit_ldxi_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, long o);
-void ejit_ldxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, long o);
+void ejit_ldxi_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+void ejit_ldxi_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+void ejit_ldxi_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+void ejit_ldxi_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+
+void ejit_ldxi_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+void ejit_ldxi_u16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+void ejit_ldxi_u32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+void ejit_ldxi_u64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+
+void ejit_ldxi_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
+ long o);
+void ejit_ldxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
+ long o);
void ejit_sti_8(struct ejit_func *s, struct ejit_gpr r0, void *p);
void ejit_sti_16(struct ejit_func *s, struct ejit_gpr r0, void *p);
@@ -235,34 +307,55 @@ 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);
/* from r0 to r1 + o */
-void ejit_stxi_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-void ejit_stxi_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-void ejit_stxi_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-void ejit_stxi_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-
-void ejit_stxi_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, long o);
-void ejit_stxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, long o);
-
-void ejit_addr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2);
-void ejit_addr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1, struct ejit_fpr r2);
-void ejit_addi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-
-void ejit_subr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2);
-void ejit_subr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1, struct ejit_fpr r2);
-void ejit_subi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o);
-
-void ejit_mulr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2);
-void ejit_mulr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1, struct ejit_fpr r2);
-
-void ejit_divr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2);
-void ejit_divr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1, struct ejit_fpr r2);
+void ejit_stxi_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+void ejit_stxi_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+void ejit_stxi_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+void ejit_stxi_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+
+void ejit_stxi_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
+ long o);
+void ejit_stxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
+ long o);
+
+void ejit_addr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+void ejit_addr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2);
+void ejit_addi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+
+void ejit_absr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1);
+
+void ejit_subr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+void ejit_subr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2);
+void ejit_subi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ long o);
+
+void ejit_mulr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+void ejit_mulr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2);
+
+void ejit_divr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+void ejit_divr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2);
void ejit_negr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1);
-void ejit_eqr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2);
-void ejit_ltr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2);
+void ejit_eqr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+void ejit_ltr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
-struct ejit_reloc ejit_bltr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1);
+struct ejit_reloc ejit_bltr(struct ejit_func *s, struct ejit_gpr r0,
+ struct ejit_gpr r1);
struct ejit_reloc ejit_bnei(struct ejit_func *s, struct ejit_gpr r0, long o);
struct ejit_reloc ejit_beqi(struct ejit_func *s, struct ejit_gpr r0, long o);
struct ejit_reloc ejit_bgti(struct ejit_func *s, struct ejit_gpr r0, long o);