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

388 commits

Author SHA1 Message Date
Andy Wingo
c3240d09b2 Unbox indexes of vectors, strings, and structs
* libguile/vm-engine.c (string-length, string-ref)
  (make-vector, vector-ref, vector-set!)
  (allocate-struct, struct-ref, struct-set!): Take indexes and return
  lengths as untagged u64 values.

* libguile/vm.c (vm_error_not_a_string): New helper.

* module/language/tree-il/compile-cps.scm (convert):
* module/language/cps/constructors.scm (inline-vector):
* module/language/cps/closure-conversion.scm (convert-one): Untag
  arguments to {string,vector,struct}-{ref,set!}, make-vector, and
  allocate-struct.  Tag return values from {string,vector}-length.

* module/language/cps/slot-allocation.scm (compute-var-representations):
  vector-length and string-length define u64 slots.

* module/language/cps/effects-analysis.scm: make-vector no longer causes
  a &type-check effect.

* module/language/cps/types.scm: Update to expect &u64 values for
  lengths and indexes.
2015-12-01 15:42:24 +01:00
Andy Wingo
a08b3d40f8 Untag values and indexes for all bytevector instructions
* libguile/vm-engine.c (bv-s8-ref, bv-s16-ref, bv-s32-ref, bv-s64-ref):
  Unbox index and return unboxed S32 value.
  (bv-s8-set!, bv-s16-set!, bv-s32-set!, bv-s64-set!): Unbox index and
  take unboxed S32 value.
  (bv-u8-ref, bv-u16-ref, bv-u32-ref, bv-u64-ref)
  (bv-s8-set!, bv-s16-set!, bv-s32-set!, bv-s64-set!): Likewise, but
  with unsigned values.
  (bv-f32-ref, bv-f32-set!, bv-f64-ref, bv-f64-set!): Use memcpy to
  access the value so we don't have to think about alignment.  GCC will
  inline this to a single instruction on architectures that support
  unaligned access.
* libguile/vm.c (vm_error_out_of_range_uint64)
  (vm_error_out_of_range_int64): New helpers.

* module/language/cps/slot-allocation.scm (compute-var-representations):
  All bytevector ref operations produce untagged values.

* module/language/cps/types.scm (define-bytevector-accessors): Update
  for bytevector untagged indices and values.

* module/language/cps/utils.scm (compute-constant-values): Fix s64
  case.

* module/language/tree-il/compile-cps.scm (convert): Box results of all
  bytevector accesses, and unbox incoming indices and values.
2015-12-01 15:42:24 +01:00
Andy Wingo
8bf77f7192 Add support for unboxed s64 values
* libguile/frames.c (enum stack_item_representation):
  (scm_to_stack_item_representation):
  (scm_frame_local_ref, scm_frame_local_set_x): Support for S64
  representations.

* libguile/frames.h (union scm_vm_stack_element): Add signed 64-bit
  integer field.

* libguile/vm-engine.c (scm->s64, s64->scm, load-s64): New
  instructions.

* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/effects-analysis.scm:
* module/language/cps/slot-allocation.scm (compute-var-representations)
  (compute-needs-slot, allocate-slots):
* module/language/cps/utils.scm (compute-constant-values):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Add support for new primcalls.

* module/language/cps/types.scm (&s64): New type.
  (&s64-min, &s64-max, &u64-max): New convenience definitions.
  (&range-min, &range-max): Use &s64-min and &u64-max names.
  (scm->s64, load-s64, s64->scm): Add support for new primcalls.

* module/system/vm/assembler.scm (emit-scm->s64, emit-s64->scm)
  (emit-load-s64): New exports.
* module/system/vm/assembler.scm (write-arities): Support for s64
  slots.

* module/system/vm/debug.scm (arity-definitions): Support for s64
  slots.
2015-12-01 15:42:19 +01:00
Andy Wingo
f34688ad25 New instructions load-f64, load-u64
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add word
  types for immediate f64 and u64 values.
  (TYPE_WIDTH): Bump up by a bit, now that we have 32 word types.
  (NOP, parse_instruction): Use 64-bit meta type.

* libguile/vm-engine.c (load-f64, load-u64): New instructions.

