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

201 commits

Author SHA1 Message Date
Andy Wingo
daf3e88a81 Rework the way immediate encodings are calculated.
* module/system/base/types/internal.scm (scm->immediate-bits):
  (immediate-bits->scm, sign-extend, truncate-bits): New public
  routines.
* module/system/vm/assembler.scm (immediate-bits): Reimplement in terms
  of scm->immediate-bits and similar.
  (X8_S8_I16, X8_S8_ZI16): Rework operand encodings.
  (load-constant): Use truncate-bits to determine which cases apply.
2020-08-03 22:19:18 +02:00
Andy Wingo
8366634db7 Add eq-immediate? instruction
* libguile/jit.c (compile_eq_immediate, compile_eq_immediate_slow): Add
  JIT compiler.
* libguile/vm-engine.c (eq_immediate): New instruction.
* doc/ref/vm.texi (Comparison Instructions): Document.
* module/system/vm/assembler.scm (encode-X8_S8_ZI16!/shuffle): New
  shuffler.
* module/system/vm/disassembler.scm (code-annotation): Add eq-immediate?
  case.
2020-08-03 22:19:12 +02:00
Andy Wingo
172e5ccfc1 Add sign-extending make-immediate instruction
* doc/ref/vm.texi (Instruction Set, Constant Instructions): Document new
  instruction.
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): New first
  word kind with zi16 operand.
* libguile/jit.c (compile_make_immediate, compile_make_immediate_slow):
  New compilers.
  (COMPILE_X8_S8_ZI16): New operand kind.
* libguile/vm-engine.c (make-immediate): New instruction.
* module/language/bytecode.scm:
* module/system/vm/assembler.scm (encode-X8_S8_ZI16<-/shuffle):
  (signed-bits, load-constant): Support the new instruction kind.
* module/system/vm/disassembler.scm (disassemblers)
  (sign-extended-immediate, code-annotation): Support for zi16
  operands.
2020-07-30 17:36:11 +02:00
Andy Wingo
bb7fa5bdc2 Add jtable instruction
* doc/ref/vm.texi (Instruction Set): Document new v32-x8-l24 instruction
  kind.
  (Branch Instructions): Document jtable.
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add
  V32_X8_L24.
* libguile/jit.c (compile_jtable, compile_jtable_slow):
  (COMPILE_X8_S24__V32_X8_L24, analyze): Add stub JIT compiler
  implementation.
* libguile/vm-engine.c (jtable): New instruction.
* module/language/bytecode.scm (instruction-arity): Deprecate.
* module/system/vm/assembler.scm (encoder, assembler): Add V32_X8_L24
  case.
* module/system/vm/disassembler.scm (u32-ref, s32-ref): Move definitions
  to expansion-time only.
  (define-op-handlers): New definition, replacing visit-opcodes.
  (disassemblers, jump-parsers, stack-effect-parsers, clobber-parsers):
  Rework in terms of define-op-handlers.  Default case becomes #f, and
  add support for jtable.
  (disassemble-one, instruction-relative-jump-targets)
  (instruction-stack-size-after, instruction-slot-clobbers): Inline
  default case in the lookup procedure, not copied in the handler
  vector.
  (compute-labels): Add jtable case.
  (instruction-lengths-vector, instruction-length): Rework to allow
  variable-length instructions, and mark jtable as being
  variable-length.
  (instruction-has-fallthrough?): Add jtable to the no-fallthrough
  set.
2020-07-23 12:24:11 +02:00
Andy Wingo
c6636ff312 Bump objcode minor version
* libguile/loader.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump, so
  that compiled files from Guile 3.0.3 will error when loaded on 3.0.2.
2020-05-13 09:37:54 +02:00
Andy Wingo
2ba3eb4cf2 Fix shuffling assembler for new primcalls
* module/system/vm/assembler.scm (encode-X8_S8_C8_S8-C32!/shuffle): New
  shuffling assembler.
