summaryrefslogtreecommitdiff
path: root/module/system/vm/disassembler.scm
Commit message (Collapse)AuthorAgeFilesLines
* Remove unnecessary module imports.Ludovic Courtès2023-02-241-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These were found with: make GUILE_WARNINGS='-W1 -Wunused-module' * module/ice-9/copy-tree.scm: * module/ice-9/eval-string.scm: * module/ice-9/getopt-long.scm: * module/ice-9/poll.scm: * module/ice-9/popen.scm: * module/ice-9/sandbox.scm: * module/ice-9/threads.scm: * module/sxml/apply-templates.scm: * module/sxml/simple.scm: * module/system/base/types.scm: * module/system/repl/command.scm: * module/system/repl/common.scm: * module/system/repl/coop-server.scm: * module/system/repl/debug.scm: * module/system/repl/error-handling.scm: * module/system/repl/repl.scm: * module/system/repl/server.scm: * module/system/vm/assembler.scm: * module/system/vm/disassembler.scm: * module/system/vm/dwarf.scm: * module/system/vm/elf.scm: * module/system/vm/frame.scm: * module/system/vm/inspect.scm: * module/system/vm/linker.scm: * module/system/vm/program.scm: * module/system/vm/trace.scm: * module/system/vm/trap-state.scm: * module/system/vm/traps.scm: * module/system/xref.scm: * module/texinfo/indexing.scm: * module/texinfo/plain-text.scm: * module/texinfo/reflection.scm: * module/texinfo/string-utils.scm: * module/web/client.scm: * module/web/http.scm: * module/web/request.scm: * module/web/response.scm: Remove imports of unused modules.
* disassembler: Show intrinsic name for 'call-' instructions.Ludovic Courtès2022-11-011-1/+46
| | | | | | | * module/system/vm/disassembler.scm (code-annotation)[intrinsic-name]: New procedure. Add clauses for intrinsics. * NEWS: Update.
* CPS compiler reduces eq? on constant to eq-constant?Andy Wingo2020-08-031-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * module/language/cps/compile-bytecode.scm (compile-function): Expect eq-constant? instead of eq-null?, etc. * module/language/cps/effects-analysis.scm: Likewise. * module/language/cps/reify-primitives.scm (reify-primitives): For eq-constant?, reify a $const unless the constant is an immediate whose encoding fits in 16 bits. * module/language/cps/type-fold.scm (materialize-constant): Helper to make a constant from a type, min, and max. (fold-eq-constant?): New helper. (eq-constant?): New folder. (undefined?): Define specifically. (define-nullish-predicate-folder): Renamd from define-special-immediate-predicate-folder. Use only for null?, false, and nil?. (*branch-reducers*): New mechanism. Reduce eq? to eq-constant? if possible. (local-type-fold): Refactor to use materialize-constant, and to allow reducing branches. * module/language/cps/types.scm (constant-type): Return three values instead of a type entry. (constant-type-entry): New function that returns a type entry. Adapt callers. (infer-constant-comparison): New helper. (eq-constant?): New inferrer. (undefined?): New inferrer. * module/language/tree-il/compile-bytecode.scm (eq-constant?): Fix truncate-bits signed arg. (define-immediate-type-predicate): Adapt to visit-immediate-tags change. * module/language/tree-il/compile-cps.scm (convert): Convert eq? to constant to eq-constant?. Advantaged is that it gets fixnums and chars in addition to special immediates. * module/language/tree-il/cps-primitives.scm (define-immediate-type-predicate): Adapt to allow #f as pred. * module/system/base/types/internal.scm (immediate-tags): Use #f as pred for false, nil, etc. (immediate-bits->scm): Adapt. * module/system/vm/assembler.scm (emit-eq-null?, emit-eq-nil?) (emit-eq-false?, emit-eq-true?, emit-unspecified?, emit-eof-object?): Remove specialized emitters. * module/system/vm/assembler.scm (define-immediate-tag=?-macro-assembler): Allow for pred to be #f. * module/system/vm/disassembler.scm (define-immediate-tag-annotation): Adapt to pred being #f.
* Add eq-immediate? instructionAndy Wingo2020-08-031-1/+1
| | | | | | | | | | | * 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.
* Add sign-extending make-immediate instructionAndy Wingo2020-07-301-1/+11
| | | | | | | | | | | | | | | | | * 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.
* Add jtable instructionAndy Wingo2020-07-231-191/+203
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* bitvector-set-bit! / bitvector-clear-bit! replace bitvector-set!Andy Wingo2020-04-141-1/+1
| | | | | | | | | | | | | | | | | | | * NEWS: Add entry. * doc/ref/api-data.texi (Bit Vectors): Update. * libguile/array-handle.h (bitvector_set_x, scm_array_get_handle): Adapt to bitvector changes. * libguile/bitvectors.h: * libguile/bitvectors.c (scm_c_bitvector_set_bit_x) (scm_c_bitvector_clear_bit_x): New functions. * libguile/deprecated.h: * libguile/deprecated.c (scm_bitvector_set_x): Deprecate. * module/ice-9/sandbox.scm (mutable-bitvector-bindings): Replace bitvector-set! with bitvector-set-bit! / bitvector-clear-bit!. * module/system/vm/disassembler.scm (static-opcode-set): Use bitvector-set-bit!. * module/system/vm/frame.scm (compute-defs-by-slot, available-bindings): Use bitvector-set-bit!. * test-suite/tests/bitvectors.test: Update.
* bitvector-bit-set? / bitvector-bit-clear? replace bitvector-refAndy Wingo2020-04-141-1/+1
| | | | | | | | | | | | | | | | | | | | | This is an opportunity to make a new interface that can be more efficient in 3.0 (because no generic array support), easier to read (no need for 'not'), and more consistent with other bitvector interfaces. * NEWS: Add entry. * doc/ref/api-data.texi (Bit Vectors): Update. * libguile/array-handle.h (bitvector_ref, scm_array_get_handle): Adapt to bitvector changes. * libguile/bitvectors.h: * libguile/bitvectors.c (scm_c_bitvector_bit_is_set) (scm_c_bitvector_bit_is_clear): New functions. * libguile/deprecated.h: * libguile/deprecated.c (scm_bitvector_ref): Deprecate. * module/ice-9/sandbox.scm (bitvector-bindings): Replace bitvector-ref with bitvector-bit-set? / bitvector-bit-clear?. * module/system/vm/disassembler.scm (instruction-has-fallthrough): Use bitvector-bit-clear?. * test-suite/tests/bitvectors.test: Update.
* Have disassemble-file accept an optional output portDaniel Llorens2019-08-291-2/+2
| | | | * module/system/vm/disassembler.scm (disassemble-file): As stated.
* Add bind-optionals instructionAndy Wingo2019-06-061-2/+4
| | | | | | | | | | | * 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.
* Rework VM approach to shuffling unknown numbers of argsAndy Wingo2018-07-201-18/+9
| | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Reserve frame word for machine return addressAndy Wingo2018-07-201-1/+1
| | | | | | | | | | | | | | | | | | | | * libguile/frames.h: Add machine return address to diagram. (SCM_FRAME_MACHINE_RETURN_ADDRESS): (SCM_FRAME_SET_MACHINE_RETURN_ADDRESS): New macros. (SCM_FRAME_PREVIOUS_SP): (SCM_FRAME_DYNAMIC_LINK): (SCM_FRAME_SET_DYNAMIC_LINK): Adapt for new frame size. * libguile/vm-engine.c (halt): Set frame size to 3. (call, call-label): Set mRA to 0. * libguile/vm.c (push_interrupt_frame, reinstate_continuation_x): (scm_call_n): Set frame size to 3. In push_interrupt_frame, init the mRA of the frame. (vm_builtin_call_with_values_code, vm_handle_interrupt_code): Allocate larger frames. * module/language/cps/slot-allocation.scm (allocate-slots): Frame size is 3. * module/system/vm/disassembler.scm (define-clobber-parser): Bump frame size.
* Prepare for frames having separate virtual and machine return addrsAndy Wingo2018-07-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/frames.c (scm_frame_return_address): Use SCM_FRAME_VIRTUAL_RETURN_ADDRESS. (scm_c_frame_previous): Likewise. * libguile/frames.h: Update diagram for new names. (union scm_vm_stack_element): Rename "as_ip" to "as_vcode", and add "as_mcode" for machine code pointers. (SCM_FRAME_VIRTUAL_RETURN_ADDRESS) (SCM_FRAME_SET_VIRTUAL_RETURN_ADDRESS): Rename to these, from SCM_FRAME_RETURN_ADDRESS and SCM_FRAME_SET_RETURN_ADDRESS. * libguile/vm-engine.c (halt, call, call-label, return-values) (return-from-interrupt): Adapt to renamings. Make "halt" have frame size as a parameter. * libguile/vm.c (scm_i_vm_mark_stack): Adapt to renaming. (push_interrupt_frame): Take mRA as additional argument. In future we will set it as frame mRA. (capture_continuation): Adapt to renaming. (scm_call_n): Adapt to renaming and make frame size adjustable. (push_interrupt_frame, reinstate_continuation_x): Make frame size adjustable. * module/language/cps/slot-allocation.scm (allocate-slots): Make frame size adjustable. * libguile/intrinsics.h (scm_t_thread_mra_intrinsic): New type; use for push_interrupt_frame. (scm_t_thread_u8_scm_sp_vra_intrinsic): Rename from the same but was "ra" instead of "vra", and change type to uint32_t*. * module/system/vm/disassembler.scm (define-clobber-parser): Parameterize clobber set for calls by frame size.
* Remove backend support for cached-module-box et al.Andy Wingo2018-05-141-22/+0
| | | | | | | | | | | | | | | | | * 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.
* Explode atomic box ops to new atomic instructionsAndy Wingo2018-04-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Add load-label instructionAndy Wingo2018-04-101-0/+9
| | | | | | | * 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.
* Remove free-ref, free-set!Andy Wingo2018-01-221-2/+0
| | | | | | | | | * libguile/vm-engine.c (free-ref, free-set!): Remove ops. * module/language/cps/effects-analysis.scm: * module/system/vm/assembler.scm: * module/system/vm/disassembler.scm (code-annotation): * module/language/cps/compile-bytecode.scm (compile-function): Remove support for free-ref / free-set!.
* Add CPS compilation support for mutable-vector?Andy Wingo2018-01-071-1/+2
| | | | | | | * module/system/base/types/internal.scm (heap-tags): Add immutable-vector? and mutable-vector?. * module/language/tree-il/cps-primitives.scm: * module/system/vm/disassembler.scm: Bump copyright lines.
* Fix stack effect/clobber parsing for callsAndy Wingo2017-12-271-5/+7
| | | | | | | | | * module/system/vm/disassembler.scm (define-stack-effect-parser) (define-clobber-parser): * module/system/vm/frame.scm (compute-frame-sizes, compute-killv): Fix bug introduced in dd8bf6a98cfd852c4a6981337eb0df11dd427415 whereby a call would clobber all locals, leaving the backtrace much less useful than it should be.
* Re-mark "throw" et al as not having fallthroughAndy Wingo2017-12-061-0/+1
| | | | | | | * module/system/vm/disassembler.scm (instruction-has-fallthrough?): Re-add throw, etc. * module/system/vm/frame.scm (compute-frame-sizes, compute-killv): Allow for unreachable code.
* Mark throw, throw/value, etc as having fallthroughAndy Wingo2017-12-021-1/+6
| | | | | | * module/system/vm/disassembler.scm (instruction-has-fallthrough?): Mark throw and so on as having fallthrough. Doing otherwise breaks backtraces.
* Add support for comparisons against integer immediatesAndy Wingo2017-11-151-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/vm-engine.c (s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?) (imm-s64<?): New instructions. * libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add new X8_S12_Z12 word type used by the new S64/immediate instructions. A Z12 is a 12-bit signed integer immediate. * module/system/vm/assembler.scm: Export new instructions, and add X8_S12_Z12 support. Also, add missing shufflers for X8_S12_C12. * module/language/bytecode.scm (compute-instruction-arity): * module/system/vm/disassembler.scm (unpack-s12, disassembler): Add support for X8_S12_Z12. * module/language/cps/types.scm (define-predicate-inferrer/param): New helper. (u64-=, u64-<, s64-<): Remove type checkers; this procedure does not cause &type-check. (u64-imm=?, s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?, imm-s64<?): New type inferrers. * module/language/cps/type-fold.scm (define-unary-branch-folder*): New helper. (u64-imm=?, s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?, imm-s64<?): New branch folders. * module/language/cps/reify-primitives.scm (reify-primitives): Reify constants for new immediate branching primcalls if values out of range. * module/language/cps/effects-analysis.scm: Add support for new primcalls. * module/language/cps/compile-bytecode.scm (compile-function): Add support for new primcalls and instructions. Compile u64-imm-= to s64-imm=?.
* Add new "throw" VM opsAndy Wingo2017-11-051-0/+3
| | | | | | | | | | | | | | | | | | | | | * libguile/throw.h (scm_ithrow, scm_throw): Mark as SCM_NORETURN. * libguile/throw.c (scm_throw, scm_ithrow): Adapt to not return. * libguile/vm-engine.c (throw, throw/value, throw/value+data): New instructions. * libguile/vm.c (vm_throw, vm_throw_with_value) (vm_throw_with_value_and_data): New helpers. * module/language/cps/compile-bytecode.scm (compile-function): Add cases for new instructions. * module/language/cps/prune-bailouts.scm (prune-bailouts): More simple, now that there are no $kreceives in play. * module/language/cps/reify-primitives.scm (reify-clause): Update reification of no-clause functions to use new throw op. * module/language/tree-il/compile-cps.scm (convert): Convert invocations of the variable-arity 'throw primitive from Tree-IL to the new fixed-arity CPS instructions. * module/system/vm/assembler.scm (emit-throw/value*) (emit-throw/value+data*, emit-throw): Export new instructions. * module/system/vm/disassembler.scm (code-annotation): Add annotation.
* Remove disassembler support for old-style jump instructionsAndy Wingo2017-10-301-38/+2
| | | | | | * module/system/vm/disassembler.scm (code-annotation, compute-labels) (instruction-has-fallthrough?, define-jump-parser): Remove disassembler support for old-style jump instructions.
* Use tag visitors to generate assemblers, disassembly annotationsAndy Wingo2017-10-291-49/+11
| | | | | | | | | * module/system/vm/disassembler.scm (immediate-tag-annotations) (heap-tag-annotations): Generate using tag visitors. * module/system/vm/assembler.scm (define-immediate-tag=?-macro-assembler) (define-heap-tag=?-macro-assembler): New helpers. Use these to generate immediate-tag=? and heap-tag=? macro assemblers.
* Refactor (system base types internal) to use more macrosAndy Wingo2017-10-291-7/+7
| | | | | | | | | | | | | | | | | | | | | | * module/system/base/types/internal.scm (visit-immediate-tags) (visit-heap-tags): New helpers. * module/system/base/types/internal.scm (define-tags, define-tag): New helpers. (immediate-tags, heap-tags): Use define-tags to define all of the tag values. For consistency some names are changed: (%tc2-fixnum): Renamed from %tc2-inum. (%tc8-flag): Removed. (%tc16-null): Renamed from %tc16-eol. (%tc7-weak-vector): Renamed from %tc7-wvect. (%tc7-hash-table): Renamed from %tc7-hashtable. (%tc7-flonum): Renamed from %tc7-real. (visit-heap-tags, visit-immediate-tags): New exports. * module/system/base/types.scm (cell->object): Adapt to renamings. (match-bit-pattern): Add a case to match immediate SCM bits literally. (scm->object): Adapt to use the special immediate values directly. * module/system/vm/disassembler.scm (immediate-tag-annotations): (heap-tag-annotations): Adapt to new names.
* Add assembler and disassembler support for new instructionsAndy Wingo2017-10-251-3/+62
| | | | | | | | | | * module/system/vm/assembler.scm: Export assemblers for the new instructions. * module/system/vm/disassembler.scm (immediate-tag-annotations) (heap-tag-annotations, code-annotation): Add support for disassembling the new instructions, with good annotations. (compute-labels, instruction-has-fallthrough?, define-jump-parser): Add support for new branching instructions.
* Add support for C16_C16 instruction wordsAndy Wingo2017-10-241-1/+4
| | | | | | | * module/language/bytecode.scm (compute-instruction-arity): * module/system/vm/assembler.scm (pack-u16-u16, expand): * module/system/vm/disassembler.scm (disassembler): * libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add C16_C16.
* Add disjoint syntax object typeAndy Wingo2017-03-281-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/Makefile.am (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES): (DOT_X_FILES, DOT_DOC_FILES, noinst_HEADERS): Add syntax.c and syntax.h. * libguile/evalext.c (scm_self_evaluating_p): * libguile/goops.c (class_syntax, scm_class_of, scm_goops_early_init): * libguile/init.c (scm_init_guile): * libguile/print.c (iprin1): * libguile/tags.h (scm_tc7_syntax): * module/oop/goops.scm (<syntax>): * module/system/base/types.scm (%tc7-syntax, cell->object): * module/system/vm/disassembler.scm (code-annotation): Wire up the new data type. * libguile/syntax.c: * libguile/syntax.h: New files. * module/ice-9/boot-9.scm: Move new definitions to (system syntax internal). * module/system/syntax.scm (print-syntax): New helper. * module/system/vm/assembler.scm (statically-allocatable?) (intern-constant, link-data): Arrange to be able to write syntax objects into images. * module/language/cps/types.scm (&syntax): New type. Remove &hash-table; it was never detected, an internal binding, and we need the bit to avoid going into bignum territory.
* Add unboxed floating point comparison instructions.David Thompson2017-01-121-0/+2
| | | | | | | | | | | | | | | | | | | | * libguile/vm-engine.c (BR_F64_ARITHMETIC): New preprocessor macro. (br_if_f64_ee, br_if_f64_lt, br_if_f64_le, br_if_f64_gt, br_if_f64_ge): New VM instructions. * doc/ref/vm.texi ("Unboxed Floating-Point Arithmetic"): Document them. * module/language/cps/compile-bytecode.scm (compile-function): Emit f64 comparison instructions. * module/language/cps/effects-analysis.scm: Define effects for f64 primcalls. * module/language/cps/primitives.scm (*branching-primcall-arities*): Add arities for f64 primcalls. * module/language/cps/specialize-numbers.scm (specialize-f64-comparison): New procedure. (specialize-operations): Specialize f64 comparisons. * module/system/vm/assembler.scm (emit-br-if-f64-=, emit-br-if-f64-<) (emit-br-if-f64-<=, emit-br-if-f64->, emit-br-if-f64->=): Export. * module/system/vm/disassembler.scm (code-annotation): Add annotations for f64 comparison instructions.
* Add support for comparing u64 values with SCM valuesAndy Wingo2015-12-031-1/+5
| | | | | | | | | | | | | | | | | | | | | * libguile/vm-engine.c (BR_U64_SCM_COMPARISON): New helper. (br-if-u64-<=-scm, br-if-u64-<-scm, br-if-u64-=-scm) (br-if-u64->-scm, br-if-u64->=-scm): New instructions, to compare an untagged u64 with a tagged SCM. Avoids many u64->scm operations. * module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/effects-analysis.scm: * module/language/cps/type-fold.scm: * module/system/vm/assembler.scm: * module/system/vm/disassembler.scm (code-annotation, compute-labels): * module/language/cps/primitives.scm (*branching-primcall-arities*): Add support for new opcodes. * module/language/cps/specialize-numbers.scm (specialize-u64-scm-comparison): New helper. * module/language/cps/specialize-numbers.scm (specialize-operations): Specialize u64 comparisons. * module/language/cps/types.scm (true-comparison-restrictions): New helper. (define-comparison-inferrer): Use the new helper. Add support for u64-<-scm et al.
* Untag values and indexes for all bytevector instructionsAndy Wingo2015-12-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* New instructions load-f64, load-u64Andy Wingo2015-12-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Add instructions to branch on u64 comparisonsAndy Wingo2015-12-011-1/+3
| | | | | | | | | | | | | | | | * 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.
* Don't compile equal? to br-if-equalAndy Wingo2015-11-121-2/+2
| | | | | | | | | | | | | | | * module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/primitives.scm (*branching-primcall-arities*): * module/language/cps/type-fold.scm (equal?): * module/language/cps/types.scm (equal?): * module/language/tree-il/compile-cps.scm (convert): `equal?' is no longer a branching primcall, because it isn't inline. The implementation could lead to bad backtraces also, as it didn't save the IP, and actually could lead to segfaults as it didn't reload the SP after the return. There is an eqv? fast-path, though. * module/system/vm/assembler.scm (br-if-equal): Remove interface. * module/system/vm/disassembler.scm (code-annotation): (compute-labels): No need to handle br-if-equal.
* Remove use of return in disassembler.scmAndy Wingo2015-10-281-1/+1
| | | | | * module/system/vm/disassembler.scm (instruction-has-fallthrough?): Remove return from static opcode set.
* Always emit return-valuesAndy Wingo2015-10-281-0/+4
| | | | | | | | | | | | | * module/language/cps/compile-bytecode.scm (compile-function): Remove special cases for nullary and unary returns; instead always use return-values and rely on hinting to try to place values in the right slot already. * module/system/vm/assembler.scm (emit-init-constants): Use return-values. * module/system/vm/disassembler.scm (code-annotation): Add annotation for return-values.
* Update VM documentation for new stack layoutAndy Wingo2015-10-221-1/+7
| | | | | | | * doc/ref/vm.texi: Update for new stack layout. * module/system/vm/disassembler.scm (code-annotation): Print the frame sizes after alloc-frame, reset-frame, etc to make reading the disassembly easier.
* Add stack size computation to disassemblerAndy Wingo2015-10-211-8/+70
| | | | | | | | | | | | | | * module/system/vm/disassembler.scm (define-stack-effect-parser) (stack-effect-parsers, instruction-stack-size-after): New stack size facility. (define-clobber-parser, clobber-parsers, instruction-slot-clobbers): Take incoming and outgoing stack sizes as arguments to interpret SP-relative clobbers. * module/system/vm/frame.scm (compute-frame-sizes): New helper that computes frame sizes for each position in a function. (compute-killv): Adapt to compute the clobbered set given the computed frame sizes.
* Prepare for SP-addressed localsAndy Wingo2015-10-211-40/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Keywords have a tc7Andy Wingo2015-01-221-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/tags.h (scm_tc7_keyword): Allocate a tc7, so that the VM can have cheap keyword? tests. * libguile/keywords.c: * libguile/keywords.h: Adapt. * libguile/goops.c (scm_class_of, scm_sys_goops_early_init): Capture <keyword>. * libguile/print.c (iprin1): Inline keyword printer. * libguile/evalext.c (scm_self_evaluating_p): Add keywords here. * libguile/deprecated.h: * libguile/deprecated.c (scm_tc16_keyword): Deprecate. * module/language/cps/compile-bytecode.scm (compile-fun): Add keyword? case, and bitvector? case while we're at it. * module/language/cps/effects-analysis.scm (define-primitive-effects): Add bytevector?, keyword?, and bitvector? cases. * module/language/cps/primitives.scm (*branching-primcall-arities*): Add keyword?. * module/language/cps/types.scm (bitvector?, keyword?, bytevector?): Add branch inferrers. * module/language/tree-il/primitives.scm (*interesting-primitive-names*): (*effect-free-primitives*): (*effect+exception-free-primitives*): Add bytevector?, keyword?, and bitvector?. * module/oop/goops.scm (<keyword>): New class. * module/system/base/types.scm (%tc7-keyword, cell->object): Add cases. * module/system/vm/assembler.scm (br-if-keyword): New definition. * module/system/vm/disassembler.scm (code-annotation): Add br-if-tc7 case for keywords. * test-suite/tests/types.test ("clonable objects"): Update now that keywords are cloneable.
* Compiler emits br-if-logtestAndy Wingo2014-07-031-1/+1
| | | | | | | | | | * module/language/cps/compile-bytecode.scm (compile-fun): * module/language/cps/primitives.scm (*branching-primcall-arities*): * module/language/cps/type-fold.scm (logtest): * module/language/cps/types.scm (logtest): * module/system/vm/assembler.scm (system): * module/system/vm/disassembler.scm (compute-labels): Add backend support for the logtest instruction.
* Add br-if-logtest opcodeAndy Wingo2014-07-031-1/+2
| | | | | | * libguile/vm-engine.c (br-if-logtest): New opcode. * module/system/vm/disassembler.scm (code-annotation): Add branch annotation support.
* VM opcodes only have <24-bit slot operands in the first wordAndy Wingo2014-04-201-16/+0
| | | | | | | | | | * 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.
* Add parsing interfaces to the disassemblerAndy Wingo2014-04-161-1/+116
| | | | | | | * module/system/vm/disassembler.scm (instruction-length): (instruction-has-fallthrough?, instruction-relative-jump-targets): (instruction-slot-clobbers): New interfaces; to be used when determining the bindings available at a given point of a procedure.
* Improve disassembly for optimized closuresAndy Wingo2014-04-131-4/+19
| | | | | | | * module/system/vm/disassembler.scm (code-annotation): Add call-label and tail-call-label cases. (disassemble-addr): With call-label we can see sets of mutually recursive functions, so keep a global "visited?" set.
* Rename "RTL" to "bytecode"Andy Wingo2013-12-021-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "RTL" didn't make any sense, and now that there's no other bytecode to disambiguate against, just call it bytecode. * module/Makefile.am: * module/ice-9/eval-string.scm: * module/language/bytecode.scm: * module/language/bytecode/spec.scm: * module/language/cps/arities.scm: * module/language/cps/compile-bytecode.scm: * module/language/cps/compile-rtl.scm: * module/language/cps/contification.scm: * module/language/cps/elide-values.scm: * module/language/cps/primitives.scm: * module/language/cps/reify-primitives.scm: * module/language/cps/spec.scm: * module/language/cps/specialize-primcalls.scm: * module/language/rtl.scm: * module/language/rtl/spec.scm: * module/scripts/compile.scm: * module/system/base/compile.scm: * module/system/repl/common.scm: * module/system/vm/assembler.scm: * module/system/vm/debug.scm: * module/system/vm/disassembler.scm: * module/system/vm/dwarf.scm: * test-suite/tests/cross-compilation.test: * test-suite/tests/dwarf.test: * test-suite/tests/rtl-compilation.test: * test-suite/tests/rtl.test: * test-suite/vm/run-vm-tests.scm: Fixups.
* Unknown files print as (unknown file) in disassemblerAndy Wingo2013-11-301-1/+1
| | | | | * module/system/vm/disassembler.scm (disassemble-buffer): Print unknown files as "(unknown file)".
* ,x disassembles nested programs tooAndy Wingo2013-11-301-21/+38
| | | | | | | * module/system/vm/disassembler.scm (code-annotation): (disassemble-buffer, disassemble-addr, disassemble-program): Arrange to disassemble nested procedures. (disassemble-image): Adapt.
* Rename objcodes?.{scm,c,h} to loader.{scm,c,h}Andy Wingo2013-11-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | * libguile/loader.c: * libguile/loader.h: Rename from objcodes.[ch]. * module/system/vm/loader.scm: Rename from objcode.scm. * libguile/Makefile.am: * libguile/gsubr.c: * libguile/init.c: * libguile/procs.c: * libguile/vm.c: * module/Makefile.am: * module/ice-9/eval-string.scm: * module/language/rtl/spec.scm: * module/system/base/target.scm: * module/system/repl/command.scm: * module/system/repl/common.scm: * module/system/vm/debug.scm: * module/system/vm/disassembler.scm: * module/system/vm/objcode.scm: * test-suite/tests/compiler.test: * test-suite/tests/dwarf.test: * test-suite/tests/rtl-compilation.test: * test-suite/tests/rtl.test: Adapt.