* module/language/bytecode.scm (compute-instruction-arity): Add parser
  for new instruction word types.

* module/language/cps/compile-bytecode.scm (compile-function): Add
  special-cased assemblers for new instructions, and also for scm->u64
  and u64->scm which I missed before.

* module/language/cps/effects-analysis.scm (load-f64, load-u64): New
  instructions.

* module/language/cps/slot-allocation.scm (compute-needs-slot): load-f64
  and load-u64 don't need slots.
  (compute-var-representations): Update for new instructions.

* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Specialize scm->f64 and scm->u64 to make-f64 and make-u64.

* module/language/cps/types.scm (load-f64, load-u64): Wire up to type
  inference, though currently type inference only runs before
  specialization.

* module/language/cps/utils.scm (compute-defining-expressions): For some
  reason I don't understand, it's possible to see two definitions that
  are equal but not equal? here.  Allow for now.
  (compute-constant-values): Punch through type conversions to get
  constant u64/f64 values.

* module/system/vm/assembler.scm (assembler): Support for new word
  types.  Export the new assemblers.
2015-12-01 11:30:55 +01:00
Andy Wingo
bdfa1c1b42 Add tagged and untagged arithmetic ops with immediate operands
* libguile/vm-engine.c (add/immediate, sub/immediate)
  (uadd/immediate, usub/immediate, umul/immediate): New instructions.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/slot-allocation.scm (compute-needs-slot):
* module/language/cps/types.scm:
* module/system/vm/assembler.scm (system):
* module/language/cps/effects-analysis.scm: Support
  for new instructions.

* module/language/cps/optimize.scm (optimize-first-order-cps): Move
  primcall specialization to the last step -- the only benefit of doing
  it earlier was easier reasoning about side effects, and we're already
  doing that in a more general way with (language cps types).
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Specialize add and sub to add/immediate and sub/immediate, and
  specialize u64 addition as well.  U64 specialization doesn't work now
  though because computing constant values doesn't work for U64s; oh
  well.
2015-12-01 11:30:55 +01:00
Andy Wingo
8f18b71b7a Remove add1 and sub1
* libguile/vm-engine.c: Remove add1 and sub1 instructions.  Will replace
  with add/immediate and sub/immediate.
* module/language/tree-il/peval.scm (peval): If we reify a new
  <primcall>, expand it.  Removes 1- and similar primcalls.
* module/language/tree-il/primitives.scm: Don't specialize (+ x 1) to 1+.
  (expand-primcall): New export, does a single primcall expansion.
  (expand-primitives): Use the new helper.
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm:
* module/language/cps/types.scm:
* module/system/vm/assembler.scm: Remove support for add1 and sub1 CPS
  primitives.
* test-suite/tests/peval.test ("partial evaluation"): Adapt tests that
  expect 1+/1- to expect +/-.
2015-12-01 11:30:55 +01:00
Andy Wingo
d294d5d1e1 Add unsigned 64-bit arithmetic operators: uadd, usub, umul
* libguile/vm-engine.c (uadd, usub, umul): New ops.
* module/language/cps/effects-analysis.scm (uadd, usub, umul): Add
  effects analysis.
* module/language/cps/slot-allocation.scm (compute-var-representations):
  The new ops define 'u64 values.
* module/language/cps/types.scm (uadd, usub, umul): Add type checkers
  and inferrers.
* module/system/vm/assembler.scm (emit-uadd, emit-usub, emit-umul): New
  assemblers.
2015-12-01 11:30:55 +01:00
Andy Wingo
07607f66b8 Add instructions to branch on u64 comparisons
* libguile/vm-engine.c (BR_U64_ARITHMETIC): New helper.
  (br-if-u64-=, br-if-u64-<, br-if-u64->=): New instructions.

* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm (*branching-primcall-arities*):
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm (u64-=, infer-u64-comparison-ranges):
  (define-u64-comparison-inferrer, u64-<, u64-<=, u64->=, u64->):
* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm (code-annotation):
  (compute-labels): Compiler and toolchain support for the new
  instructions.
