1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
Commit graph

119 commits

Author SHA1 Message Date
Andy Wingo
d1cf892880 Optimize fixnum or s64 -> f64 conversions
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add "inexact"
  intrinsic.
* libguile/jit.c (compile_s64_to_f64): New compiler.
* libguile/vm-engine.c (s64->f64): New instruction.
* module/language/cps/effects-analysis.scm (heap-numbers-equal?):
* module/language/cps/reify-primitives.scm (compute-known-primitives):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/specialize-numbers.scm (fixnum->f64):
  (specialize-operations):
* module/language/cps/type-fold.scm (scm->f64, inexact):
* module/language/cps/types.scm (inexact, s64->f64):
* module/language/tree-il/cps-primitives.scm (exact->inexact):
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*effect-free-primitives*):
* module/system/vm/assembler.scm: Recognize exact->inexact as a
  primitive, and optimize it.  Add compiler support for new "inexact"
  and "s64->f64" primcalls.
2019-09-01 20:46:04 +02:00
Andy Wingo
b02d1b08d7 Compiler allocates boxed flonums in unmarked space
This fixes a bug whereby the compiler would sometimes allocate floats in
marked space.

* libguile/gc-inline.h (scm_inline_gc_malloc_pointerless_words): New
  internal helper.
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* libguile/intrinsics.c (allocate_pointerless_words):
  (allocate_pointerless_words_with_freelist): New intrinsics.
* libguile/jit.c (compile_allocate_pointerless_words):
  (compile_allocate_pointerless_words_immediate): New compilers.
* libguile/vm-engine.c (allocate_pointerless_words)
  (allocate_pointerless_words_immediate): New opcodes.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm (param):
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/types.scm (allocate-words):
(allocate-words/immediate):
* module/system/vm/assembler.scm (system): Add support for the new
  opcodes.
2019-08-26 10:19:24 +02:00
Andy Wingo
b1564df298 Unbox floor/ceiling and trigonometric functions where possible
* libguile/intrinsics.c (scm_atan1): New intrinsic, wrapping scm_atan.
  (scm_bootstrap_intrinsics): Add new intrinsics.
* libguile/intrinsics.h (scm_t_f64_from_f64_f64_intrinsic): New
  intrinsic type.
  (SCM_FOR_ALL_VM_INTRINSICS): Add intrinsics for floor, ceiling, sin,
  cos, tan, asin, acos, atan, and their unboxed counterparts.
* libguile/jit.c (sp_f64_operand): New helper.
  (compile_call_f64_from_f64, compile_call_f64_from_f64_f64): Call out
  to intrinsics.
* libguile/vm-engine.c (call-f64<-f64-f64): New opcode.
* module/language/cps/effects-analysis.scm: Add new intrinsics.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add new intrinsics.
* module/language/cps/slot-allocation.scm (compute-var-representations):
  Add 'f64 slot types for the new unboxed intrinsics.
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Support unboxing the new intrinsics.
* module/language/cps/types.scm: Define type inferrers for the new
  intrinsics.
* module/language/tree-il/cps-primitives.scm: Define CPS translations
  for the new intrinsics.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*effect-free-primitives*, atan): Define primitive resolvers.
* module/system/vm/assembler.scm: Export assemblers for the new
  intrinsics.
  (define-f64<-f64-f64-intrinsic): New helper.
2019-08-24 11:56:18 +02:00
Andy Wingo
382cc5c246 Add support for optimized unboxed abs and sqrt
Some components of this have been wired up for a while; this commit
finishes the compiler, runtime, and JIT support.

* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* libguile/intrinsics.c (scm_bootstrap_intrinsics): Declare the new
  intrinsics.
* libguile/jit.c (compile_call_f64_from_f64): Define code generators for
  the new intrinsics.
* libguile/vm-engine.c (call-f64<-f64): New instruction.
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm (compute-known-primitives):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/specialize-numbers.scm (specialize-operations):
* module/language/tree-il/cps-primitives.scm (abs):
* module/system/vm/assembler.scm (system, define-f64<-f64-intrinsic):
  (sqrt, abs, fsqrt, fabs):
* module/language/cps/types.scm (fsqrt, fabs): Add new f64<-f64
  primitives.
2019-08-04 21:54:51 +02:00
Andy Wingo
d0aca1635e Fix some compiler warnings on 64-bit builds 2019-08-03 12:44:30 +02:00
Andy Wingo
ba5d1dfc6a Fix calls to handle-interrupts trampoline on ARMv7
* libguile/jit.c (initialize_jit): Keep handle_interrupts_trampoline as
  an address, not a function pointer.
