1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs accessors arrays kernel sequences namespaces words
4 math math.order layouts classes.union compiler.units alien
5 byte-arrays combinators compiler.cfg.registers
6 compiler.cfg.instructions.syntax ;
7 IN: compiler.cfg.instructions
11 V{ } clone insn-classes set-global
14 : new-insn ( ... class -- insn ) f swap boa ; inline
16 ! Virtual CPU instructions, used by CFG IR
19 ! Instructions which use vregs
20 TUPLE: vreg-insn < insn ;
22 ! Instructions which are referentially transparent; used for
24 TUPLE: pure-insn < vreg-insn ;
31 INSN: ##load-reference
35 ! These three are inserted by representation selection
83 ! Dummy instruction that simply inhibits TCO
94 use: obj/tagged-rep slot/int-rep
103 use: src/tagged-rep obj/tagged-rep slot/int-rep
107 use: src/tagged-rep obj/tagged-rep
116 PURE-INSN: ##tagged>integer
118 use: src/tagged-rep ;
123 use: src1/int-rep src2/int-rep ;
132 use: src1/int-rep src2/int-rep ;
141 use: src1/int-rep src2/int-rep ;
150 use: src1/int-rep src2/int-rep ;
159 use: src1/int-rep src2/int-rep ;
168 use: src1/int-rep src2/int-rep ;
177 use: src1/int-rep src2/int-rep ;
186 use: src1/int-rep src2/int-rep ;
195 use: src1/int-rep src2/int-rep ;
204 use: src1/int-rep src2/int-rep ;
208 use: src1/int-rep src2/int-rep ;
222 PURE-INSN: ##bit-count
227 PURE-INSN: ##add-float
229 use: src1/double-rep src2/double-rep ;
231 PURE-INSN: ##sub-float
233 use: src1/double-rep src2/double-rep ;
235 PURE-INSN: ##mul-float
237 use: src1/double-rep src2/double-rep ;
239 PURE-INSN: ##div-float
241 use: src1/double-rep src2/double-rep ;
243 PURE-INSN: ##min-float
245 use: src1/double-rep src2/double-rep ;
247 PURE-INSN: ##max-float
249 use: src1/double-rep src2/double-rep ;
253 use: src/double-rep ;
256 PURE-INSN: ##unary-float-function
261 PURE-INSN: ##binary-float-function
263 use: src1/double-rep src2/double-rep
266 ! Single/double float conversion
267 PURE-INSN: ##single>double-float
271 PURE-INSN: ##double>single-float
273 use: src/double-rep ;
275 ! Float/integer conversion
276 PURE-INSN: ##float>integer
278 use: src/double-rep ;
280 PURE-INSN: ##integer>float
285 PURE-INSN: ##zero-vector
289 PURE-INSN: ##fill-vector
293 PURE-INSN: ##gather-vector-2
295 use: src1/scalar-rep src2/scalar-rep
298 PURE-INSN: ##gather-int-vector-2
300 use: src1/int-rep src2/int-rep
303 PURE-INSN: ##gather-vector-4
305 use: src1/scalar-rep src2/scalar-rep src3/scalar-rep src4/scalar-rep
308 PURE-INSN: ##gather-int-vector-4
310 use: src1/int-rep src2/int-rep src3/int-rep src4/int-rep
313 PURE-INSN: ##select-vector
318 PURE-INSN: ##shuffle-vector
323 PURE-INSN: ##shuffle-vector-halves-imm
326 literal: shuffle rep ;
328 PURE-INSN: ##shuffle-vector-imm
331 literal: shuffle rep ;
333 PURE-INSN: ##tail>head-vector
338 PURE-INSN: ##merge-vector-head
343 PURE-INSN: ##merge-vector-tail
348 PURE-INSN: ##float-pack-vector
353 PURE-INSN: ##signed-pack-vector
358 PURE-INSN: ##unsigned-pack-vector
363 PURE-INSN: ##unpack-vector-head
368 PURE-INSN: ##unpack-vector-tail
373 PURE-INSN: ##integer>float-vector
378 PURE-INSN: ##float>integer-vector
383 PURE-INSN: ##compare-vector
388 PURE-INSN: ##test-vector
394 INSN: ##test-vector-branch
399 PURE-INSN: ##add-vector
404 PURE-INSN: ##saturated-add-vector
409 PURE-INSN: ##add-sub-vector
414 PURE-INSN: ##sub-vector
419 PURE-INSN: ##saturated-sub-vector
424 PURE-INSN: ##mul-vector
429 PURE-INSN: ##mul-high-vector
434 PURE-INSN: ##mul-horizontal-add-vector
439 PURE-INSN: ##saturated-mul-vector
444 PURE-INSN: ##div-vector
449 PURE-INSN: ##min-vector
454 PURE-INSN: ##max-vector
459 PURE-INSN: ##avg-vector
464 PURE-INSN: ##dot-vector
469 PURE-INSN: ##sad-vector
474 PURE-INSN: ##horizontal-add-vector
479 PURE-INSN: ##horizontal-sub-vector
484 PURE-INSN: ##horizontal-shl-vector-imm
489 PURE-INSN: ##horizontal-shr-vector-imm
494 PURE-INSN: ##abs-vector
499 PURE-INSN: ##sqrt-vector
504 PURE-INSN: ##and-vector
509 PURE-INSN: ##andn-vector
514 PURE-INSN: ##or-vector
519 PURE-INSN: ##xor-vector
524 PURE-INSN: ##not-vector
529 PURE-INSN: ##shl-vector-imm
534 PURE-INSN: ##shr-vector-imm
539 PURE-INSN: ##shl-vector
541 use: src1 src2/int-scalar-rep
544 PURE-INSN: ##shr-vector
546 use: src1 src2/int-scalar-rep
549 ! Scalar/vector conversion
550 PURE-INSN: ##scalar>integer
555 PURE-INSN: ##integer>scalar
560 PURE-INSN: ##vector>scalar
565 PURE-INSN: ##scalar>vector
570 ! Boxing and unboxing aliens
571 PURE-INSN: ##box-alien
576 PURE-INSN: ##box-displaced-alien
578 use: displacement/int-rep base/tagged-rep
580 literal: base-class ;
582 PURE-INSN: ##unbox-any-c-ptr
584 use: src/tagged-rep ;
586 PURE-INSN: ##unbox-alien
588 use: src/tagged-rep ;
590 ! Raw memory accessors
593 use: base/int-rep displacement/int-rep
594 literal: scale offset rep c-type ;
596 INSN: ##load-memory-imm
599 literal: offset rep c-type ;
602 use: src base/int-rep displacement/int-rep
603 literal: scale offset rep c-type ;
605 INSN: ##store-memory-imm
606 use: src base/int-rep
607 literal: offset rep c-type ;
615 INSN: ##write-barrier
616 use: src/tagged-rep slot/int-rep
618 temp: temp1/int-rep temp2/int-rep ;
620 INSN: ##write-barrier-imm
623 temp: temp1/int-rep temp2/int-rep ;
627 literal: symbol library ;
639 literal: stack-frame ;
644 literal: unboxer rep ;
646 INSN: ##unbox-long-long
647 use: src/tagged-rep out/int-rep
650 INSN: ##store-reg-param
654 INSN: ##store-stack-param
658 INSN: ##load-reg-param
662 INSN: ##load-stack-param
668 literal: size align offset ;
675 INSN: ##box-long-long
677 use: src1/int-rep src2/int-rep
680 INSN: ##allot-byte-array
684 INSN: ##prepare-var-args ;
687 literal: symbols dll ;
692 INSN: ##alien-indirect
695 INSN: ##alien-assembly
698 INSN: ##begin-callback ;
700 INSN: ##alien-callback
703 INSN: ##end-callback ;
712 ! Tagged conditionals
713 INSN: ##compare-branch
714 use: src1/tagged-rep src2/tagged-rep
717 INSN: ##compare-imm-branch
723 use: src1/tagged-rep src2/tagged-rep
727 PURE-INSN: ##compare-imm
733 ! Integer conditionals
734 INSN: ##compare-integer-branch
735 use: src1/int-rep src2/int-rep
738 INSN: ##compare-integer-imm-branch
743 use: src1/int-rep src2/int-rep
746 INSN: ##test-imm-branch
750 PURE-INSN: ##compare-integer
752 use: src1/int-rep src2/int-rep
756 PURE-INSN: ##compare-integer-imm
764 use: src1/int-rep src2/int-rep
768 PURE-INSN: ##test-imm
775 INSN: ##compare-float-ordered-branch
776 use: src1/double-rep src2/double-rep
779 INSN: ##compare-float-unordered-branch
780 use: src1/double-rep src2/double-rep
783 PURE-INSN: ##compare-float-ordered
785 use: src1/double-rep src2/double-rep
789 PURE-INSN: ##compare-float-unordered
791 use: src1/double-rep src2/double-rep
795 ! Overflowing arithmetic
798 use: src1/tagged-rep src2/tagged-rep
803 use: src1/tagged-rep src2/tagged-rep
808 use: src1/tagged-rep src2/int-rep
812 temp: temp1/int-rep temp2/int-rep ;
814 INSN: ##restore-context
815 temp: temp1/int-rep temp2/int-rep ;
818 INSN: ##check-nursery-branch
820 temp: temp1/int-rep temp2/int-rep ;
825 literal: scrub-d scrub-r gc-roots ;
827 ! Spills and reloads, inserted by register allocator
828 TUPLE: spill-slot { n integer } ;
829 C: <spill-slot> spill-slot
842 ##box-displaced-alien ;
844 UNION: conditional-branch-insn
847 ##compare-integer-branch
848 ##compare-integer-imm-branch
851 ##compare-float-ordered-branch
852 ##compare-float-unordered-branch
854 ##check-nursery-branch
860 UNION: ##read ##slot ##slot-imm ##vm-field ##alien-global ;
861 UNION: ##write ##set-slot ##set-slot-imm ##set-vm-field ;
863 ! Instructions that clobber registers. They receive inputs and
864 ! produce outputs in spill slots.
865 UNION: hairy-clobber-insn
875 ! Instructions that clobber registers but are allowed to produce
876 ! outputs in registers. Inputs are in spill slots, except for
877 ! inputs coalesced with the output, in which case that input
878 ! will be in a register.
881 ##unary-float-function
882 ##binary-float-function
889 ! Instructions that have complex expansions and require that the
890 ! output registers are not equal to any of the input registers
891 UNION: def-is-use-insn
893 ##box-displaced-alien