2015-12-01 11:30:54 +01:00
Andy Wingo
87cc8b0f97 bv-f{32,64}-{ref,set!} take unboxed u64 index
* module/language/tree-il/compile-cps.scm (convert): bv-f32-ref,
  bv-f32-set!, bv-f64-ref, and bv-f64-set! take the index as an untagged
  u64 value.
* module/language/cps/types.scm (define-bytevector-uaccessors): New
  helper, used while migrating bytevectors to take unboxed indexes.
  Adapt f32/f64 accessors to use this definition helper.
* libguile/vm-engine.c (BV_FLOAT_REF, BV_FLOAT_SET): The index is
  unboxed.
2015-12-01 11:30:54 +01:00
Andy Wingo
8464cc576c Add bv-length instruction
* libguile/vm-engine.c (bv-length): New instruction.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm (bv-length):
* module/language/cps/primitives.scm (*instruction-aliases*):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/types.scm (bv-length):
* module/language/tree-il/compile-cps.scm (convert): Add support for
  bv-length.
* module/system/vm/assembler.scm: Export emit-bv-length.
2015-12-01 11:30:54 +01:00
Andy Wingo
dfbe869e24 Add low-level support for unboxed 64-bit unsigned ints
* libguile/frames.c (enum stack_item_representation)
* libguile/frames.c (scm_to_stack_item_representation):
  (scm_frame_local_ref, scm_frame_local_set_x): Support 'u64 slots.
* libguile/frames.h (union scm_vm_stack_element): Add as_u64 member.

* libguile/vm-engine.c (SP_REF_U64, SP_SET_U64): New helpers.
  (scm->u64, u64->scm): New instructions.

* module/language/cps/cse.scm (compute-equivalent-subexpressions):
  Scalar replacement for u64->scm and scm->u64.

* module/language/cps/effects-analysis.scm (scm->u64, u64->scm): Add
  cases.

* module/language/cps/slot-allocation.scm (compute-var-representations):
  (allocate-slots): Represent the result of scm->u64 as a "u64" slot.

* module/language/cps/types.scm (&u64): New type.
  (scm->u64, u64->scm): Add support for these ops.

* module/system/vm/assembler.scm (write-arities):
* module/system/vm/debug.scm (arity-definitions): Support u64
  representations.
2015-12-01 11:30:54 +01:00
Andy Wingo
3b3405e504 Apply of non-programs has IP that is not from prev frame
* libguile/vm-engine.c (vm_engine)
* libguile/vm.c (vm_apply_non_program_code): Arrange so that the code to
  apply a non-program has its own IP, so that frame-instruction-pointer
  for a non-program application doesn't point into the previously active
  frame.
2015-12-01 11:30:45 +01:00
Andy Wingo
d729a0dc75 Remove br-if-equal opcode
* libguile/vm-engine.c (br-if-equal): Remove opcode.
2015-11-12 21:23:09 +01:00
Andy Wingo
3b4941f3a9 Add fadd, fsub, fmul, fdiv instructions
* libguile/vm-engine.c (fadd, fsub, fmul, fdiv): New instructions.

* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm: Wire up support for new instructions.

* module/system/vm/assembler.scm: Export emit-fadd and friends.
2015-11-11 10:21:28 +01:00
Andy Wingo
b1ac8d68b5 bv-{f32,f64}-{ref,set!} operate on raw f64 values
* module/language/tree-il/compile-cps.scm (convert): Box results of
  bv-f32-ref and bv-f64-ref.  Unbox the argument to bv-f32-set! and
  bv-f64-set!.

* libguile/vm-engine.c (bv-f32-ref, bv-f64-ref): Results are raw.
  (bv-f32-set!, bv-f64-set!): Take unboxed arguments.

* module/system/vm/assembler.scm (emit-scm->f64, emit-f64->scm):
  Export.

* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm: Add support for scm->f64 and
  f64->scm.

* module/language/cps/slot-allocation.scm (compute-var-representations):
  Add cases for primops returning raw values.

* module/language/cps/types.scm (bv-f32-ref, bv-f32-set!)
  (bv-f64-ref, bv-f64-set!): Deal in &f64 values instead of reals.