2019-08-02 17:00:07 +02:00
Andy Wingo
89e28df1c9 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.
2019-06-20 14:02:05 +02:00
Andy Wingo
cce222d189 Fix compilation on GCC 5.5
* libguile/jit.c (OLD_FP_FOR_RETURN_TRAMPOLINE): Initialize static const
  var from CPP define instead of T0.
  (compile_return_values, emit_return_to_interpreter_trampoline): Adapt
  to upper-casing.
2019-06-20 12:07:40 +02:00
Andy Wingo
7cbbc83dcb Use call/return instructions for non-tail calls
This change speeds up the indirect branches at return sites by taking
advantage of the CPU's return address stack.

* libguile/jit.c (emit_push_frame): Don't store the mra; we do that via
  a trampoline.
  (emit_handle_interrupts_trampoline): Take MRA from link register
  instead of T0.
  (compile_call, compile_call_label): Compute MRA via the new
  jmpi_with_link lightening instruction.
  (compile_return_values): Return to caller via ret instead of jmp.
  (compile_handle_interrupts): Jump to handle-interrupts trampoline via
  jmpi_with_link, to provide the MRA.
  (initialize_jit): Bless the trampolines so that they are valid
  operands to BX on ARM.
2019-06-20 10:55:24 +02:00
Andy Wingo
af72d01de8 Speed up returns in JIT
This patch is a bit unfortunate, in the sense that it exposes some of
the JIT guts to the rest of the VM.  Code needs to treat "machine return
addresses" as valid if non-NULL (as before) and also not equal to a
tier-down trampoline.  This is because tier-down at a return needs the
old frame pointer to load the "virtual return address", and the way this
patch works is that it passes the vra in a well-known register.  It's a
custom calling convention for a certain kind of return.

* libguile/jit.h (scm_jit_return_to_interpreter_trampoline): New
  internal global.
* libguile/jit.c: (scm_jit_clear_mcode_return_addresses): Move here,
  from vm.c.  Instead of zeroing return addresses, set them to the
  return-to-interpreter trampoline.
* libguile/vm-engine.c (return-values): Don't enter mcode if the mra is
  scm_jit_return_to_interpreter_trampoline.
* libguile/vm.c (capture_continuation): Treat the tier-down trampoline
  as NULL.
2019-06-18 21:45:29 +02:00
Andy Wingo
e8203a3f8c jit: Direct tail calls assert that target can have mcode
* libguile/jit.c (emit_direct_tail_call): Assert that the callee label
  starts with an instrument-entry.
2019-06-18 21:26:34 +02:00
Andy Wingo
f07fadc72e VM does not initialize stack frames
* libguile/jit.c (compile_alloc_frame): Stop initializing locals.
  (compile_bind_rest): Use emit_alloc_frame.
* libguile/vm-engine.c (assert_nargs_ee_locals, allocate_frame): Don't
  initialize locals.
  (bind_rest): Don't initialize locals, and assert that the locals count
  has a minimum.
2019-06-06 17:39:53 +02:00
Andy Wingo
c86758c298 Allow for bind-optionals without alloc-frame
This reduces subr trampoline instruction count for subrs with optional
args.

* libguile/gsubr.c (get_subr_stub_code): Insert bind-optionals
  instructions.
  (primitive_call_ip): Handle bind-optionals.
* libguile/programs.c (try_parse_arity): Handle bind-optionals.
* libguile/jit.c (struct scm_jit_state)
  (compile_call, compile_call_label, compile_tail_call)
  (compile_tail_call_label, compile_receive), compile_receive_values)
  (compile_shuffle_down, compile_return_values, compile_subr_call)
  (compile_foreign_call, compile_continuation_call)
  (compile_compose_continuation, compile_abort, compile_assert_nargs_ee)
  (compile_assert_nargs_ge, compile_assert_nargs_le)
  (compile_alloc_frame, compile_reset_frame, compile_push)
  (compile_pop, compile_drop, compile_expand_apply_argument)
  (compile_bind_kwargs, compile_bind_rest, compile_bind_optionals)
  (compile, compute_mcode): Separately track min and max frame sizes.
2019-06-06 17:26:59 +02:00
Andy Wingo
9fd978ed7e Add bind-optionals instruction
* doc/ref/vm.texi (Function Prologue Instructions): Document new
  instruction.
* libguile/jit.c (compile_bind_optionals): New compiler.
* libguile/vm-engine.c (VM_NAME): New interpreter.
* module/system/vm/assembler.scm (opt-prelude): Emit bind-optionals as
  appropriate.
* module/system/vm/disassembler.scm (define-stack-effect-parser)
  (code-annotation): Handle bind-optionals.
