1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

Add an inlined jit fast-path for allocate-words/immediate

* libguile/intrinsics.c (allocate_words_with_freelist)
  (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): New intrinsic.
* libguile/jit.c (compile_allocate_words_immediate): Add fast-path.
  A marginal improvement.
This commit is contained in:
Andy Wingo 2019-06-20 14:02:05 +02:00
parent 33aecf48b0
commit 89e28df1c9
3 changed files with 46 additions and 7 deletions

View file

@ -418,6 +418,15 @@ allocate_words (scm_thread *thread, size_t n)
return SCM_PACK_POINTER (scm_inline_gc_malloc_words (thread, n));
}
static SCM
allocate_words_with_freelist (scm_thread *thread, size_t freelist_idx)
{
return SCM_PACK_POINTER
(scm_inline_gc_alloc (&thread->freelists[freelist_idx],
freelist_idx,
SCM_INLINE_GC_KIND_NORMAL));
}
static SCM
current_module (scm_thread *thread)
{
@ -506,6 +515,7 @@ scm_bootstrap_intrinsics (void)
scm_vm_intrinsics.allocate_words = allocate_words;
scm_vm_intrinsics.current_module = current_module;
scm_vm_intrinsics.push_prompt = push_prompt;
scm_vm_intrinsics.allocate_words_with_freelist = allocate_words_with_freelist;
scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
"scm_init_intrinsics",

View file

@ -161,6 +161,7 @@ typedef uint32_t* scm_t_vcode_intrinsic;
M(thread_u8_scm_sp_vra_mra, push_prompt, "push-prompt", PUSH_PROMPT) \
M(thread_scm, unpack_values_object, "unpack-values-object", UNPACK_VALUES_OBJECT) \
M(vcode, handle_interrupt_code, "%handle-interrupt-code", HANDLE_INTERRUPT_CODE) \
M(scm_from_thread_sz, allocate_words_with_freelist, "allocate-words/freelist", ALLOCATE_WORDS_WITH_FREELIST) \
/* Add new intrinsics here; also update scm_bootstrap_intrinsics. */
enum scm_vm_intrinsic

View file

@ -32,6 +32,7 @@
#include "frames.h"
#include "gsubr.h"
#include "gc-inline.h"
#include "instructions.h"
#include "intrinsics.h"
#include "simpos.h" /* scm_getenv_int */
@ -2056,14 +2057,41 @@ compile_allocate_words (scm_jit_state *j, uint16_t dst, uint16_t nwords)
static void
compile_allocate_words_immediate (scm_jit_state *j, uint16_t dst, uint16_t nwords)
{
jit_gpr_t t = T0;
size_t bytes = nwords * sizeof(SCM);
size_t idx = scm_inline_gc_bytes_to_freelist_index (bytes);
emit_store_current_ip (j, t);
emit_call_2 (j, scm_vm_intrinsics.allocate_words, thread_operand (),
jit_operand_imm (JIT_OPERAND_ABI_WORD, nwords));
emit_retval (j, t);
emit_reload_sp (j);
emit_sp_set_scm (j, dst, t);
if (SCM_UNLIKELY (idx >= SCM_INLINE_GC_FREELIST_COUNT))
{
jit_gpr_t t = T0;
emit_store_current_ip (j, t);
emit_call_1 (j, GC_malloc, jit_operand_imm (JIT_OPERAND_ABI_WORD, bytes));
emit_retval (j, t);
emit_reload_sp (j);
emit_sp_set_scm (j, dst, t);
}
else
{
jit_gpr_t res = T0;
ptrdiff_t offset = offsetof(struct scm_thread, freelists);
offset += idx * sizeof(void*);
emit_ldxi (j, res, THREAD, offset);
jit_reloc_t fast = jit_bnei (j->jit, res, 0);
emit_store_current_ip (j, res);
emit_call_2 (j, scm_vm_intrinsics.allocate_words_with_freelist,
thread_operand (),
jit_operand_imm (JIT_OPERAND_ABI_WORD, idx));
emit_retval (j, res);
emit_reload_sp (j);
jit_reloc_t done = jit_jmp (j->jit);
jit_patch_here (j->jit, fast);
jit_gpr_t new_freelist = T1;
emit_ldr (j, new_freelist, res);
jit_stxi (j->jit, offset, THREAD, new_freelist);
jit_patch_here (j->jit, done);
emit_sp_set_scm (j, dst, res);
}
}
static void