2015-11-11 10:20:12 +01:00
Andy Wingo
5bbc47b06d Add VM ops to pack and unpack raw f64 values.
* libguile/vm-engine.c (scm->f64, f64->scm): New ops.
2015-10-28 17:58:30 +00:00
Andy Wingo
95855087ec Remove return opcode
* libguile/vm-engine.c (return): Remove opcode.
2015-10-28 13:11:40 +00:00
Andy Wingo
7aee3c74f5 return-values opcode resets the frame
* libguile/vm-engine.c (return-values): Change to also reset the frame,
  if nlocals is nonzero.

* doc/ref/vm.texi (Procedure Call and Return Instructions): Updated
  docs.

* module/language/cps/compile-bytecode.scm (compile-function): Adapt to
  call emit-return-values with the right number of arguments.
2015-10-28 10:47:18 +00:00
Andy Wingo
8832e8b68c Small subr-call refactor
* libguile/gsubr.c (scm_apply_subr): New internal helper.
* libguile/vm-engine.c (subr-call): Call out to scm_apply_subr.
* doc/ref/vm.texi (subr-call): Don't specify how the foreign pointer is
  obtained.
2015-10-22 12:13:37 +00:00
Andy Wingo
9144f50c31 subr-call implementation simplification
* libguile/vm-engine.c (subr-call): Reference args from SP, not FP.
2015-10-22 11:35:07 +00:00
Andy Wingo
70c317ab51 SP-relative local addressing
* libguile/vm-engine.c: S24/S12/S8 operands addressed relative to the
  SP, not the FP.  Cache the SP instead of a FP-relative locals
  pointer.  Further cleanups to follow.

* libguile/vm.c (vm_builtin_call_with_values_code): Adapt to mov operand
  addresing change.

* module/language/cps/compile-bytecode.scm (compile-function): Reify
  SP-relative local indexes where appropriate.

* module/system/vm/assembler.scm (emit-fmov*): New helper, exported as
  emit-fmov.
  (shuffling-assembler, define-shuffling-assembler): Rewrite to shuffle
  via push/pop/drop.
  (standard-prelude, opt-prelude, kw-prelude): No need to provide for
  shuffling args.

* test-suite/tests/rtl.test: Update.

* module/language/cps/slot-allocation.scm: Don't reserve slots 253-255.
2015-10-21 11:49:20 +02:00
Andy Wingo
0da0308b84 Prepare for SP-addressed locals
* libguile/vm-engine.c: Renumber opcodes, and take the opportunity to
  fold recent additions into more logical places.  Be more precise when
  describing the encoding of operands, to shuffle local references only
  and not constants, immediates, or other such values.
  (SP_REF, SP_SET): New helpers.
  (BR_BINARY, BR_ARITHMETIC): Take full 24-bit operands.  Our shuffle
  strategy is to emit push when needed to bring far locals near, then
  pop afterwards, shuffling away far destination values as needed; but
  that doesn't work for conditionals, unless we introduce a trampoline.
  Let's just do the simple thing for now.  Native compilation will use
  condition codes.
  (push, pop, drop): Back from the dead!  We'll only use these for
  temporary shuffling though, when an opcode can't address the full
  24-bit range.
  (long-fmov): New instruction, like long-mov but relative to the frame
  pointer.
  (load-typed-array, make-array): Don't use a compressed encoding so
  that we can avoid the shuffling case.  It would be a pain, given that
  they have so many operands already.

* module/language/bytecode.scm (compute-instruction-arity): Update for
  new instrution word encodings.

* module/system/vm/assembler.scm: Update to expose some opcodes
  directly, without the need for shuffling wrappers.  Adapt to
  instruction word encodings change.

* module/system/vm/disassembler.scm (disassembler): Adapt to instruction
  coding change.
2015-10-21 11:49:20 +02:00
Andy Wingo
8f027385db Rename union scm_vm_stack_element members
* libguile/frames.h (union scm_vm_stack_element): Rename members from
  scm, ip, etc to as_scm, as_ip, etc.  Adapt users.
2015-10-21 11:49:20 +02:00
Andy Wingo
aa9f6b0082 VM caches address of local 0 instead of FP
* libguile/vm-engine.c (vm_engine): Cache the address of local 0 instead
  of the FP.  This makes locals access a bit cheaper, but we still have
  to negate the index.  The right fix is to index relative to the SP
  instead.  That's a more involved change, so we punt until later.
