[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] nick.lloyd-bytecode-jit 932eacc 9/9: Avoid extra calls to
From: |
Nickolas Lloyd |
Subject: |
[Emacs-diffs] nick.lloyd-bytecode-jit 932eacc 9/9: Avoid extra calls to `jit_function_to_closure' |
Date: |
Sun, 29 Jan 2017 16:30:46 +0000 (UTC) |
branch: nick.lloyd-bytecode-jit
commit 932eacc3df12fea80aa4c17cc8413d7a7355f512
Author: Nickolas Lloyd <address@hidden>
Commit: Nickolas Lloyd <address@hidden>
Avoid extra calls to `jit_function_to_closure'
* src/bytecode-jit.c (jit_byte_code__, jit_exec):
* src/alloc.c (cleanup_vector, mark_compiled): Add vector slot for
holding the generated closure so that it only has to be generated once.
---
src/alloc.c | 20 +++++++++++---------
src/bytecode-jit.c | 8 +++++---
src/bytecode.c | 2 +-
src/lisp.h | 3 ++-
4 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/src/alloc.c b/src/alloc.c
index 585be22..1a3f747 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3219,11 +3219,12 @@ cleanup_vector (struct Lisp_Vector *vector)
else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_CONDVAR))
finalize_one_condvar ((struct Lisp_CondVar *) vector);
else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_COMPILED)
- && (void *)vector->contents[COMPILED_JIT_ID] != NULL)
+ && vector->contents[COMPILED_JIT_CTXT] != (Lisp_Object )NULL)
{
- jit_function_t func =
- (jit_function_t )vector->contents[COMPILED_JIT_ID];
- jit_context_destroy (jit_function_get_context (func));
+ jit_context_t ctxt = (jit_context_t )vector->contents[COMPILED_JIT_CTXT];
+ jit_context_destroy (ctxt);
+ vector->contents[COMPILED_JIT_CTXT] = (Lisp_Object )NULL;
+ vector->contents[COMPILED_JIT_CLOSURE] = (Lisp_Object )NULL;
}
}
@@ -3481,9 +3482,9 @@ stack before executing the byte-code.
usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING
INTERACTIVE-SPEC &rest ELEMENTS) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
- Lisp_Object val = make_uninit_vector (max(nargs, COMPILED_JIT_ID + 1));
+ Lisp_Object val = make_uninit_vector (max(nargs, COMPILED_JIT_CLOSURE + 1));
struct Lisp_Vector *p = XVECTOR (val);
- size_t size = min(nargs, COMPILED_JIT_ID);
+ size_t size = min(nargs, COMPILED_JIT_CLOSURE);
/* Don't allow the global zero_vector to become a byte code object. */
eassert (0 < nargs);
@@ -3507,9 +3508,10 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH
&optional DOCSTRING INT
must convert them back to the original unibyte form. */
p->contents[COMPILED_BYTECODE] = Fstring_as_unibyte
(p->contents[COMPILED_BYTECODE]);
- /* set rest size so that total footprint = COMPILED_JIT_ID + 1 */
- XSETPVECTYPESIZE (p, PVEC_COMPILED, size, COMPILED_JIT_ID + 1 - size);
- p->contents[COMPILED_JIT_ID] = 0;
+ /* set rest size so that total footprint = COMPILED_JIT_CLOSURE + 1 */
+ XSETPVECTYPESIZE (p, PVEC_COMPILED, size, COMPILED_JIT_CLOSURE + 1 - size);
+ p->contents[COMPILED_JIT_CTXT] = (Lisp_Object )NULL;
+ p->contents[COMPILED_JIT_CLOSURE] = (Lisp_Object )NULL;
XSETCOMPILED (val, p);
return val;
}
diff --git a/src/bytecode-jit.c b/src/bytecode-jit.c
index 6ab7349..0d058c9 100644
--- a/src/bytecode-jit.c
+++ b/src/bytecode-jit.c
@@ -675,7 +675,7 @@ jit_exec (Lisp_Object byte_code, Lisp_Object args_template,
ptrdiff_t nargs, Lis
stack.next = byte_stack_list;
byte_stack_list = &stack;
Lisp_Object (*func)(Lisp_Object *) =
- (Lisp_Object (*)(Lisp_Object *))jit_function_to_closure ((void *)AREF
(byte_code, COMPILED_JIT_ID));
+ (void *)AREF (byte_code, COMPILED_JIT_CLOSURE);
Lisp_Object ret = func (top);
byte_stack_list = byte_stack_list->next;
return ret;
@@ -820,7 +820,7 @@ jit_byte_code__ (Lisp_Object byte_code)
CHECK_COMPILED (byte_code);
/* check if function has already been compiled */
- if (XVECTOR (byte_code)->contents[COMPILED_JIT_ID])
+ if (XVECTOR (byte_code)->contents[COMPILED_JIT_CTXT] != (Lisp_Object )NULL)
return;
if (!jit_initialized)
emacs_jit_init ();
@@ -1588,7 +1588,9 @@ jit_byte_code__ (Lisp_Object byte_code)
jit_context_build_end (ctxt.libjit_ctxt);
if (err)
emacs_abort ();
- ASET (byte_code, COMPILED_JIT_ID, (Lisp_Object )ctxt.func);
+ ASET (byte_code, COMPILED_JIT_CTXT, (Lisp_Object )ctxt.libjit_ctxt);
+ ASET (byte_code, COMPILED_JIT_CLOSURE,
+ (Lisp_Object )jit_function_to_closure (ctxt.func));
}
}
diff --git a/src/bytecode.c b/src/bytecode.c
index 0e95c3e..8b132ca 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -1291,7 +1291,7 @@ exec_byte_code (Lisp_Object byte_code, Lisp_Object
args_template,
ptrdiff_t nargs, Lisp_Object *args)
{
#ifdef HAVE_LIBJIT
- if (AREF (byte_code, COMPILED_JIT_ID))
+ if (AREF (byte_code, COMPILED_JIT_CTXT) != (Lisp_Object )NULL)
return jit_exec (byte_code, args_template, nargs, args);
else if (byte_code_jit_on)
{
diff --git a/src/lisp.h b/src/lisp.h
index 63b336a..931dcef 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2592,7 +2592,8 @@ enum Lisp_Compiled
COMPILED_STACK_DEPTH = 3,
COMPILED_DOC_STRING = 4,
COMPILED_INTERACTIVE = 5,
- COMPILED_JIT_ID = 6
+ COMPILED_JIT_CTXT = 6,
+ COMPILED_JIT_CLOSURE = 7
};
/* Flag bits in a character. These also get used in termhooks.h.
- [Emacs-diffs] nick.lloyd-bytecode-jit updated (a35c6fd -> 932eacc), Nickolas Lloyd, 2017/01/29
- [Emacs-diffs] nick.lloyd-bytecode-jit 82f54dd 2/9: ; Fix compiler warnings in src/bytecode-jit.c, Nickolas Lloyd, 2017/01/29
- [Emacs-diffs] nick.lloyd-bytecode-jit fcc76c6 7/9: Free JIT contexts when compiled functions cleaned up, Nickolas Lloyd, 2017/01/29
- [Emacs-diffs] nick.lloyd-bytecode-jit 223bcfe 6/9: ; Store jit_function_t value instead of closure., Nickolas Lloyd, 2017/01/29
- [Emacs-diffs] nick.lloyd-bytecode-jit 1b8bb2d 8/9: ; Fix a performance regression in bytecode JIT compiler, Nickolas Lloyd, 2017/01/29
- [Emacs-diffs] nick.lloyd-bytecode-jit 86357df 4/9: ; Change JIT_* macros to return a value., Nickolas Lloyd, 2017/01/29
- [Emacs-diffs] nick.lloyd-bytecode-jit 68c56c0 3/9: ; Create a new context for each JIT compilation., Nickolas Lloyd, 2017/01/29
- [Emacs-diffs] nick.lloyd-bytecode-jit 932eacc 9/9: Avoid extra calls to `jit_function_to_closure',
Nickolas Lloyd <=
- [Emacs-diffs] nick.lloyd-bytecode-jit f33ff0c 1/9: Use inline functions instead of macros for JIT operations., Nickolas Lloyd, 2017/01/29
- [Emacs-diffs] nick.lloyd-bytecode-jit 639dfad 5/9: ; Make JIT compilation loop more readable., Nickolas Lloyd, 2017/01/29