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

9452 commits

Author SHA1 Message Date
Andy Wingo
1152036333 Move receive slow path out of line
* libguile/jit.c (compile_receive, compile_receive_slow): Move slow path
  out of line.
2019-12-10 17:09:20 +01:00
Andy Wingo
a3be0b1e2d Move handle-interrupts slow path out of line
* libguile/jit.c (compile_handle_interrupts)
  (compile_handle_interrupts_slow): Move slow path out of line.
2019-12-10 17:08:22 +01:00
Andy Wingo
9c329776df Move add, sub slow paths out of line
* libguile/jit.c (compile_call_scm_from_scm_sc)
  (compile_call_scm_from_scm_scm_slow): Move non-fixnum path out of
  line.
2019-12-10 17:08:05 +01:00
Andy Wingo
fafa502875 Move add/immediate, sub/immediate slow paths out of line
* libguile/jit.c (compile_call_scm_from_scm_uimm)
  (compile_call_scm_from_scm_uimm_slow): Move non-fixnum path out of
  line.
2019-12-10 17:06:06 +01:00
Andy Wingo
d21c5a26da Add infrastructure for out-of-line JIT compilation of slow paths
* libguile/jit.c (struct pending_reloc): Rename target_vcode_offset
  field to target_label_offset.
  (inline_label_offset, slow_label_offset): New helpers.
  (emit_direct_tail_call): Use inline_label_offset helper.
  (add_pending_reloc): Factor out of add_inter_instruction_patch.
  (add_inter_instruction_patch): Use inline_label_offset helper.
  (add_slow_path_patch): New helper.
  (continue_after_slow_path): New helper.

  Add slow path compilers for all instructions.

  (compile_slow_path): New helper.
  (compile): Compile slow paths after main code.
  (compute_mcode): Allocate twice as many labels.
2019-12-10 17:05:03 +01:00
Andy Wingo
4a6a7e15d6 Remove vm->sp_min_since_gc
* libguile/jit.c (emit_alloc_frame_for_sp):
* libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME):
* libguile/vm.c (vm_increase_sp, scm_i_vm_prepare_stack):
  (return_unused_stack_to_os, vm_expand_stack, alloc_frame):
  (scm_call_with_stack_overflow_handler):
* libguile/vm.h (struct scm_vm): Remove sp_min_since_gc handling.  It
  was a very minor optimization when it was centralized in vm.c, but now
  with JIT it's causing too much duplicate code generation.
2019-12-09 22:03:34 +01:00
Ludovic Courtès
edf5aea7ac Fix non-deterministic crash in 'finalization_thread_proc'.
Fixes <https://bugs.gnu.org/37757>.
Reported by Jesse Gibbons <jgibbons2357@gmail.com>.

* libguile/finalizers.c (finalization_thread_proc): Do not enter the
"switch (data.byte)" condition when data.n <= 0.
2019-12-09 14:44:59 +01:00
Andy Wingo
a1e88ebc12 Fix JIT tier-up from within loops for already-JIT-compiled functions
* libguile/jit.c (scm_jit_compute_mcode): If a caller wants mcode for a
  loop but the function already has mcode, instead of punting, just
  compile again.
2019-12-08 21:44:47 +01:00
Andy Wingo
2fbc38f0d0 Fix stack overflow if printing a pre-boot error throws an error
* libguile/throw.c (scm_throw): Fall back to fprintf if all is lost.
2019-11-25 09:46:58 +01:00
Ludovic Courtès
659526d33b ports: 'scm_port_poll' honors "w" flags.
Fixes <https://bugs.gnu.org/36709>.
Reported by Mark H Weaver <mhw@netris.org>.

* libguile/ports.c (scm_port_poll): Replace second POLLIN by POLLOUT.
2019-11-18 15:14:56 +01:00
Andy Wingo
aabea7394a Allow equality between arrays of vu8 and u8
* libguile/array-map.c (scm_array_equal_p): Treat vu8 and u8 arrays as
  equivalent.