2015-10-21 11:49:20 +02:00
Andy Wingo
0007507340 VM stack grows downward
Adapt VM stack to grow downward.  This will make native compilation look
more like the VM code, as we will be able to use native CALL
instructions, taking proper advantage of the return address buffer.

* libguile/continuations.c (scm_i_continuation_to_frame): Record offsets
  from stack top.

* libguile/control.c (scm_i_prompt_pop_abort_args_x): Adapt for reversed
  order of arguments, and instead of relying on the abort to push on the
  number of arguments, make the caller save the stack depth, which
  allows us to compute the number of arguments ourselves.
  (reify_partial_continuation, scm_c_abort): Adapt to reversed stack
  order.

* libguile/dynstack.c (scm_dynstack_wind_prompt): Since we wind the
  stack in a downward direction, subtract the reloc instead of adding
  it.

* libguile/dynstack.h (SCM_F_DYNSTACK_PROMPT_ESCAPE_ONLY): Remove flag;
  instead rely on prompt-establishing code to save the stack depth.

* libguile/eval.c (eval): Remove extraneous "volatile" declarations for
  variables that are not re-set between the setjmp and any longjmp.
  Adapt to save stack depth before instating the prompt.

* libguile/foreign.c (scm_i_foreign_call): Adapt to receive arguments in
  reverse order.

* libguile/frames.c (frame_stack_top, scm_i_frame_stack_top): Adapt to
  compute stack top instead of stack bottom.
  (scm_c_frame_closure): Adapt to stack growth change.
  (scm_frame_num_locals, scm_frame_local_ref, scm_frame_set_x): Use
  union data type to access stack.
  (RELOC): Reformat.
  (scm_c_frame_previous): Adapt to stack growth change.

* libguile/frames.h: Adapt stack diagram to indicate that the stack
  grows up.
  (union scm_vm_stack_element): New data type used to access items on
  the stack.
  (SCM_FRAME_PREVIOUS_SP)
  (SCM_FRAME_RETURN_ADDRESS, SCM_FRAME_SET_RETURN_ADDRESS)
  (SCM_FRAME_DYNAMIC_LINK, SCM_FRAME_SET_DYNAMIC_LINK)
  (SCM_FRAME_LOCAL, SCM_FRAME_NUM_LOCALS): Adapt to stack representation
  change.
  (SCM_FRAME_SLOT): New helper.
  (SCM_VM_FRAME_FP, SCM_VM_FRAME_SP): Adapt to stack growth change.

* libguile/stacks.c (scm_make_stack): Record offsets from top of stack.

* libguile/throw.c (catch): Adapt to scm_i_prompt_pop_abort_args_x
  change.

* libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME):
  (FRAME_LOCALS_COUNT_FROM): Adapt to stack growth change.
  (LOCAL_ADDRESS): Use SCM_FRAME_SLOT to get the address as the proper
  data type.
  (RETURN_ONE_VALUE, RETURN_VALUE_LIST): Adapt to stack growth change.
  (apply): Shuffling up the SMOB apply args can cause the stack to
  expand, so use ALLOC_FRAME instead of RESET_FRAME.
  (vm_engine): Adapt for stack growth change.

* libguile/vm.c (vm_increase_sp, vm_push_sp, vm_restore_sp): Adapt to
  stack representation change.
  (scm_i_vm_cont_to_frame): Adapt to take offsets from the top.
  (scm_i_vm_capture_stack): Adapt to capture from the top.
  (vm_return_to_continuation_inner): Adapt for data type changes.
  (vm_return_to_continuation): Likewise, and instead of looping, just
  splat the saved arguments on with memcpy.
  (vm_dispatch_hook): Adapt to receive arguments in the reverse order.
  Adapt callers.
  (vm_abort): There is never a tail argument.  Adapt to stack
  representation change.
  (vm_reinstate_partial_continuation)
  (vm_reinstate_partial_continuation_inner): Adapt to stack growth
  change.
  (allocate_stack, free_stack): Adapt to data type change.
  (expand_stack): Don't try to mremap(), as you can't grow a mapping
  from the bottom.  Without knowing that there's a free mapping space
  right below the old stack, which there usually isn't on Linux, we have
  to copy.  We can't use MAP_GROWSDOWN because Linux is buggy.
  (make_vm): Adapt to stack representation changes.
  (return_unused_stack_to_os): Round down instead of up, as the stack
  grows down.
  (scm_i_vm_mark_stack): Adapt to walk up the stack.
  (scm_i_vm_free_stack): Adapt to scm_vm changes.
  (vm_expand_stack_inner, reset_stack_limit, vm_expand_stack): Adapt to
  the stack growing down.
  (scm_call_n): Adapt to the stack growing down.  Don't allow argv to
  point into the stack.

