diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-06-29 18:00:51 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-06-29 18:00:51 +0300 |
commit | 322c7fba3d2f4c9b5b0d78b44feefd38ae44d017 (patch) | |
tree | de20ed83ee9231e853cefb46bb8ba60cf65e09dd /include | |
parent | d4c1d32e0aa21677e72c54ed220fdc70cea732c8 (diff) | |
download | ejit-322c7fba3d2f4c9b5b0d78b44feefd38ae44d017.tar.gz ejit-322c7fba3d2f4c9b5b0d78b44feefd38ae44d017.zip |
continue working through bytecode ops
Diffstat (limited to 'include')
-rw-r--r-- | include/ejit/ejit.h | 131 |
1 files changed, 80 insertions, 51 deletions
diff --git a/include/ejit/ejit.h b/include/ejit/ejit.h index 5152d8d..1869be9 100644 --- a/include/ejit/ejit.h +++ b/include/ejit/ejit.h @@ -26,19 +26,19 @@ enum ejit_type }; /* can be kind of dangerous since we default to a pointer, hmm */ -#define EJIT_TYPE(x)\ - _Generic((typeof(x))(0),\ - int8_t: EJIT_INT8,\ - int16_t: EJIT_INT16,\ - int32_t: EJIT_INT32,\ - int64_t: EJIT_INT64,\ - uint8_t: EJIT_UINT8,\ - uint16_t: EJIT_UINT16,\ - uint32_t: EJIT_UINT32,\ - uint64_t: EJIT_UINT64,\ - float: EJIT_FLOAT,\ - double: EJIT_DOUBLE,\ - default: EJIT_POINTER) +#define EJIT_TYPE(x) \ + _Generic((typeof(x))(0), \ + int8_t: EJIT_INT8, \ + int16_t: EJIT_INT16, \ + int32_t: EJIT_INT32, \ + int64_t: EJIT_INT64, \ + uint8_t: EJIT_UINT8, \ + uint16_t: EJIT_UINT16, \ + uint32_t: EJIT_UINT32, \ + uint64_t: EJIT_UINT64, \ + float: EJIT_FLOAT, \ + double: EJIT_DOUBLE, \ + default: EJIT_POINTER) struct ejit_arg { union { @@ -166,19 +166,21 @@ struct ejit_func; 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, bool use_64); +void ejit_compile_func(struct ejit_func *f, size_t gpr, size_t fpr, + bool use_64); void ejit_select_compile_func(struct ejit_func *f, size_t gpr, size_t fpr, bool use_64, bool try_jit); int64_t ejit_run_func(struct ejit_func *f, size_t argc, - struct ejit_arg args[argc]); + struct ejit_arg args[argc]); static inline int64_t ejit_run_func_1(struct ejit_func *f, struct ejit_arg a0) { return ejit_run_func(f, 1, &a0); } -static inline int64_t ejit_run_func_2(struct ejit_func *f, struct ejit_arg a0, struct ejit_arg a1) +static inline int64_t ejit_run_func_2(struct ejit_func *f, struct ejit_arg a0, + struct ejit_arg a1) { struct ejit_arg args[2] = {a0, a1}; return ejit_run_func(f, 2, args); @@ -192,6 +194,13 @@ static inline double ejit_run_func_f_1(struct ejit_func *f, struct ejit_arg a0) return ejit_run_func_f(f, 1, &a0); } +static inline double ejit_run_func_f_2(struct ejit_func *f, struct ejit_arg a0, + struct ejit_arg a1) +{ + struct ejit_arg args[2] = {a0, a1}; + return ejit_run_func_f(f, 2, args); +} + void ejit_destroy_func(struct ejit_func *s); #define EJIT_GPR(x) ((struct ejit_gpr){.r = (x)}) @@ -252,25 +261,25 @@ static inline struct ejit_arg ejit_double(double a) return (struct ejit_arg){.d = a, .type = EJIT_DOUBLE}; } -#define EJIT_ARG(x, t) \ - _Generic((t)(0), \ - 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, \ +#define EJIT_ARG(x, t) \ + _Generic((t)(0), \ + 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) #define EJIT_AUTO(x) \ EJIT_ARG(x, typeof(x)) -static inline ejit_use64(struct ejit_arg a) +static inline bool ejit_use64(struct ejit_arg a) { if (a.type == EJIT_INT64 || a.type == EJIT_UINT64) return true; @@ -308,7 +317,7 @@ void ejit_retval(struct ejit_func *s, struct ejit_gpr r0); 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_movi(struct ejit_func *s, struct ejit_gpr r0, int64_t 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); @@ -327,27 +336,34 @@ 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); + int64_t o); + void ejit_ldxi_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o); + int64_t o); + void ejit_ldxi_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o); + int64_t o); + void ejit_ldxi_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o); + int64_t o); void ejit_ldxi_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o); + int64_t o); + void ejit_ldxi_u16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o); + int64_t o); + void ejit_ldxi_u32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o); + int64_t o); + void ejit_ldxi_u64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o); + int64_t o); void ejit_ldxi_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, - long o); + int64_t o); + void ejit_ldxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, - long o); + int64_t 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); @@ -364,34 +380,42 @@ 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); + int64_t o); + void ejit_stxi_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o); + int64_t o); + void ejit_stxi_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o); + int64_t o); + void ejit_stxi_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o); + int64_t o); void ejit_stxi_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, - long o); + int64_t o); + void ejit_stxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, - long o); + int64_t 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); + int64_t 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); + int64_t o); void ejit_mulr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2); @@ -403,6 +427,10 @@ void ejit_divr(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_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_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, @@ -412,9 +440,10 @@ void ejit_ltr(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); +struct ejit_reloc ejit_bnei(struct ejit_func *s, struct ejit_gpr r0, int64_t o); +struct ejit_reloc ejit_beqr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1); +struct ejit_reloc ejit_beqi(struct ejit_func *s, struct ejit_gpr r0, int64_t o); +struct ejit_reloc ejit_bgti(struct ejit_func *s, struct ejit_gpr r0, int64_t o); struct ejit_reloc ejit_jmp(struct ejit_func *s); void ejit_patch(struct ejit_func *s, struct ejit_reloc r, struct ejit_label l); |