2019-11-16 14:34:53 +01:00
Andy Wingo
f4ca107f7f Rebase throw/catch on top of raise-exception/with-exception-handler
* libguile/exceptions.c:
* libguile/exceptions.h: New files.
* libguile.h: Add exceptions.h.
* libguile/Makefile.am (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
  (DOT_X_FILES, DOT_DOC_FILES, modinclude_HEADERS): Add exceptions.c and
  exceptions.h.
* libguile/init.c (scm_i_init_guile): Initialize exceptions.
* libguile/threads.c (scm_spawn_thread): Use new names for
  scm_i_make_catch_handler and scm_c_make_thunk.
* libguile/throw.c: Rewrite to be implemented in terms of
  with-exception-handler / raise-exception.
* libguile/throw.h: Use data types from exceptions.h.  Move
  scm_report_stack_overflow and scm_report_out_of_memory to
  exceptions.[ch].
* module/ice-9/boot-9.scm (&error, &programming-error)
  (&non-continuable, make-exception-from-throw, raise-exception)
  (with-exception-handler): New top-level definitions.
  (throw, catch, with-throw-handler): Rewrite in terms of
  with-exception-handler and raise-exception.
: New top-level definitions.
* module/ice-9/exceptions.scm: Adapt to re-export &error,
  &programming-error, &non-continuable, raise-exception, and
  with-exception-handler from boot-9.
  (make-quit-exception, guile-quit-exception-converter): New exception
  converters.
  (make-exception-from-throw): Override core binding.
* test-suite/tests/eval.test ("inner trim with prompt tag"): Adapt to
  "with-exception-handler" being the procedure on the stack.
  ("outer trim with prompt tag"): Likewise.
* test-suite/tests/exceptions.test (throw-test): Use pass-if-equal.
* module/srfi/srfi-34.scm: Reimplement in terms of core exceptions, and
  make "guard" actually re-raise continuations with the original "raise"
  continuation.
2019-11-13 22:24:19 +01:00
Andy Wingo
f2c8ff5a52 Remove boot "catch" definition.
* libguile/throw.c (scm_init_throw): Remove boot definition of "catch".
2019-11-07 16:46:53 +01:00
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
0a3591c374 Fix fatan2 intrinsic initialization
* libguile/intrinsics.c (scm_bootstrap_intrinsics): Fix fatan2
  initialization.
2019-08-25 21:26:42 +02:00
Andy Wingo
253cf3dc6f Revert "Revert scm_c_make_char rename"
My reversion of Mark's commit was in error; the supposed ABI change was
never released.

This reverts commit 3925a64682.
2019-08-24 11:57:39 +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
9e3a5c9a10 Fix the jitless fix
* libguile/vm.c (capture_continuation): Use #if, not #ifdef, to test the
  condition.
2019-08-19 16:43:43 +02:00
Andy Wingo
9d78665539 Disable some JIT compilation code when JIT configured out
* libguile/vm.c (vm_recompute_disable_mcode, capture_continuation):
  Disable logic if JIT not configured.
2019-08-19 16:31:29 +02:00
Andy Wingo
79a40cf717 Add "mod" field to tree-il toplevel ref, set, define
Add "mod" field to <toplevel-ref>, <toplevel-set>, and
<toplevel-define>, indicating the expander's idea of what the current
module is when a toplevel variable is accessed or created.  This will
help in later optimizations.

* libguile/expand.c (TOPLEVEL_REF, TOPLEVEL_SET, TOPLEVEL_DEFINE)
  (expand, expand_define, expand_set_x, convert_assignment):
* libguile/expand.h (SCM_EXPANDED_TOPLEVEL_REF_FIELD_NAMES):
(SCM_MAKE_EXPANDED_TOPLEVEL_REF, SCM_EXPANDED_TOPLEVEL_SET_FIELD_NAMES):
(SCM_MAKE_EXPANDED_TOPLEVEL_SET, SCM_EXPANDED_TOPLEVEL_DEFINE_FIELD_NAMES):
(SCM_MAKE_EXPANDED_TOPLEVEL_DEFINE):
* module/ice-9/compile-psyntax.scm (translate-literal-syntax-objects):
* module/ice-9/psyntax-pp.scm:
* module/ice-9/psyntax.scm:
* module/language/tree-il.scm:
* module/language/tree-il.scm (parse-tree-il, make-tree-il-folder):
(pre-post-order):
* module/language/tree-il/analyze.scm (goops-toplevel-definition):
(macro-use-before-definition-analysis, proc-ref?, format-analysis):
* module/language/tree-il/compile-cps.scm (convert):
* module/language/tree-il/debug.scm (verify-tree-il):
* module/language/tree-il/effects.scm (make-effects-analyzer):
* module/language/tree-il/fix-letrec.scm (free-variables):
* module/language/tree-il/peval.scm (peval):
* test-suite/tests/tree-il.test: Adapt uses.
2019-08-18 22:27:12 +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
3869cdc59d Merge from stable-2.2 2019-08-02 15:34:28 +02:00
Andy Wingo
aad64cf381 Merge from stable-2.2 2019-08-02 15:29:33 +02:00
Andy Wingo
3925a64682 Revert scm_c_make_char rename
This was, I think, an unintentional ABI change.
Reverts 579dd2da44.
2019-08-02 15:19:17 +02:00
Andy Wingo
b3b14fe6a2 Merge from stable-2.2 2019-08-02 15:04:20 +02:00
Andy Wingo
50c744d43a Merge from stable-2.2 2019-08-02 15:03:53 +02:00
Andy Wingo
8ecc82959a Merge from stable-2.2 2019-08-02 15:03:18 +02:00
Andy Wingo
94b20b79ec Merge from stable-2.2 2019-08-02 15:02:49 +02:00
Andy Wingo
c5526c4e40 Merge from stable-2.2 2019-08-02 15:02:11 +02:00
Andy Wingo
967f129f80 Merge from stable-2.2 2019-08-02 14:59:48 +02:00
Andy Wingo
dbb2b1d437 Merge from stable-2.2 2019-08-02 14:57:57 +02:00
Andy Wingo
24a48d8900 Merge from stable-2.2 2019-08-02 14:57:42 +02:00
Andy Wingo
afb2c96248 Merge from stable-2.2 2019-08-02 14:57:29 +02:00
Andy Wingo
0a78d39b77 Merge from stable-2.2 2019-08-02 14:31:46 +02:00
Ludovic Courtès
ab2fd70ef1 'strftime' and 'strptime' honor the locale encoding.
Fixes <https://bugs.gnu.org/35920>.
Reported by Christopher Lam <christopher.lck@gmail.com>.

* libguile/stime.c (scm_strftime): Use 'scm_to_locale_stringn' instead
of 'scm_to_utf8_stringn'.
(scm_strptime): Likewise, and use 'scm_string_length' instead of
'u8_strnlen'.
* test-suite/tests/time.test ("strftime")["strftime passes wide
characters"]: Wrap body in 'with-locale'.
["strftime fr_FR.utf8", "strftime fr_FR.iso88591"]: New tests.
("strptime")["strftime fr_FR.utf8", "strftime fr_FR.iso88591"]: New
tests.
2019-06-30 21:31:36 +02:00
Ludovic Courtès
f4f9d177f0 Remove references to 'inet-ntoa' and 'inet-aton'.
These procedures were removed in Guile 2.2 by commit
fc7bd367ab (May 2011).

* libguile/socket.h (scm_inet_aton, scm_inet_ntoa): Remove.
* module/system/repl/server.scm (make-tcp-server-socket): Use
'inet-pton' instead of 'inet-aton'.
* doc/ref/web.texi (HTTP): Likewise in 'declare-header!' example.
* doc/ref/posix.texi (Network Address Conversion): Remove documentation
of 'inet-ntoa' and 'inet-aton'.
2019-06-24 15:10:13 +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
33aecf48b0 Inline freelist vectors into scm_thread
* libguile/gc-inline.h:
* libguile/threads.h (SCM_INLINE_GC_GRANULE_WORDS)
  (SCM_INLINE_GC_GRANULE_BYTES, SCM_INLINE_GC_FREELIST_COUNT): Move
  definitions here, from gc-inline.h.
  (struct scm_thread): Inline freelist vectors.
* libguile/threads.c (thread_mark): Update marker for pointerless
  freelists.
  (on_thread_exit): Clear individual freelist entries, instead of the
  vector as a whole.
  (guilify_self_2): No need to alloc freelist vectors.
2019-06-20 13:48:24 +02:00
Andy Wingo
117bb3bade Rearrange scm_thread for better locality
* libguile/threads.h (struct scm_thread): Move async-related bits up, so
  that the VM can access them easier.  Likewise for freelists (which we
  will inline soon).
2019-06-20 13:37:47 +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
Ludovic Courtès
8cf7b06d24 Copy terminating zero in 'scm_cat_path'.
* libguile/script.c (scm_cat_path): Pass N + 1, not N, to 'strncat'.
Reported by GCC 9.1.0.
2019-06-20 11:43:54 +02:00
Ludovic Courtès
d59dc5fbf2 srfi-14: Fix possible buffer overrun in '%char-set-dump'.
* libguile/srfi-14.c (scm_sys_char_set_dump): Change array size from 9
to 11 as suggested by GCC 9.1.0.
2019-06-20 11:34:46 +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
3b7061323e Merge remote-tracking branch 'lightening/master' 2019-06-20 10:55:13 +02:00
Andy Wingo
acce0297ff Merge remote-tracking branch 'lightening/master' 2019-06-20 10:15: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