summaryrefslogtreecommitdiff
path: root/module/language/cps/specialize-numbers.scm
Commit message (Collapse)AuthorAgeFilesLines
* Fix fixpoint computation in compute-significant-bitsAndy Wingo2020-03-231-2/+23
| | | | | | | | * module/language/cps/specialize-numbers.scm (preserve-eq?): New helper. (sigbits-union): Use the new helper. Fixes bugs.gnu.org/38486. Thanks to Zack Marvel for the bug report and Matt Wette for tracking it down.
* Optimize fixnum or s64 -> f64 conversionsAndy Wingo2019-09-011-1/+8
| | | | | | | | | | | | | | | | | | | | | * 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.
* Unbox floor/ceiling and trigonometric functions where possibleAndy Wingo2019-08-241-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Add support for optimized unboxed abs and sqrtAndy Wingo2019-08-041-0/+6
| | | | | | | | | | | | | | | | | | | | | 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.
* Add support no closure in $callkAndy Wingo2019-06-071-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | * module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/contification.scm (compute-contification-candidates): * module/language/cps/cse.scm (apply-cse): * module/language/cps/dce.scm (compute-live-code): * module/language/cps/devirtualize-integers.scm (compute-use-counts): * module/language/cps/peel-loops.scm (rename-cont): * module/language/cps/renumber.scm (renumber): * module/language/cps/rotate-loops.scm (rotate-loop): * module/language/cps/simplify.scm (compute-singly-referenced-vars): (beta-reduce): * module/language/cps/slot-allocation.scm (compute-defs-and-uses): (compute-lazy-vars): (compute-shuffles): (compute-frame-size): (allocate-lazy-vars): (allocate-slots): * module/language/cps/specialize-numbers.scm (compute-significant-bits): * module/language/cps/verify.scm (check-valid-var-uses): Allow for the $callk proc to be #f. * module/language/cps/compile-bytecode.scm (compile-function): Reset frame to appropriate size.
* Add compiler support for eliding closure bindingsAndy Wingo2019-06-071-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Rename $closure to $const-funAndy Wingo2018-10-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | * module/language/cps.scm ($const-fun): Rename from $closure, as we always use this now with nfree == 0. * module/language/cps/closure-conversion.scm: * module/language/cps/compile-bytecode.scm: * 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/slot-allocation.scm: * module/language/cps/specialize-numbers.scm: * module/language/cps/types.scm: * module/language/cps/utils.scm: * module/language/cps/verify.scm: Adapt users.
* Add $code CPS expression typeAndy Wingo2018-04-101-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* $throw is a new kind of CPS termAndy Wingo2018-01-031-1/+3
| | | | | | * module/language/cps.scm ($throw): New term type that doesn't have a continuation. Adapt all callers. Remove now-unneeded "prune-bailouts" pass.
* $prompt is now its own kind of CPS term.Andy Wingo2018-01-031-4/+4
| | | | | | * module/language/cps.scm ($prompt): Rework to be its own term kind. Now $continue always continues to a single continuation. Adapt callers.
* $branch is now a distinct CPS term typeAndy Wingo2018-01-031-70/+50
| | | | | | | * module/language/cps.scm ($branch): Refactor to be its own CPS term type, not relying on $continue to specify a continuation (which before was only for the false case) or a source location. Update allllllll callers.
* Fix NaN handling in <= and >=Andy Wingo2017-12-021-0/+11
| | | | | | | | | | | | | | | * module/language/cps/compile-bytecode.scm (compile-function): Add support for emitting <= via < and jge / jnge. * module/language/cps/effects-analysis.scm: Declare effects for <= and f64-<=. * module/language/cps/primitives.scm (*comparisons*): Add <=, f64-<=. * module/language/cps/specialize-numbers.scm (specialize-operations): Specialize <= to < for integer comparisons. Specialize to f64-<= for f64 ops. * module/language/cps/type-fold.scm (<=): Add folder. * module/language/cps/types.scm (infer-<=): Add inferrer. * module/language/tree-il/compile-cps.scm (canonicalize): Canonicalize <= and >= to <=, so that nans are handled correctly.
* Refactor number specialization to reduce duplicationAndy Wingo2017-12-021-255/+209
| | | | | * module/language/cps/specialize-numbers.scm (specialize-operations): Factor out specialize-primcall and specialize-branch operations.
* Enable lsh/immediate, rsh/immediate specializationAndy Wingo2017-11-281-6/+6
| | | | | | | * module/language/cps/specialize-numbers.scm (specialize-operations): Fix typo in match syntax preventing us from optimizing the immediate variants of lsh and rsh, and typo also in specialize-unop argument order.
* Better unboxing for logand over s64 valuesAndy Wingo2017-11-241-0/+20
| | | | | | * module/language/cps/specialize-numbers.scm (specialize-operations): Do a better job unboxing logand if we know the result is a u64, even if arguments are s64.
* Specialize fixnum and s64 phisAndy Wingo2017-11-241-12/+57
| | | | | | | | * module/language/cps/specialize-numbers.scm (compute-specializable-fixnum-vars, compute-specializable-s64-vars): * module/language/cps/specialize-numbers.scm (compute-specializable-phis): (apply-specialization): Re-enable specialization of fixnum phis and also s64 phis.
* Specialize-numbers reifies instructions that type-checkAndy Wingo2017-11-201-378/+303
| | | | | | | | | | | * module/language/cps/specialize-numbers.scm (specialize-operations): Before, this pass would reify e.g. uadd for an addition of s64 values if it could prove that the result would be within the s64 range. But this is really confusing if later we want to do range analysis over the result. Additionally it would sometimes reify diamond control patterns that weren't really amenable to CSE. So instead we now reify instructions that can pass type checks, like "sadd" instead of "uadd".
* Revert specialization of fixnum phi variablesAndy Wingo2017-11-201-36/+5
| | | | | | | | * module/language/cps/specialize-numbers.scm (compute-specializable-fixnum-vars, compute-specializable-phis) (apply-specialization): Don't specialize phis as fixnums. Need to try again with some proper range analysis, as a variable defined with tag-fixnum can indicate either a u64 or a s64.
* ursh, ursh/immediate, etc only residualized if count < 64Andy Wingo2017-11-151-1/+3
| | | | | | | | | | | | | | * module/language/cps/reify-primitives.scm (reify-primitives): Remove cases for ursh/immediate etc, as these should all be within range, by construction. * module/language/cps/specialize-numbers.scm (specialize-operations): Only reify ursh/immediate, etc if the shift count is less than 64. * module/language/cps/specialize-primcalls.scm (specialize-primcalls): Remove specialization cases for ursh/immediate etc; this is the domain of specialize-numbers. * module/language/cps/types.scm (ursh, srsh, ulsh): Limit arguments to be less than 63. (ulsh/immediate): Assume parameter is in range.
* Compiler specializes comparisons to immediate integersAndy Wingo2017-11-151-49/+141
| | | | | | | | | | | * module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/effects-analysis.scm (load-const/unlikely): * module/language/cps/types.scm (load-const/unlikely): * module/language/cps/primitives.scm (*macro-instruction-arities*): Add new primcall, load-const/unlikely. * module/language/cps/specialize-numbers.scm: Rework comparison specialization. Add support for specializing comparisons against integer immediates.
* Add support for comparisons against integer immediatesAndy Wingo2017-11-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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=?.
* Better untagging of fixnumsAndy Wingo2017-11-131-163/+313
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * module/language/cps/compile-bytecode.scm (compile-function): Add support for tag-fixnum/unlikely. * module/language/cps/cse.scm (compute-equivalent-subexpressions): Add equivalent subexpressions for tag-fixnum. * module/language/cps/effects-analysis.scm: * module/language/cps/primitives.scm (*macro-instruction-arities*): Add tag-fixnum/unlikely. * module/language/cps/specialize-numbers.scm (specialize-u64-unop) (specialize-u64-binop, specialize-u64-shift) (specialize-u64-comparison): Make the arg unboxers and result boxers into keyword arguments. (specialize-s64-unop): New helper. (specialize-fixnum-comparison, specialize-fixnum-scm-comparison) (specialize-scm-fixnum-comparison): Rename from specialize-s64-comparison et al. Perhaps this should be expanded again to include the whole s64 range, once we start to expand scm->s64 et al. (specialize-operations): Specialize arithmetic, etc on signed operands and results. Use less powerful unboxing/boxing ops if possible -- e.g. tag-fixnum instead of u64->scm. Prefer fixnum comparisons over u64 comparisons. (compute-specializable-fixnum-vars): New helper. (compute-specializable-phis): Specialize fixnum phis as well. (specialize-primcalls): Specialize untag-fixnum of a constant to load-s64. * module/language/cps/type-fold.scm (u64->scm, s64->scm): (scm->s64, scm->u64): Reduce to fixnum ops where possible. * module/language/cps/types.scm: Remove type checkers for ops that don't throw type errors. Alias tag-fixnum/unlikely to tag-fixnum.
* Specialize rsh/lsh, not ashAndy Wingo2017-11-111-40/+7
| | | | | * module/language/cps/specialize-numbers.scm (specialize-operations): Replace "ash" specializer with "rsh"/"lsh" specializer.
* Specialize comparisons to SCM as s64Andy Wingo2017-11-111-46/+57
| | | | | | | | | | | * module/language/cps/specialize-numbers.scm (specialize-s64-comparison) (specialize-s64-scm-comparison, specialize-scm-s64-comparison): New helpers. (specialize-scm-u64-comparison, specialize-u64-scm-comparison): Remove. Comparing SCM as s64 is better as fixnums are a subset of s64, not u64. (specialize-operations): Prefer s64 comparisons when we can't specialize both arguments; this at least inlines the fixnum case.
* Canonicalize <=, >=, and > primcalls to <Andy Wingo2017-11-111-8/+40
| | | | | | | | | | | | | | | | | | | | * module/language/tree-il/compile-cps.scm (canonicalize): Convert <=, >=, and > primcalls to <. * module/language/cps/primitives.scm (*comparisons*): * module/language/cps/effects-analysis.scm: Remove superfluous primcalls. * module/language/cps/specialize-numbers.scm (specialize-u64-scm-comparison): Only emit < primcalls for ordered comparisons. (specialize-scm-u64-comparison): New helper. * module/language/cps/specialize-numbers.scm (specialize-operations): Remove support for >=, <=, and the like. * module/language/cps/type-fold.scm: Remove folders for <= and so on. * module/language/cps/types.scm (define-=-inferrer, define-<-inferrer): New helpers; use them for all = and < variants. Remove checkers and inferrers for <= and the like. * module/language/cps/compile-bytecode.scm (compile-function): Remove unnecessary cases.
* Add lsh, rsh instructionsAndy Wingo2017-11-051-17/+113
| | | | | | | | | | | | | | | | | | | | | | * libguile/vm-engine.c (lsh, rsh, lsh/immediate, rsh/immediate): New instructions taking unboxed bit counts. * module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/effects-analysis.scm: * module/language/cps/specialize-numbers.scm (specialize-f64-unop): (specialize-u64-unop): Add ability to specialize add/immediate, etc, and add lsh/immediate as well. (specialize-u64-binop, specialize-u64-shift): Move rsh/lsh specialization to its own procedure, given that the bit count is already unboxed. (specialize-operations): Adapt to support more /immediate instructions. * module/language/cps/type-fold.scm (mul): Reify an lsh/immediate instead of an ash. * module/language/cps/types.scm (compute-ash-range): Add type inferrers for lsh, rsh, and their immediate variants. * module/system/vm/assembler.scm: Export emit-lsh and so on. * module/language/tree-il/compile-cps.scm (convert): Convert "ash" on immediates to rsh/immediate or lsh/immediate.
* load-f64, etc take immediate parametersAndy Wingo2017-11-051-4/+2
| | | | | | | | | | | | | | | | | | | | | * module/language/cps/compile-bytecode.scm (compile-function): Make load-f64, load-s64, and load-u64 take an immediate parameter instead of a CPS value. * module/language/cps/effects-analysis.scm: Remove CPS argument from immediate load instructions. * module/language/cps/slot-allocation.scm (compute-needs-slot): Remove special case for load-64 etc. * module/language/cps/specialize-numbers.scm (specialize-u64-scm-comparison): Adapt. * module/language/cps/specialize-primcalls.scm (specialize-primcalls): Adapt. * module/language/cps/types.scm (define-type-inferrer*): Also take param argument. (define-type-inferrer, define-predicate-inferrer): Adapt. (define-type-inferrer/param): New helper. (load-f64, load-s64, load-u64): Adapt inferrers to pass on value from param. * module/language/cps/utils.scm (compute-constant-values): Adapt.
* $primcall has a "param" memberAndy Wingo2017-11-051-40/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * module/language/cps.scm ($primcall): Add "param" member, which will be a constant parameter to the primcall. The idea is that constants used by primcalls as immediates don't need to participate in optimizations in any way -- they should not participate in CSE, have the same lifetime as the primcall so not part of DCE either, and don't need slot allocation. Indirecting them through a named $const binding is complication for no benefit. This change should eventually improve compilation time and memory usage, once we fully take advantage of it, as the number of labels and variables will go down. * module/language/cps/closure-conversion.scm: * module/language/cps/compile-bytecode.scm: * module/language/cps/constructors.scm: * module/language/cps/contification.scm: * module/language/cps/cse.scm: * module/language/cps/dce.scm: * module/language/cps/effects-analysis.scm: * module/language/cps/elide-values.scm: * module/language/cps/handle-interrupts.scm: * module/language/cps/licm.scm: * module/language/cps/peel-loops.scm: * module/language/cps/prune-bailouts.scm: * module/language/cps/prune-top-level-scopes.scm: * module/language/cps/reify-primitives.scm: * module/language/cps/renumber.scm: * module/language/cps/rotate-loops.scm: * module/language/cps/self-references.scm: * module/language/cps/simplify.scm: * module/language/cps/slot-allocation.scm: * module/language/cps/specialize-numbers.scm: * module/language/cps/specialize-primcalls.scm: * module/language/cps/split-rec.scm: * module/language/cps/type-checks.scm: * module/language/cps/type-fold.scm: * module/language/cps/types.scm: * module/language/cps/utils.scm: * module/language/cps/verify.scm: * module/language/tree-il/compile-cps.scm: Adapt all users.
* Inline u64/scm comparisonsAndy Wingo2017-10-291-6/+29
| | | | | * module/language/cps/specialize-numbers.scm (specialize-u64-scm-comparison): Inline comparisons against fixnums.
* Add hacks around lack of allocation sinkingAndy Wingo2017-10-291-0/+1
| | | | | | | | | | | | * 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/primitives.scm (*macro-instruction-arities*): * module/language/cps/specialize-numbers.scm (compute-specializable-vars): * module/language/cps/types.scm: Add new variants of u64->scm and s64->scm that can't be replaced by CSE's auxiliary definitions, so we can sink unlikely allocations to side branches. This is a hack until we can get allocation sinking working
* Simplify $branch to always take a $primcallAndy Wingo2017-10-291-2/+0
| | | | | | | | | | | | | | | | | | | | | * module/language/tree-il/compile-cps.scm (convert): Lower (if foo A B) to (if (false? foo) B A). * module/language/cps/specialize-numbers.scm: * module/language/cps/closure-conversion.scm: * module/language/cps/contification.scm: * module/language/cps/cse.scm: * module/language/cps/dce.scm: * module/language/cps/peel-loops.scm: * module/language/cps/rotate-loops.scm: * module/language/cps/self-references.scm: * module/language/cps/simplify.scm: * module/language/cps/slot-allocation.scm: * module/language/cps/split-rec.scm: * module/language/cps/type-fold.scm: * module/language/cps/types.scm: * module/language/cps/verify.scm: Adapt. * module/language/cps/compile-bytecode.scm: Add support for new-style false? instruction for false? primcall.
* Type inference distinguishes &fixnum and &bignum typesAndy Wingo2017-10-261-6/+6
| | | | | | | | | | | | | | | | | This will allow heap-object? / inum? predicates to do something useful. * module/language/cps/types.scm (&fixnum, &bignum): Split &exact-integer into these types. Keep &exact-integer as a union type. (type<=?): New helper. (constant-type): Return &fixnum or &bignum as appropriate. (define-exact-integer!): New helper, tries to make exact integer results be &fixnum if they are within range. Adapt users. (restricted-comparison-ranges, define-binary-result!): Use type<=? instead of = for &exact-integer. * module/language/cps/type-fold.scm (logtest, mul, logbit?): Use type<=?. * module/language/cps/specialize-numbers.scm (inferred-sigbits): (specialize-operations): Use type<=?.
* Fix bug in comparison between real and complexDaniel Llorens2017-03-091-6/+8
| | | | | | | | | This bug was introduced by 35a90592501ebde7e7ddbf2486ca9d315e317d09. * module/language/cps/specialize-numbers.scm (specialize-operations): Check that both operands are real as a condition for specialize-f64-comparison. * test-suite/tests/numbers.test: Add test.
* Add unboxed floating point comparison instructions.David Thompson2017-01-121-14/+38
| | | | | | | | | | | | | | | | | | | | * 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.
* Fix bug in compute-significant-bits for phi predecessorsAndy Wingo2016-12-141-11/+15
| | | | | | | * module/language/cps/specialize-numbers.scm (compute-significant-bits): Always revisit predecessors after first visit. Avoids situation where predecessor of an unvisited phi var could default to 0 significant bits and never be revisited. Fixes (format #f "~2f" 9.9).
* Better unboxingAndy Wingo2016-09-011-69/+211
| | | | | | | | | | | | | * module/language/cps/specialize-numbers.scm (truncate-u64): New helper, truncates a SCM value. (specialize-u64-binop): Add ulogxor case. (sigbits-union, sigbits-intersect, sigbits-intersect3) (next-power-of-two, range->sigbits, inferred-sigbits) (significant-bits-handlers, define-significant-bits-handler): (significant-bits-handler, compute-significant-bits): Add facility to compute the bits in a value that are significant. (specialize-operations): Unbox in more cases, when only u64 bits are significant. Unbox logxor. Elide logand where it has no effect.
* Add support for comparing u64 values with SCM valuesAndy Wingo2015-12-031-5/+25
| | | | | | | | | | | | | | | | | | | | | * 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.
* Specialize u64 bit operationsAndy Wingo2015-12-021-8/+89
| | | | | * module/language/cps/specialize-numbers.scm (specialize-u64-binop): (specialize-operations): Specialize u64 bit operations.
* Specialize u64 arithmeticAndy Wingo2015-12-011-19/+48
| | | | | | * module/language/cps/specialize-numbers.scm (specialize-operations): (specialize-u64-binop): Specialize u64 addition, subtraction, and multiplication.
* Unbox u64 phi valuesAndy Wingo2015-12-011-54/+83
| | | | | | | | | * module/language/cps/specialize-numbers.scm (compute-specializable-vars): Refactor to work on any kind of unboxable value, not just f64 values. (compute-specializable-f64-vars, compute-specializable-u64-vars): New helpers. (apply-specialization): Support for u64 values.
* Beginning of u64 phi unboxingAndy Wingo2015-12-011-45/+62
| | | | | | | | | | | | | * module/language/cps/specialize-numbers.scm (compute-specializable-u64-vars): New stub. * module/language/cps/specialize-numbers.scm (compute-specializable-phis): Rename from compute-specializable-f64-phis, and return an intmap instead of an intset. The values distinguish f64 from u64 vars. * module/language/cps/specialize-numbers.scm (apply-specialization): Start of u64 phi unboxing. * module/language/cps/specialize-numbers.scm (specialize-phis): (specialize-numbers): Adapt.
* Specialize u64 comparisonsAndy Wingo2015-12-011-2/+33
| | | | | | | | | | * module/language/cps/specialize-numbers.scm (specialize-u64-comparison): New function. * module/language/cps/specialize-numbers.scm (specialize-operations): Rename from specialize-f64-operations, as it will specialize both kinds. Add a case to specialize u64 comparisons. * module/language/cps/specialize-numbers.scm (specialize-numbers): Adapt to specialize-operations name change.
* Remove debug printout in specialize-numbersAndy Wingo2015-11-111-1/+0
| | | | | | | * module/language/cps/specialize-numbers.scm (apply-f64-specialization): Remove printout. I didn't see any when compiling Guile, which means that probably this optimization doesn't hit for any code in Guile itself, sadly :P
* Better f64 unboxing for loop vars that might flow to $ktailAndy Wingo2015-11-111-7/+13
| | | | | * module/language/cps/specialize-numbers.scm (compute-specializable-f64-vars): Tweak to allow f64 values to flow directly to return sites.
* The compiler can unbox float64 loop variablesAndy Wingo2015-11-111-2/+251
| | | | | * module/language/cps/specialize-numbers.scm: Specialize phi variables as well.
* Add new pass to specialize "add" into "fadd" where possibleAndy Wingo2015-11-111-0/+91
* module/language/cps/specialize-numbers.scm: New pass, to turn "add" into "fadd", and similarly for sub, mul, and div. * module/language/cps/optimize.scm: * module/Makefile.am: * bootstrap/Makefile.am: Wire up the new pass.