* libguile/vm.h (struct scm_vm, struct scm_vm_cont): Adapt to hold the
  stack top and bottom.
2015-10-21 11:49:20 +02:00
Andy Wingo
bb051f2154 Fix write beyond stack boundary in vm-engine.c
* libguile/vm-engine.c (RETURN_ONE_VALUE, RETURN_VALUE_LIST): These
  helpers, used in subr-call and the like, might not actually have
  enough space to push the return values.  Use ALLOC_FRAME instead of
  RESET_FRAME, for that reason.
2015-06-05 00:34:05 +02:00
Andy Wingo
27b3b5b92d Add allocate-struct, struct-ref, struct-set! instructions
* libguile/vm-engine.c (allocate-struct, struct-ref, struct-set!): New
  instructions, to complement their "immediate" variants.

* module/language/cps/compile-bytecode.scm (compile-fun):
* module/system/vm/assembler.scm (system): Wire up the new instructions.
2015-01-22 12:53:33 +01:00
Andy Wingo
8c6206f319 Add br-if-logtest opcode
* libguile/vm-engine.c (br-if-logtest): New opcode.
* module/system/vm/disassembler.scm (code-annotation): Add branch
  annotation support.
2014-07-03 14:50:50 +02:00
Andy Wingo
f5cb70e94a Refactorings to apply-hook and push-continuation-hook
* libguile/vm-engine.c (vm_engine): Always invoke the apply hook after
  the ip has been reset.  Avoids problems in frame-bindings, which
  builds its bindings map based on the IP.  Invoke push-continuation
  before linking the new frame, so that more locals are available to the
  frame inspector.

* module/system/vm/traps.scm (trap-in-procedure): No need for a
  push-cont handler, as the apply handler will exit the frame.
2014-05-04 14:09:42 +02:00
Mark H Weaver
475772ea57 Merge branch 'stable-2.0'
Conflicts:
	GUILE-VERSION
	NEWS
	guile-readline/ice-9/readline.scm
	libguile/async.c
	libguile/backtrace.c
	libguile/deprecated.h
	libguile/gc-malloc.c
	libguile/gdbint.c
	libguile/init.c
	libguile/ioext.c
	libguile/mallocs.c
	libguile/print.c
	libguile/rw.c
	libguile/scmsigs.c
	libguile/script.c
	libguile/simpos.c
	libguile/snarf.h
	libguile/strports.c
	libguile/threads.c
	libguile/vm-i-scheme.c
	libguile/vm-i-system.c
	module/srfi/srfi-18.scm
	test-suite/Makefile.am
	test-suite/standalone/test-num2integral.c
2014-04-25 02:06:01 -04:00
Andy Wingo
d38ca16e2c Add make-vector opcode
* libguile/vm-engine.c (make-vector): New opcode.
* module/language/cps/compile-bytecode.scm (compile-fun):
* module/system/vm/assembler.scm (system): Support the new opcode.
  (*bytecode-minor-version*): Bump.

* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* test-suite/tests/compiler.test ("limits"): Add vector test.
2014-04-21 22:47:33 +02:00
Andy Wingo
c09708f985 VM opcodes only have <24-bit slot operands in the first word
* libguile/vm-engine.c (make-array): Change to only have
  restricted-width operands in the first word.  This instruction is
  currently unused, however.

* module/system/vm/assembler.scm (assembler):
* module/system/vm/disassembler.scm (disassembler): Disallow
  restricted-width operands in tail words.
