guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 03/03: Add an inlined jit fast-path for allocate-words/i


From: Andy Wingo
Subject: [Guile-commits] 03/03: Add an inlined jit fast-path for allocate-words/immediate
Date: Thu, 20 Jun 2019 08:17:34 -0400 (EDT)

wingo pushed a commit to branch master
in repository guile.

commit 89e28df1c9069dcb65188fe7b3973c333d87d7e2
Author: Andy Wingo <address@hidden>
Date:   Thu Jun 20 14:02:05 2019 +0200

    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.
---
 libguile/intrinsics.c | 10 ++++++++++
 libguile/intrinsics.h |  1 +
 libguile/jit.c        | 42 +++++++++++++++++++++++++++++++++++-------
 3 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/libguile/intrinsics.c b/libguile/intrinsics.c
index ab6b6a8..ced3711 100644
--- a/libguile/intrinsics.c
+++ b/libguile/intrinsics.c
@@ -419,6 +419,15 @@ allocate_words (scm_thread *thread, size_t 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)
 {
   return scm_i_current_module (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",
diff --git a/libguile/intrinsics.h b/libguile/intrinsics.h
index 2c1b53a..de4f0e2 100644
--- a/libguile/intrinsics.h
+++ b/libguile/intrinsics.h
@@ -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
diff --git a/libguile/jit.c b/libguile/jit.c
index 7722234..700b1a4 100644
--- a/libguile/jit.c
+++ b/libguile/jit.c
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]