2020-05-11 15:03:19 +02:00
Andy Wingo
4274d615cc Add new lookup, lookup-bound intrinsics
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* libguile/intrinsics.c (lookup, lookup_bound):
* libguile/intrinsics.c (scm_bootstrap_intrinsics): New intrinsics.
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/effects-analysis.scm (current-module):
* module/language/cps/compile-bytecode.scm (compile-function):
* module/system/vm/assembler.scm: Add compiler support.
2020-05-11 10:22:34 +02:00
Andy Wingo
d6b6392cfb Rename "lookup" intrinsic to "module-variable"
It can return #f, unlike scm_(module_)?lookup.

* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* libguile/intrinsics.c (module_variable, scm_bootstrap_intrinsics):
  Rename.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm (current-module):
* module/language/cps/reify-primitives.scm (reify-lookup)
  (compute-known-primitives):
* module/language/tree-il/compile-bytecode.scm (emit-cached-module-box)
  (emit-cached-toplevel-box, emit-toplevel-box):
* module/language/tree-il/compile-cps.scm (toplevel-box):
* module/system/vm/assembler.scm (module-variable): Adapt users.
2020-05-11 09:46:40 +02:00
Andy Wingo
564f700771 Export emit-shuffle-down for baseline compiler
* module/system/vm/assembler.scm (emit-shuffle-down): Export.
2020-05-04 15:23:04 +02:00
Andy Wingo
d6b6daca37 Add intrinsics for a baseline compiler
Since there's no optimization in the baseline compiler, there's no sense
in instruction explosion.

* libguile/intrinsics.h:
* libguile/intrinsics.c ($car, $cdr, $set-car!, $set-cdr!,
  $variable-ref, $variable-set!, $vector-length, $vector-ref,
  $vector-set!, $vector-ref/immediate, $vector-set!, $allocate-struct,
  $struct-vtable, $struct-ref, $struct-set!  $struct-ref/immediate,
  $struct-set!): New intrinsics.
* libguile/jit.c (compile_call_scm_scm, compile_call_scm_scm_slow)
  (compile_call_scm_scm_scm, compile_call_scm_scm_scm_slow)
  (compile_call_scm_uimm_scm, compile_call_scm_uimm_scm_slow): New
  code generators.
* libguile/vm-engine.c (call-scm-scm, call-scm-scm-scm,
  call-scm-uimm-scm): New instructions.
* module/system/vm/assembler.scm (emit-null?, emit-false?, emit-nil?):
  Export these.  Also export emitters for the new intrinsics.
  (define-scm-scm-intrinsic, define-scm-uimm-scm-intrinsic)
  (define-scm-scm-scm-intrinsic): New helpers.