2019-06-06 16:36:32 +02:00
Andy Wingo
12d6e43176 Avoid saving IP for <? fast-path
* libguile/jit.c (compile_less): Only save IP on slow-path.
2019-06-06 14:39:02 +02:00
Andy Wingo
1128dbc444 Remove check for instrument-entry
* libguile/jit.c (emit_indirect_tail_call): If everything starts with
  instrument-entry, and thus has a vcode pointer, no need to emit a
  dynamic check.
2019-05-27 19:22:23 +02:00
Andy Wingo
9c5098ab25 Dynamically assert functions start with instrument-entry
* libguile/jit.c (emit_indirect_tail_call): Add dynamic assertion.
2019-05-27 19:09:12 +02:00
Andy Wingo
1fb39929f9 Reapply atomics inlining
This patch reapplies 230a555976 and
e8d34258be, but fixing a misplaced
comma (!).
2019-05-27 19:05:10 +02:00
Andy Wingo
d0a95bfbe8 Revert "Fix atomics usage in handle-interrupts JIT."
This reverts commit e8d34258be.
2019-05-27 18:40:41 +02:00
Andy Wingo
e8d34258be Fix atomics usage in handle-interrupts JIT.
* libguile/jit.c (compile_handle_interrupts): Use atomics in
  handle-interrupts.
2019-05-27 12:08:58 +02:00
Andy Wingo
33e07fc56c Use new atomic instructions from lightening
* libguile/jit.c (compile_atomic_scm_ref_immediate):
(compile_atomic_scm_set_immediate):
(compile_atomic_scm_swap_immediate):
(compile_atomic_scm_compare_and_swap_immediate): Use lightening
instructions.
2019-05-27 11:57:36 +02:00
Andy Wingo
e9e52b6ab9 Mark a couple functions as maybe-unused.
* libguile/jit.c (fp_scm_operand, sp_slot_operand): Maybe unused.
2019-05-23 09:34:08 +02:00
Andy Wingo
da0cc5d3e6 Bless enter_mcode as a function pointer
* libguile/jit.c (initialize_jit): Bless enter_mcode, to allow ARMv7
  interworking.
2019-05-21 14:02:27 +02:00
Andy Wingo
e00936d46b Allow jit_end to fail
* libguile/jit.c (emit_code): Emitting a constant table might cause us
  to fail.
2019-05-21 13:36:37 +02:00
Andy Wingo
107926f8dd Fix allocator passed to lightening
* libguile/jit.c (jit_alloc_fn): On targets that need a dynamically
  allocated literal pool, we will need to trace that pool, so pass a
  pointerful malloc.  Fixes JIT on AArch64.
2019-05-21 12:39:55 +02:00
Andy Wingo
c461126fab Fix u64-ref JIT on 32-bit
* libguile/jit.c (compile_u64_ref): Fix 32-bit load path; endianness was
  reversed.
2019-04-29 09:41:03 +02:00
Andy Wingo
85b3ee0ec3 Fix unneeded stack alignment.
* libguile/jit.c (emit_entry_trampoline): Remove unneeded alignment.
2019-04-28 18:45:10 +02:00
Andy Wingo
fb1f3ba051 Fix errors in 32-bit JIT support
* libguile/jit.c (compile_ursh_immediate):
(compile_ulsh_immediate): Fix immediate/register variant calling.
Happily a benefit of lightening, as type safety did this for us.
(DEFINE_CLOBBER_RECORDING_EMITTER_R_R_2): Pass JIT state.
2019-04-28 13:54:34 +02:00
Andy Wingo
334d0ba860 Adapt to lightening changes
* libguile/jit.c (emit_entry_trampoline): Use
  jit_{enter,leave}_jit_abi.
  (compile_allocate_words_immediate): Use JIT_OPERAND_ABI_WORD.
2019-04-28 13:54:34 +02:00
Andy Wingo
26bd81716b Align stack before entering JIT code
* libguile/jit.c (emit_entry_trampoline): Ensure stack is aligned when
  going into JIT code.
2019-04-28 13:54:34 +02:00
Andy Wingo
14e64a8b57 Ensure stack alignment in JIT code.
* libguile/jit.c (emit_entry_trampoline): Explicitly align stack.
2019-04-26 12:45:16 +02:00
Andy Wingo
52248cf622 Adapt to changes in upstream lightening
* libguile/jit.c (emit_entry_trampoline): Adapt to change in callee-save
  predicates.
