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: ##shuffle-vector
318 PURE-INSN: ##shuffle-vector-halves-imm
321 literal: shuffle rep ;
323 PURE-INSN: ##shuffle-vector-imm
326 literal: shuffle rep ;
328 PURE-INSN: ##tail>head-vector
333 PURE-INSN: ##merge-vector-head
338 PURE-INSN: ##merge-vector-tail
343 PURE-INSN: ##signed-pack-vector
348 PURE-INSN: ##unsigned-pack-vector
353 PURE-INSN: ##unpack-vector-head
358 PURE-INSN: ##unpack-vector-tail
363 PURE-INSN: ##integer>float-vector
368 PURE-INSN: ##float>integer-vector
373 PURE-INSN: ##compare-vector
378 PURE-INSN: ##test-vector
384 INSN: ##test-vector-branch
389 PURE-INSN: ##add-vector
394 PURE-INSN: ##saturated-add-vector
399 PURE-INSN: ##add-sub-vector
404 PURE-INSN: ##sub-vector
409 PURE-INSN: ##saturated-sub-vector
414 PURE-INSN: ##mul-vector
419 PURE-INSN: ##mul-high-vector
424 PURE-INSN: ##mul-horizontal-add-vector
429 PURE-INSN: ##saturated-mul-vector
434 PURE-INSN: ##div-vector
439 PURE-INSN: ##min-vector
444 PURE-INSN: ##max-vector
449 PURE-INSN: ##avg-vector
454 PURE-INSN: ##dot-vector
459 PURE-INSN: ##sad-vector
464 PURE-INSN: ##horizontal-add-vector
469 PURE-INSN: ##horizontal-sub-vector
474 PURE-INSN: ##horizontal-shl-vector-imm
479 PURE-INSN: ##horizontal-shr-vector-imm
484 PURE-INSN: ##abs-vector
489 PURE-INSN: ##sqrt-vector
494 PURE-INSN: ##and-vector
499 PURE-INSN: ##andn-vector
504 PURE-INSN: ##or-vector
509 PURE-INSN: ##xor-vector
514 PURE-INSN: ##not-vector
519 PURE-INSN: ##shl-vector-imm
524 PURE-INSN: ##shr-vector-imm
529 PURE-INSN: ##shl-vector
531 use: src1 src2/int-scalar-rep
534 PURE-INSN: ##shr-vector
536 use: src1 src2/int-scalar-rep
539 ! Scalar/vector conversion
540 PURE-INSN: ##scalar>integer
545 PURE-INSN: ##integer>scalar
550 PURE-INSN: ##vector>scalar
555 PURE-INSN: ##scalar>vector
560 ! Boxing and unboxing aliens
561 PURE-INSN: ##box-alien
566 PURE-INSN: ##box-displaced-alien
568 use: displacement/int-rep base/tagged-rep
570 literal: base-class ;
572 PURE-INSN: ##unbox-any-c-ptr
574 use: src/tagged-rep ;
576 PURE-INSN: ##unbox-alien
578 use: src/tagged-rep ;
580 ! Raw memory accessors
583 use: base/int-rep displacement/int-rep
584 literal: scale offset rep c-type ;
586 INSN: ##load-memory-imm
589 literal: offset rep c-type ;
592 use: src base/int-rep displacement/int-rep
593 literal: scale offset rep c-type ;
595 INSN: ##store-memory-imm
596 use: src base/int-rep
597 literal: offset rep c-type ;
605 INSN: ##write-barrier
606 use: src/tagged-rep slot/int-rep
608 temp: temp1/int-rep temp2/int-rep ;
610 INSN: ##write-barrier-imm
613 temp: temp1/int-rep temp2/int-rep ;
617 literal: symbol library ;
629 literal: stack-frame ;
634 literal: unboxer rep ;
636 INSN: ##store-reg-param
640 INSN: ##store-stack-param
648 INSN: ##store-struct-return
652 INSN: ##store-long-long-return
653 use: src1/int-rep src2/int-rep ;
655 INSN: ##prepare-struct-area
660 literal: n rep boxer ;
662 INSN: ##box-long-long
666 INSN: ##box-small-struct
670 INSN: ##box-large-struct
675 literal: symbols dll ;
680 INSN: ##alien-indirect
683 INSN: ##alien-assembly
686 INSN: ##save-param-reg
687 literal: offset reg rep ;
689 INSN: ##begin-callback ;
691 INSN: ##alien-callback
694 INSN: ##end-callback ;
703 ! Tagged conditionals
704 INSN: ##compare-branch
705 use: src1/tagged-rep src2/tagged-rep
708 INSN: ##compare-imm-branch
714 use: src1/tagged-rep src2/tagged-rep
718 PURE-INSN: ##compare-imm
724 ! Integer conditionals
725 INSN: ##compare-integer-branch
726 use: src1/int-rep src2/int-rep
729 INSN: ##compare-integer-imm-branch
734 use: src1/int-rep src2/int-rep
737 INSN: ##test-imm-branch
741 PURE-INSN: ##compare-integer
743 use: src1/int-rep src2/int-rep
747 PURE-INSN: ##compare-integer-imm
755 use: src1/int-rep src2/int-rep
759 PURE-INSN: ##test-imm
766 INSN: ##compare-float-ordered-branch
767 use: src1/double-rep src2/double-rep
770 INSN: ##compare-float-unordered-branch
771 use: src1/double-rep src2/double-rep
774 PURE-INSN: ##compare-float-ordered
776 use: src1/double-rep src2/double-rep
780 PURE-INSN: ##compare-float-unordered
782 use: src1/double-rep src2/double-rep
786 ! Overflowing arithmetic
789 use: src1/tagged-rep src2/tagged-rep
794 use: src1/tagged-rep src2/tagged-rep
799 use: src1/tagged-rep src2/int-rep
803 temp: temp1/int-rep temp2/int-rep ;
805 INSN: ##restore-context
806 temp: temp1/int-rep temp2/int-rep ;
809 INSN: ##check-nursery-branch
811 temp: temp1/int-rep temp2/int-rep ;
816 ! Spills and reloads, inserted by register allocator
817 TUPLE: spill-slot { n integer } ;
818 C: <spill-slot> spill-slot
831 ##box-displaced-alien ;
833 UNION: conditional-branch-insn
836 ##compare-integer-branch
837 ##compare-integer-imm-branch
840 ##compare-float-ordered-branch
841 ##compare-float-unordered-branch
843 ##check-nursery-branch
849 UNION: ##read ##slot ##slot-imm ##vm-field ##alien-global ;
850 UNION: ##write ##set-slot ##set-slot-imm ##set-vm-field ;
852 ! Instructions that clobber registers
855 ##unary-float-function
856 ##binary-float-function
864 ##store-struct-return
865 ##store-long-long-return
873 ! Instructions that have complex expansions and require that the
874 ! output registers are not equal to any of the input registers
875 UNION: def-is-use-insn
877 ##box-displaced-alien