2014-04-20 11:52:14 +02:00
Andy Wingo
73fc4e73e4 VM robustness for optimized closures
* libguile/vm.c (vm_error_unbound, vm_error_unbound_fluid): Remove proc
  argument.  The value in slot 0 is not necessarily the procedure being
  applied, after the prelude is done.

* libguile/vm-engine.c (vm_engine): Use LOCAL_REF (0) instead of
  SCM_FRAME_PROGRAM, and adapt to above changes.
2014-04-16 19:20:23 +02:00
Andy Wingo
b7ee9e086e Fix up some opcode metadata
* libguile/vm-engine.c (make-long-immediate, static-ref): Mark as "dst"
  instructions.
2014-04-16 12:51:34 +02:00
Andy Wingo
fcd3c8ccd3 Zero-offset branches are backward branches; fix "br" backward branches
* libguile/vm-engine.c (BR_UNARY, BR_BINARY, BR_ARITHMETIC): A jump with
  a zero offset is also a backward branch, in the sense that it's not a
  forward branch.
  ("br"): We forgot to VM_HANDLE_INTERRUPTS here on backwards branches.
  Oops!
2014-02-22 15:39:29 +01:00
Andy Wingo
698c55b04b assertion refactor in the vm
* libguile/vm.c:
* libguile/vm-engine.c: Change the one use of
  VM_ENABLE_PARANOID_ASSERTIONS to ASSERT.  That becomes the one use of
  VM_ENABLE_ASSERTIONS, so disable that too.
2014-02-20 19:57:47 +01:00
Andy Wingo
c2ae85beab VM never extends vp->sp beyond mapped region of stack
* libguile/vm-engine.c (ALLOC_FRAME): Fold CHECK_OVERFLOW into this
  routine, and rework to not extend vp->sp until the stack has been
  expanded.

* libguile/vm.c (vm_increase_sp): Likewise, don't extend vp->sp until
  the stack has expanded.
  (vm_expand_stack): Rework to take the new stack pointer as an
  argument, and also to update vp->sp_max_since_gc and vp->sp.
2014-02-20 10:17:51 +01:00
Andy Wingo
a32488ba13 SCM_I_IS_VECTOR only true for tc7_vector, not weak vectors
* libguile/tags.h (SCM_TYP7S, SCM_HAS_TYP7S): Remove these, as we no
  longer do the differs-by-one-bit thing for vectors and weak vectors.
* libguile/vectors.h (SCM_I_IS_VECTOR): Use SCM_HAS_TYP7.
  (SCM_I_IS_NONWEAK_VECTOR): Remove.
* libguile/vm-engine.c (vector-length, vector-ref, vector-set!)
  (vector-ref/immediate, vector-set!/immediate): We can inline these
  instructions completely now.

* libguile/vm.c (vm_error_not_a_vector, vm_error_out_of_range): New
  error conditions.
2014-02-08 17:19:52 +01:00
Andy Wingo
b914b236c3 Various VM stack management fixes
* libguile/vm.c (vm_increase_sp): New interface, to increase the SP to
  some new level, possibly expanding the stack.
  (vm_push_sp, vm_restore_sp): Intefaces to vm_increase_sp.
  (vm_return_to_continuation): Don't throw an error if there's not
  enough space; instead, expand.
  (vm_reinstate_partial_continuation): Use the new helper.
  (return_unused_stack_to_os): Avoid off-by-one error (sp points to
  valid memory.)
  (scm_call_n): Never write beyond the sp.
2014-02-05 22:52:00 +01:00
Andy Wingo
b3ae2b5068 Add VM and compiler support for calls to known procedures
* module/language/cps.scm ($callk): New expression type, for calls to
  known labels.  Part of "low CPS".
* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm: Adapt call sites.

* libguile/vm-engine.c (call-label, tail-call-label): New instructions.
  Renumber the rest; this is an ABI change.

* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.

* doc/ref/compiler.texi (CPS in Guile): Document $callk.
2014-02-02 23:19:22 +01:00
Andy Wingo
aef1fcf94e Add thread-local lock-free, TLS-free freelists.
* libguile/bdw-gc.h: Remove a needless compatibility hack.