2019-04-25 23:47:27 +02:00
Andy Wingo
4088915a7e Lower default JIT threshold as JIT is cheaper now
* libguile/jit.c (default_jit_threshold): Lower from 50000 to 1000.
2019-04-25 18:41:03 +02:00
Andy Wingo
e9a372b020 Re-enable fixnum less-than JIT fast-path
* libguile/jit.c (compile_less): Re-enable fast-path for fixnums, now
  that the JIT library works :)
2019-04-25 18:24:20 +02:00
Andy Wingo
0ef614ecf9 Fix a JIT bug
* libguile/jit.c (compile): Reset frame size as well when restarting
  compilation.  Fixes JIT errors.
2019-04-24 22:20:00 +02:00
Andy Wingo
9a32b4b1ad Adapt to new lightening call API
* libguile/jit.c: Operands have their ABI in them.  We can now have
  addends on GPR and MEM operands, which can improve register
  allocation.  Use new jit_calli_3, etc helper APIs.
2019-04-24 16:02:33 +02:00
Andy Wingo
cfffd5b241 Fix compilation of call-scm<-u64
* libguile/jit.c (compile_call_scm_from_u64): Fix to take operands from
  the right place.
2019-04-04 16:35:44 +02:00
Andy Wingo
5df432b763 Fix arena expansion logic
* libguile/jit.c (compile): Fix logic to clear old labels.
2019-04-04 14:59:38 +02:00
Andy Wingo
891e7600f4 JIT fixes for arena overflow
* libguile/jit.c (compute_mcode): Move analysis outside the code
emitter, as it doesn't need to re-run on overflow.
(compile): Clear labels before emitting, as they may have changed if we
overflowed.
2019-04-04 14:32:05 +02:00
Andy Wingo
9ff21412ff Minor JIT cleanups
* libguile/jit.c (fp_scm_operand): Fix assertion about register state.
(compile_call_scm_sz_u32): Fix ABI declaration for immediate.
Some whitespace cleanups as well.
2019-04-04 12:48:37 +02:00
Andy Wingo
89de2cb286 More various JIT fixen
* libguile/jit.c (prepare_jit_state): Remove unused function.
(initialize_thread_jit_state): Since the lightening state is allocated
using GC memory, trace the JIT state.
(compute_mcode): Avoid double-compile.
2019-04-04 12:10:13 +02:00
Andy Wingo
f8fa1156a9 Fix some aspects of instruction mcode addresses
* libguile/jit.c (struct scm_jit_state): Remove entry_mcode member.
(add_inter_instruction_patch): Fix off-by-one.
(compile): Reset reloc_idx when restarting a compile.  All instructions
record their addresses.
2019-04-04 11:42:33 +02:00
Andy Wingo
c0369df5e7 Fix JIT bugs
* libguile/jit.c (compile): Fix reloc fixup.
(compute_mcode): Correctly compute entry mcode.
2019-04-04 11:33:16 +02:00
Andy Wingo
fb9003c137 Fix jit_gpr_is_callee_save usage
* libguile/jit.c (emit_entry_trampoline): Fix invocations for
  jit_gpr_is_callee_save.
2019-04-04 11:18:08 +02:00
Andy Wingo
93f430d282 jit: Fix inter-instruction relocs.
* libguile/jit.c (struct pending_reloc, emit_entry_trampoline)
(add_inter_instruction_patch, compile, compute_mcode): Fix
inter-instruction relocs.
2019-04-04 10:59:37 +02:00
Andy Wingo
2db4ccd68c Fix jit.c compilation
* libguile/jit.c: Finish adaptation for lightening.  Still crashes
  though.
2019-04-03 21:08:30 +02:00
Andy Wingo
061c967bfe Checkpoint for lightning to lightening conversion 2019-04-03 17:42:27 +02:00
Andy Wingo
e9be4ea73d Adapt to lightning -> lightening name change
* libguile/jit.c: Include lightening.h.
* libguile/Makefile.am: Adapt.
2019-04-03 14:08:06 +02:00
Andy Wingo
e08d10af67 Fix JIT of 64-bit comparisons on 32-bit architectures
* libguile/jit.c (compile_u64_imm_less): Compare high word using
  not-equal, to avoid a signedness compare.
(compile_s64_imm_less, compile_imm_s64_less): Fix the not-less cases.
2018-10-09 12:32:38 +02:00
Andy Wingo
d41f2e9978 Better ursh/ulsh/srsh JIT on 32-bit platforms
* libguile/jit.c (compile_ursh_immediate, compile_ulsh_immediate)
(compile_srsh_immediate): Special-case shifts by 32 bits on 32-bit
platforms.  Avoids shifting by 0.
2018-10-09 12:32:33 +02:00