void _jit_retr_d(jit_state_t *_jit, jit_int32_t u) { if (JIT_FRET != u) jit_movr_d(JIT_FRET, u); else jit_live(JIT_FRET); jit_ret(); }
/* Generate a function that computes and returns the sum of its two double arguments (return an int) i.e., double foo(double x,double y) { return x + y;} */ dblFunc makeDblFunc () { dblFunc retVal; int dbl1, dbl2; retVal = (dblFunc) jit_get_ip ().iptr; jit_prolog (2); dbl1 = jit_arg_d (); dbl2 = jit_arg_d (); jit_getarg_d (JIT_FPR0, dbl1); jit_getarg_d (JIT_FPR1, dbl2); jit_addr_d (JIT_FPR0, JIT_FPR0, JIT_FPR1); jit_movr_d (JIT_FPRET, JIT_FPR0); jit_ret (); jit_flush_code ((char *) retVal, jit_get_ip ().ptr); #ifdef LIGHTNING_DISASSEMBLE disassemble (stderr, (char *) retVal, jit_get_ip ().ptr); #endif return retVal; }
pdfd compile_rpn (char *expr) { pdfd fn; int ofs, sp = 1; fn = (pdfd) (jit_get_ip ().dptr); jit_leaf (1); ofs = jit_arg_d (); jit_getarg_d (regs[0], ofs); while (*expr) { char buf[32]; int n; /* This scanner is much less advanced than the one in rpn.c. */ if (sscanf (expr, "%[0-9]%n", buf, &n)) { double d = strtod (buf, NULL); expr += n - 1; jit_movi_d (regs[sp], d); sp++; } else if (*expr == '+') { jit_addr_d (regs[sp - 2], regs[sp - 2], regs[sp - 1]); sp--; } else if (*expr == '-') { jit_subr_d (regs[sp - 2], regs[sp - 2], regs[sp - 1]); sp--; } else if (*expr == '*') { jit_mulr_d (regs[sp - 2], regs[sp - 2], regs[sp - 1]); sp--; } else if (*expr == '/') { jit_divr_d (regs[sp - 2], regs[sp - 2], regs[sp - 1]); sp--; } else { fprintf (stderr, "cannot compile: %s\n", expr); abort (); } ++expr; } jit_movr_d (JIT_FPRET, regs[0]); jit_ret (); jit_flush_code ((char *) fn, jit_get_ip ().ptr); #ifdef LIGHTNING_DISASSEMBLE disassemble (stderr, (char *) fn, jit_get_ip ().ptr); #endif return fn; }
void _jit_retval_d(jit_state_t *_jit, jit_int32_t r0) { if (r0 != JIT_FRET) jit_movr_d(r0, JIT_FRET); }