* libguile/gc-inline.h: New file, implementing thread-local freelists
  providing faster allocation if we already have a scm_i_thread*
  pointer.  Based on gc_inline.h from libgc.

* libguile/threads.h (scm_i_thread): Add freelists here.
* libguile/threads.c (guilify_self_1, guilify_self_2): Initialize
  freelists.

* libguile/vm.c: Include gc-inline.h.
* libguile/vm-engine.c: Rename current_thread to thread.  Use
  scm_inline_cons instead of scm_cons, scm_inline_cell instead of
  scm_cell, and scm_inline_words instead of words.
2014-02-02 16:17:54 +01:00
Andy Wingo
7dba1c2ff1 Return unused parts of the stack to the OS
* libguile/vm.h (struct scm_vm): Reorder fields.  Add "sp_max_since_gc"
  field.
* libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME):
* libguile/vm.c (vm_return_to_continuation)
  (vm_reinstate_partial_continuation, scm_call_n): In places where we
  could increase the stack height, update sp_max_since_gc.
  (vm_expand_stack): Relocate sp_max_since_gc on expansion.
  (scm_bootstrap_vm): Record the page size using gnulib's getpagesize.
  (return_unused_stack_to_os): New routine, run when marking stacks.
2014-01-31 21:41:36 +01:00
Andy Wingo
024a60e374 Unnecessary VM_HANDLE_INTERRUPTS elision
* libguile/vm-engine.c: Remove VM_HANDLE_INTERRUPTS before entering a
  subr or foreign call.  The bytecode stub will have already done so
  when entering the stub, and the return sequence handles doing so
  before returning.
2014-01-28 21:56:54 +01:00
Andy Wingo
ddf0d7bb2e Fix more vm-engine comments
* libguile/vm-engine.c: Fix more comments.
2013-11-30 18:46:14 +01:00
Andy Wingo
2b6659e438 Remove slot-ref and slot-set! ops
* libguile/vm-engine.c: Remove slot-ref and slot-set! ops.
2013-11-30 18:46:14 +01:00
Andy Wingo
02f9d49614 Fix vm-engine.c comments
* libguile/vm-engine.c: Fix some comments.
2013-11-30 18:46:14 +01:00
Andy Wingo
f689dd6982 Remove the restore-continuation-hook.
* libguile/vm.h:
* libguile/vm.c:
* libguile/vm-engine.c:
* module/system/vm/traps.scm:
* module/system/vm/vm.scm: Remove the unused and redundant
  restore-continuation-hook.
2013-11-27 22:03:58 +01:00
Andy Wingo
4a1ce0169d VM copes with moving FP
* libguile/_scm.h (SCM_ASYNC_TICK_WITH_GUARD_CODE): New macro.
* libguile/vm-engine.c (VM_HANDLE_INTERRUPTS): Restore FP after
  ticking.
  (CACHE_FP): New macro.
  (CHECK_OVERFLOW): Use CACHE_FP.
  (BR_ARITHMETIC, RETURN_EXP, RETURN_ONE_VALUE, BINARY_INTEGER_OP):
  (call, return-values, subr-call, foreign-call)
  (resolve, define!, toplevel-box, module-box): Restore the FP from the
  vp where needed.
2013-11-22 18:44:33 +01:00
Andy Wingo
56280be983 Simplify state sync in VM before potential bailout.
* libguile/vm-engine.c (SYNC_IP): Remove calls to SYNC_BEFORE_GC, a
  no-op.  Replace SYNC_REGISTER / SYNC_ALL calls with just SYNC_IP.
2013-11-22 18:44:31 +01:00
Andy Wingo
d86682ba2c Add explicit nopcodes
* libguile/vm-engine.c (VM_NAME): Add explicit nopcodes, later to be
  interspersed with others.  This will allow us some extensibility
  without always shuffling around opcodes.  Also avoid lazy
  initialization; have the linker do it for us.

* libguile/instructions.c (parse_instruction):
  (scm_instruction_list): Rework instruction parsing to avoid using
  malloc.  It would seem that this would fix some GC issue -- but who
  knows!
2013-11-21 22:51:38 +01:00