1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-07 04:30:18 +02:00

Support immediate arguments

This commit is contained in:
Andy Wingo 2019-04-04 12:09:41 +02:00
parent 1d6feefa9d
commit ede10b101b

View file

@ -440,6 +440,47 @@ next_abi_arg(struct abi_arg_iterator *iter, jit_arg_t *arg)
iter->arg_idx++; iter->arg_idx++;
} }
static void
abi_imm_to_gpr(jit_state_t *_jit, jit_arg_abi_t abi, jit_gpr_t dst, intptr_t imm)
{
switch (abi) {
case JIT_ARG_ABI_UINT8:
ASSERT(0 <= imm);
ASSERT(imm <= UINT8_MAX);
break;
case JIT_ARG_ABI_INT8:
ASSERT(INT8_MIN <= imm);
ASSERT(imm <= INT8_MAX);
break;
case JIT_ARG_ABI_UINT16:
ASSERT(0 <= imm);
ASSERT(imm <= UINT16_MAX);
break;
case JIT_ARG_ABI_INT16:
ASSERT(INT16_MIN <= imm);
ASSERT(imm <= INT16_MAX);
break;
case JIT_ARG_ABI_UINT32:
ASSERT(0 <= imm);
ASSERT(imm <= UINT32_MAX);
break;
case JIT_ARG_ABI_INT32:
ASSERT(INT32_MIN <= imm);
ASSERT(imm <= INT32_MAX);
break;
#if __WORDSIZE > 32
case JIT_ARG_ABI_UINT64:
case JIT_ARG_ABI_INT64:
break;
#endif
case JIT_ARG_ABI_POINTER:
break;
default:
abort();
}
jit_movi (_jit, dst, imm);
}
static void static void
abi_gpr_to_mem(jit_state_t *_jit, jit_arg_abi_t abi, abi_gpr_to_mem(jit_state_t *_jit, jit_arg_abi_t abi,
jit_gpr_t src, jit_gpr_t base, ptrdiff_t offset) jit_gpr_t src, jit_gpr_t base, ptrdiff_t offset)
@ -568,6 +609,19 @@ store_mem_abi_arg(jit_state_t *_jit, jit_arg_abi_t abi,
} }
break; break;
case JIT_ARG_LOC_IMM: {
if (is_gpr_arg(abi)) {
jit_gpr_t tmp = get_temp_gpr(_jit);
abi_imm_to_gpr(_jit, abi, tmp, arg->loc.imm);
abi_gpr_to_mem(_jit, abi, tmp, base, offset);
unget_temp_gpr(_jit);
} else {
/* Floating-point immediates not supported yet. */
abort ();
}
break;
}
default: default:
abort(); abort();
} }
@ -682,8 +736,8 @@ prepare_args(jit_state_t *_jit, size_t argc, const jit_arg_abi_t abi[],
// We move on now to the ABI register arguments. All args whose values are in // We move on now to the ABI register arguments. All args whose values are in
// registers are ABI register arguments, but they might not be the right // registers are ABI register arguments, but they might not be the right
// register for the correponding ABI argument. Note that there may be ABI // register for the correponding ABI argument. Note that there may be ABI
// register arguments whose values are still in memory; we will load them // register arguments whose values are still in memory or as immediates; we
// later. // will load them later.
reset_abi_arg_iterator(&iter, argc, abi); reset_abi_arg_iterator(&iter, argc, abi);
for (size_t i = 0; i < argc; i++) for (size_t i = 0; i < argc; i++)
{ {
@ -705,7 +759,7 @@ prepare_args(jit_state_t *_jit, size_t argc, const jit_arg_abi_t abi[],
} }
// The only thing that's left is ABI register arguments whose values are still // The only thing that's left is ABI register arguments whose values are still
// in memory; load them now. // in memory or immediates; load them now.
reset_abi_arg_iterator(&iter, argc, abi); reset_abi_arg_iterator(&iter, argc, abi);
for (size_t i = 0; i < argc; i++) for (size_t i = 0; i < argc; i++)
{ {
@ -717,6 +771,10 @@ prepare_args(jit_state_t *_jit, size_t argc, const jit_arg_abi_t abi[],
args[i].loc.mem.offset); args[i].loc.mem.offset);
args[i].kind = JIT_ARG_LOC_GPR; args[i].kind = JIT_ARG_LOC_GPR;
args[i].loc.gpr = scratch.loc.gpr; args[i].loc.gpr = scratch.loc.gpr;
} else if (args[i].kind == JIT_ARG_LOC_IMM) {
abi_imm_to_gpr(_jit, abi[i], scratch.loc.gpr, args[i].loc.imm);
args[i].kind = JIT_ARG_LOC_GPR;
args[i].loc.gpr = scratch.loc.gpr;
} }
break; break;
@ -726,6 +784,9 @@ prepare_args(jit_state_t *_jit, size_t argc, const jit_arg_abi_t abi[],
args[i].loc.mem.offset); args[i].loc.mem.offset);
args[i].kind = JIT_ARG_LOC_FPR; args[i].kind = JIT_ARG_LOC_FPR;
args[i].loc.fpr = scratch.loc.fpr; args[i].loc.fpr = scratch.loc.fpr;
} else if (args[i].kind == JIT_ARG_LOC_IMM) {
/* Currently unsupported. */
abort ();
} }
break; break;