* doc/ref/vm.texi (Intrinsic Call Instructions): Add new instructions.
2020-04-29 21:47:37 +02:00
Andy Wingo
53a3602b20 Bump objcode minor version in preparation for new stable series
* libguile/loader.h (SCM_OBJCODE_MINIMUM_MINOR_VERSION):
  (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
2020-01-13 08:01:40 +01:00
Andy Wingo
7190905109 Fix frame-call-representation for callees without closures
* module/system/vm/assembler.scm (<arity>): Add new "has-closure?"
  flag.
  (begin-kw-arity, pack-arity-flags, write-arities): Write
  "elided-closure?" flag into binary.  A negative flag for compat
  reasons.
* module/system/vm/debug.scm (elided-closure?, arity-has-closure?): Add
  arity-has-closure? accessor.
* module/system/vm/frame.scm (frame-call-representation): Count from 0
  for callees with elided closures.
2019-11-27 15:04:55 +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
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
2751096c42 Define missing shuffling assembler for string-set! et al
* module/system/vm/assembler.scm (encode-X8_S8_S8_S8-C32!/shuffle):
  Define shuffling assembler for this instruction type.
2019-08-18 22:57:10 +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
f6c07e4eb2 Add compiler support for eliding closure bindings
* module/language/cps/closure-conversion.scm (compute-elidable-closures):
  New function.
  (convert-one, convert-closures): Add ability to set "self" variable of
  $kfun to $f, hopefully avoiding passing that argument in some cases.
* module/language/cps/compile-bytecode.scm (compile-function): Pass the
  has-closure? bit on through to the assembler.
* module/system/vm/assembler.scm (begin-standard-arity)
  (begin-opt-arity, begin-kw-arity): Only reserve space for the closure
  as appropriate.
* module/language/cps/slot-allocation.scm (allocate-args)
  (compute-defs-and-uses, compute-needs-slot)
  (compute-var-representations): Allow for closure slot allocation
  differences.
* module/language/cps/cse.scm (compute-defs):
* module/language/cps/dce.scm (compute-live-code):
* module/language/cps/renumber.scm (renumber, compute-renaming):
(allocate-args):
* module/language/cps/specialize-numbers.scm (compute-significant-bits):
(compute-defs):
* module/language/cps/split-rec.scm (compute-free-vars):
* module/language/cps/types.scm (infer-types):
* module/language/cps/utils.scm (compute-max-label-and-var):
* module/language/cps/verify.scm (check-distinct-vars):
(compute-available-definitions): Allow closure to be #f.
2019-06-07 17:01:37 +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
c9e052be49 Fix linker bug that could fail to find the shstrtab
* module/system/vm/linker.scm (<linker-object>): Add name field.  This
  allows the linker to find sections by name, notably before having
  found the .shstrtab section.  As there can be multiple sections with
  type SHT_STRTAB, this fixes a bug whereby we could use a section
  name (a strtab index) into an unrelated strtab.  In the past this
  worked because with ASCII identifiers there won't be an exception,
  although it is possible to accidentally mistake a shared string tail;
  but with UTF-8 identifiers, it's possible for a string table index to
  point in the middle of a codepoint, which is likely not valid UTF-8
  and would raise a bug.  Keeping an additional section name field fixes
  this bug.  Adapt all callers to pass a name argument to
  make-linker-object.
  (find-shstrndx): Update to look at the name field.
* module/system/vm/assembler.scm (make-object): Pass name to
  make-linker-object.

Thanks to Daniel Llorens for the test case.
2018-10-08 10:08:33 +02:00
Andy Wingo
4060728e0a Renumber instructions and bump objcode version
* libguile/loader.h (SCM_OBJCODE_MINIMUM_MINOR_VERSION):
  (SCM_OBJCODE_MINOR_VERSION): Bump version.
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
* libguile/vm-engine.c: Rearrange opcodes to be contiguous and in a
  somewhat sensible order.
2018-09-20 11:22:15 +02:00
Andy Wingo
b8a557d9a9 Fix bounds on compiler-emitted JIT metadata
* module/system/vm/assembler.scm (link-data): Fix relocation addend for
  JIT data bounds.  I never get this right!
2018-08-20 09:51:56 +02:00
Andy Wingo
d4abe8bbed Avoid needless 64-bit args on 32-bit machines for some intrinsics
* libguile/intrinsics.h:
* libguile/intrinsics.c (string_set_x): Change to take size_t and u32 as
  args.
  (allocate_words): Change to take size_t as arg.
* libguile/vm.c (expand_apply_argument): Rename from rest_arg_length,
  and also handle the stack manipulation.
* libguile/vm-engine.c (expand-apply-argument): Update for intrinsic
  change.
  (call-scm-sz-u32): Rename from call-scm-u64-u64, as it matches its
  uses and will compile better on 32-bit systems.
* module/system/vm/assembler.scm (define-scm-sz-u32-intrinsic):
  (string-set!): Update for new instrinsic call inst.
* libguile/jit.c (compile_call_scm_sz_u32): Adapt.
2018-08-13 14:30:01 +02:00
Andy Wingo
5c2e155fd7 Emit instrument-entry before programs
* module/system/vm/assembler.scm (<jit-data>, <meta>): Rework to have
  <meta> create the <jit-data> in the end-program, so that jit-data
  isn't mutable.  Record start and end PC values relative to '.rtl-text
  so that we don't need any more linker symbols.
  (emit-instrument-entry*, emit-instrument-loop*, begin-program):
  (end-program): Adapt.
  (begin-kw-arity): Include the initial instrument-entry in the first
  arity.
  (link-data, link-constants): Write the init routine before interning
  constants so that we correctly emit the jit-data for the init
  routine.
* libguile/programs.c (try_parse_arity): Skip over a
  scm_op_instrument_entry, if any.
2018-07-29 15:47:07 +02:00
Andy Wingo
a6b5049aa8 Emit instrument-loop in loops.
* am/bootstrap.am (SOURCES):
* module/Makefile.am (SOURCES): Handle renamve of handle-interrupts.scm
  to loop-instrumentation.scm.
* libguile/jit.h (SCM_JIT_COUNTER_ENTRY_INCREMENT): Rename from
  SCM_JIT_COUNTER_CALL_INCREMENT.
* libguile/vm-engine.c (instrument-entry): Rename from instrument-call.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  handle-interrupts code before calls and returns.  Compile the
  "instrument-loop" primcall to an "instrument-loop" instruction and a
  "handle-interrupts" instruction.
  (lower-cps): Adapt to add-loop-instrumentation name change.
* module/language/cps/loop-instrumentation.scm: Rename from
  handle-interrupts.scm and just add "instrument-loop" primcalls in
  loops.  The compiler will add handle-interrupts primcalls as
  appropriate.
* module/system/vm/assembler.scm (<jit-data>): New data type, for
  emitting embedded JIT data.
  (<meta>): Add field for current JIT data.
  (make-meta): Initialize current JIT data.
  (emit-instrument-entry*, emit-instrument-loop*): New instruction
  emitters that reference the current JIT data.
  (end-program): Now that all labels are known, arrange to serialize the
  JIT data.
  (link-data): Reserve space for JIT data, and add relocs to initialize
  the "start" / "end" fields.
2018-07-29 15:47:07 +02:00
Andy Wingo
87da1c8d20 Add instrument-call, instrument-loop VM instructions
* libguile/jit.h (struct scm_jit_function_data)
  (enum scm_jit_counter_value): New data types.
* libguile/jit.c (scm_jit_compute_mcode, scm_jit_enter_mcode): New
  function stubs.  Adapt label/offset compilers to take pointers.
* libguile/vm-engine.c (instrument-call, instrument-loop): New
  instructions.
* libguile/vm.c: Add jit.h include.
* module/system/vm/assembler.scm (emit-instrument-call)
  (emit-instrument-loop): New exports.
2018-07-29 15:47:03 +02:00
Andy Wingo
950a762dc2 Multiple-value returns now start from slot 0, not slot 1
This should reduce frame sizes.

* libguile/vm-engine.c (halt): Adapt to multiple-values change.  Also
  adapt to not having the boot closure on the stack.
  (receive, receive-values, subr-call, foreign-call): Adapt to expect
  values one slot down.
  (prompt): Capture one less word for the values return.
* libguile/vm.c (vm_dispatch_pop_continuation_hook):
  (vm_dispatch_abort_hook): Adapt for where to expect values.
  (vm_builtin_values_code): Add a call to shuffle-down before
  returning.  This is more overhead than what existed before, but the
  hope is that the savings elsewhere pay off.
  (vm_builtin_values_code): Adapt to different values location.
  (reinstate_continuation_x, compose_continuation): Adapt to place
  resume args at right position.
  (capture_delimited_continuation): Remove unused sp and ip arguments.
  (abort_to_prompt): Adapt to capture_delimited_continuation change.
  (scm_call_n): Adapt to not reserve space for the boot closure.
* module/language/cps/compile-bytecode.scm (compile-function): When
  returning values, adapt reset-frame call for return calling convention
  change.  Adapt truncating or rest returns to expect values in the
  right place.
* module/language/cps/slot-allocation.scm (compute-shuffles):
  (allocate-lazy-vars, allocate-slots): Allocate values from the "proc
  slot", not proc-slot + 1.
* module/system/vm/assembler.scm (emit-init-constants): Reset the frame
  before returning so that the return value is in the right place.
* test-suite/tests/rtl.test: Update for return convention change.
* libguile/foreign.c (get_foreign_stub_code): Update for return calling
  convention change.
2018-07-20 11:42:30 +02:00
Andy Wingo
c2a8224a63 Rework VM approach to shuffling unknown numbers of args
* libguile/vm-engine.c (shuffle-down, expand-apply-argument): New
  instructions.
  (tail-call, tail-call-label, return-values): Don't reset the frame.
  The compiler should reset the frame appropriately.
  (tail-call/shuffle, tail-apply): Remove unused instructions.
* libguile/vm.c (vm_builtin_apply_code): Use new shuffle-down and
  expand-apply-argument opcodes.
  (vm_builtin_call_with_values_code): Replace tail-call/shuffle with
  shuffle-down then tail-call.
* libguile/jit.c (compile_shuffle_down, compile_expand_apply_argument):
  Add compiler stubs
  (COMPILE_X8_F12_F12): New definition.
  (compile_tail_call_shuffle, compile_tail_apply): Remove unused
  compilers.
* module/language/cps/compile-bytecode.scm (compile-function): Emit
  reset-frame before tail calls and returns.
* module/system/vm/assembler.scm (system): Remove unbound "emit-return"
  export.
* module/system/vm/disassembler.scm (code-annotation)
  (instruction-has-fallthrough?, define-stack-effect-parser): Adapt for
  opcode changes.
2018-07-20 11:42:30 +02:00
Andy Wingo
8918165c40 Compile current-module as intrinsic call
* libguile/fluids.c (scm_i_fluid_ref): New internal function.
  (scm_fluid_ref): Use scm_i_fluid_ref.
* libguile/intrinsics.h:
* libguile/intrinsics.c (current_module): New intrinsic.
* libguile/modules.c (scm_i_current_module): New internal function.
  (scm_current_module): Use new internal function.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add current-module as an intrinsic primitive.
* module/system/vm/assembler.scm (define-scm<-thread-intrinsic):
  (current-module): Arrange to compile to intrinsic call.
2018-06-27 14:57:51 +02:00
Andy Wingo
ceffb5e990 Compile "define!" via intrinsic
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add new define!
  intrinsic.
* module/language/cps/compile-bytecode.scm (compile-function): Adapt
  compilation for define! to take two arguments.
* module/language/cps/effects-analysis.scm (current-module): Update
  define! for two arguments.
* module/language/tree-il/compile-cps.scm (convert): When reifying
  "define", grab the current module.
* module/system/vm/assembler.scm (define!): Define assembler as
  intrinsic.
2018-05-14 15:15:22 +02:00
Andy Wingo
77e7bea4c2 Remove backend support for cached-module-box et al.
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  unused assemblers for cached-module-box, cached-toplevel-box, and
  cache-current-module!.
* module/language/cps/effects-analysis.scm (&cache): New memory kind.
  (cache-current-module!): Set &cache memory, not &box.
  (resolve-module, lookup-module, cache-ref, cache-set!): Add effect
  annotations.
* module/system/vm/assembler.scm (emit-cache-current-module!)
  (emit-cached-toplevel-box, emit-cached-module-box): Remove
  assemblers.
* module/system/vm/disassembler.scm (code-annotation, fold-code-range):
  Remove special cases for toplevel-box and module-box.
* module/system/xref.scm (program-callee-rev-vars): Add a FIXME for the
  future.
2018-05-14 14:04:59 +02:00
Andy Wingo
f6de1b0620 Add cache-ref, cache-set! macro-instructions
* module/system/vm/assembler.scm (<cache-cell>): Remove "scope" member.
  Just be an opaque key comparable with equal?.
  (intern-cache-cell): Remove scope arg.
  (intern-module-cache-cell): Remove; callers use intern-cache-cell now.
  (cache-current-module!, cached-toplevel-box, cached-module-box): Create
  cache keys that by construction won't collide between types.
  (cache-ref, cache-set!): Add new macro assemblers.
* module/language/cps/reify-primitives.scm:
* module/language/cps/compile-bytecode.scm: Add cases for new macro
  instructions.
2018-05-14 14:04:59 +02:00
Andy Wingo
fb344a25d5 Add intrinsics for module operations
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* module/system/vm/assembler.scm (resolve-module, lookup): New intrinsics.
* module/language/cps/compile-bytecode: Add cases for primcalls
  corresponding to new intrinsics.
2018-05-14 14:04:54 +02:00
Andy Wingo
1532b570e5 lsh, rsh etc are intrinsics
* libguile/intrinsics.c (lsh, rsh, lsh_immediate, rsh_immediate): New
  intrinsics.
  (scm_bootstrap_intrinsics): Wire up the intrinsics.
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add new
  intrinsics.
* libguile/vm-engine.c (call-scm<-scm-u64): New intrinsic caller.
  (lsh, rsh, lsh/immediate, rsh/immediate): Disable.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add new intrinsics.
* module/system/vm/assembler.scm: Adapt assemblers for new intrinsics.
2018-05-01 07:02:45 +02:00
Andy Wingo
89fda6da60 push and pop dynamic state via intrinsics
* libguile/intrinsics.c (push_dynamic_state, pop_dynamic_state): New
  intrinsics.
  (scm_bootstrap_intrinsics): Add new intrinsics.
* libguile/intrinsics.h: Declare new intrinsics.
* libguile/vm-engine.c (call-thread-scm): New intrinsic caller.
  (push-dynamic-state, pop-dynamic-state): Disable.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add new intrinsics.
* module/system/vm/assembler.scm (push-dynamic-state)
  (pop-dynamic-state): Emit as intrinsics.
2018-04-29 10:41:24 +02:00
Andy Wingo
2eb9c755d1 Intrinsics for dynamic state instructions
* libguile/intrinsics.c (wind, unwind, push_fluid, pop_fluid)
  (fluid_ref): New intrinsics.
  (scm_bootstrap_intrinsics): Wire them up.
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Declare new
  intrinsics.
* libguile/vm-engine.c (wind, unwind, push_fluid, pop_fluid)
  (fluid_ref): Disable these instructions.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add new intrinsics.
* module/system/vm/assembler.scm (wind, unwind, push_fluid, pop_fluid)
  (fluid_ref): Assemble as intrinsics.
2018-04-29 10:22:30 +02:00
Andy Wingo
4779a10223 Add support for dynamic-state-related intrinsics
* libguile/vm-engine.c (call-thread, call-thread-scm-scm)
  (call-scm<-thread-scm): New intrinsics.
* module/system/vm/assembler.scm (define-thread-scm-scm-intrinsic)
  (define-thread-intrinsic, define-scm<-thread-scm-intrinsic): New
  helpers.
  (encode-X8_S12_S12-C32!/shuffle): New shuffler.
* libguile/intrinsics.h: Add new intrinsic types.
2018-04-29 10:13:50 +02:00
Andy Wingo
dff85f6f9f Explode atomic box ops to new atomic instructions
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add C8_S24
  word type.
* libguile/vm-engine.c (UNPACK_8_24): New helper.
  (atomic-scm-ref/immediate, atomic-scm-set!/immediate)
  (atomic-swap-scm!/immediate, atomic-scm-compare-and-swap!/immediate):
  New instructions.
  (make-atomic-box, atomic-box-ref, atomic-box-set!, atomic-box-swap!)
  (atomic-box-compare-and-swap!): Disable these ops.
* module/language/bytecode.scm (compute-instruction-arity): Add C8_S24
  support.
* module/system/vm/assembler.scm: Add C8_S24 support.  Export assemblers
  for new opcodes.
* module/system/vm/disassembler.scm (disassembler): Support C8_S24.
* module/language/cps/compile-bytecode.scm (compile-function): Replace
  old atomic-box assemblers with the new instructions.
* module/language/cps/effects-analysis.scm (annotation->memory-kind):
* module/language/cps/types.scm (annotation->type): Add cases for atomic
  boxes.  Mark as all memory kinds because atomic ops serialize memory
  accesses.
* module/language/tree-il/compile-cps.scm (make-atomic-box):
  (ensure-atomic-box, atomic-box-ref, atomic-box-set!):
  (atomic-box-swap!, atomic-box-compare-and-swap!): Explode these ops to
  more basic instructions.
* module/system/base/types/internal.scm (%tc7-atomic-box): Add forgotten
  export.
2018-04-13 10:09:56 +02:00
Andy Wingo
25a0fe8839 logsub is intrinsic
* libguile/intrinsics.h:
* libguile/intrinsics.c (logsub): New intrinsic.
  (scm_bootstrap_intrinsics): Init new intrinsic.
* libguile/vm-engine.c (logsub): Disable.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add logsub.
* module/system/vm/assembler.scm: Update logsub intrinsic assembler.
2018-04-12 17:10:35 +02:00
Andy Wingo
7e386bbc70 u64->scm, s64->scm intrinsics
* libguile/intrinsics.h (u64->scm, s64->scm): New intrinsics.
* libguile/intrinsics.c (scm_bootstrap_intrinsics): Initialize new
  intrinsics.
* libguile/vm-engine.c (call-scm<-u64, call-scm<-s64): New intrinsic
  callers.
  (u64->scm, s64->scm): Disable instructions.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add new intrinsics as macro-instructions.
* module/system/vm/assembler.scm (define-scm<-u64-intrinsic):
  (define-scm<-s64-intrinsic, u64->scm, s64->scm): Wire up new
  intrinsics.
2018-04-12 16:43:57 +02:00
Andy Wingo
dd88fc569d scm->u64, scm->s64, scm->u64/truncate intrinsics
* libguile/intrinsics.c (scm_to_uint64_truncate): New intrinsic.
  (scm_bootstrap_intrinsics): Init new intrinsics.
* libguile/intrinsics.h: Add scm->u64, scm->u64/truncate, and scm->s64
  as intrinsics, with their corresponding types.
* libguile/vm-engine.c (call-u64<-scm, call-s64<-scm): New intrinsic
  calling ops.
  (scm->u64, scm->s64, scm->u64/truncate): Disable opcodes.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add intrinsics as new macroinstructions.
* module/system/vm/assembler.scm: Declare new intrinsic assemblers.
2018-04-12 16:22:40 +02:00
Andy Wingo
b285226477 Disable f64->scm instruction
* libguile/vm-engine.c (f64->scm): Disable instruction.
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  f64->scm case.
* module/system/vm/assembler.scm: Remove emit-f64->scm export.
2018-04-10 20:41:04 +02:00
Andy Wingo
b9f7621e13 Add scm->f64 intrinsic
* libguile/vm-engine.c (call-f64<-scm): New intrinsic kind.
  (scm->f64): Disable instruction.
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* module/language/cps/reify-primitives.scm (compute-known-primitives):
* module/system/vm/assembler.scm (define-f64<-scm-intrinsic): Add scm->f64.
2018-04-10 19:39:50 +02:00
Andy Wingo
954bfad262 Class-of is intrinsic
* libguile/vm-engine.c (class-of): Disable.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add class-of as macro-instruction.
* libguile/intrinsics.c (scm_bootstrap_intrinsics): Add class-of.
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add class-of.
* module/system/vm/assembler.scm (class-of): Define as intrinsic.
2018-04-10 18:32:31 +02:00
Andy Wingo
1c49c1407b string->number, etc intrinsics
* libguile/intrinsics.c (string_to_number): New helper.
  (scm_bootstrap_intrinsics): Init new intrinsics.
* libguile/intrinsics.h (string->number, string->symbol)
  (symbol->keyword): Add new intrinsics.
* libguile/vm-engine.c (call-scm<-scm): New intrinsic dispatcher.
  (string->number, string->symbol, symbol->keyword): Disable these
  instructions.
* module/system/vm/assembler.scm (encode-X8_S12_S12-C32<-/shuffle):
  (define-scm<-scm-intrinsic): Enable scm<-scm intrinsics.
  (string->number, string->symbol, symbol->keyword): New intrinsic
  assemblers.
2018-04-10 17:56:08 +02:00
Andy Wingo
9f98b4a5b1 Add $code CPS expression type
* module/language/cps.scm ($code): New CPS type, for labels as values.
  Add cases to all CPS type dispatches.  $closure now indicates only
  statically allocated closures.
* module/language/cps/closure-conversion.scm (convert-one): Only reify
  $closure for statically allocated procedures.  Otherwise allocate an
  object using low-level primitives.
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  make-closure case.
* module/language/cps/slot-allocation.scm (compute-var-representations):
  $code produces a u64 value.
* module/system/vm/assembler.scm: Remove make-closure export.
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/devirtualize-integers.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/licm.scm:
* module/language/cps/peel-loops.scm:
* module/language/cps/renumber.scm:
* module/language/cps/rotate-loops.scm:
* module/language/cps/simplify.scm:
* module/language/cps/specialize-numbers.scm:
* module/language/cps/types.scm:
* module/language/cps/utils.scm:
* module/language/cps/verify.scm: Add cases for $code.
2018-04-10 17:06:27 +02:00
Andy Wingo
70e3a4a311 Add load-label instruction
* libguile/vm-engine.c (load-label): New instruction.
* module/system/vm/assembler.scm: Add emit-load-label.
* module/system/vm/disassembler.scm (code-annotation):
  (fold-code-range): Add load-label support.
2018-04-10 14:36:15 +02:00
Andy Wingo
21d5897b4c Instruction explosion for char->integer
* module/language/cps/effects-analysis.scm:
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/types.scm:
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  char->integer cases.
* module/system/vm/assembler.scm: Remove emit-char->integer export.
* module/language/tree-il/compile-cps.scm (char->integer): Define
  instruction exploder.
2018-04-10 13:45:33 +02:00
Andy Wingo
9355985154 Remove integer->char op
* libguile/vm-engine.c (integer->char): Remove unused op.
* module/language/cps/types.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  integer->char cases.
* module/system/vm/assembler.scm: Remove emit-integer->char.
2018-04-10 13:33:13 +02:00
Andy Wingo
2964abad05 Explode "string-set!"
* module/language/cps/effects-analysis.scm (string-ref): Remove effects
  declaration, given that the primitive is exploded now.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add string-set!.
* libguile/vm-engine.c (string-set!): Disable opcode.
* module/language/cps/types.scm (string-ref, string-set!): Remove type
  checker and inferrers for string-ref and string-set!, as both are
  exploded.  In the case of string-set! there are still type-check
  effects in the intrinsic call but they can't be elided by the checker,
  as we don't track when strings are read-only.
* module/language/tree-il/compile-cps.scm (ensure-char): New helper.
  (string-set!): New primcall exploded converter.
2018-04-10 12:14:47 +02:00