1 ! Copyright (C) 2008, 2009 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.algebra classes.union
5 compiler.units alien byte-arrays compiler.constants combinators
6 compiler.cfg.registers 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 and machine IRs
19 ! Instructions which are referentially transparent; used for
21 TUPLE: pure-insn < insn ;
24 INSN: ##load-immediate
28 INSN: ##load-reference
59 ! Dummy instruction that simply inhibits TCO
70 use: obj/int-rep slot/int-rep ;
78 use: src/int-rep obj/int-rep slot/int-rep ;
81 use: src/int-rep obj/int-rep
84 ! String element access
87 use: obj/int-rep index/int-rep
90 INSN: ##set-string-nth-fast
91 use: src/int-rep obj/int-rep index/int-rep
102 use: src1/int-rep src2/int-rep ;
111 use: src1/int-rep src2/int-rep ;
120 use: src1/int-rep src2/int-rep ;
129 use: src1/int-rep src2/int-rep ;
138 use: src1/int-rep src2/int-rep ;
147 use: src1/int-rep src2/int-rep ;
156 use: src1/int-rep src2/int-rep ;
165 use: src1/int-rep src2/int-rep ;
174 use: src1/int-rep src2/int-rep ;
183 use: src1/int-rep src2/int-rep ;
187 use: src1/int-rep src2/int-rep ;
202 PURE-INSN: ##add-float
204 use: src1/double-rep src2/double-rep ;
206 PURE-INSN: ##sub-float
208 use: src1/double-rep src2/double-rep ;
210 PURE-INSN: ##mul-float
212 use: src1/double-rep src2/double-rep ;
214 PURE-INSN: ##div-float
216 use: src1/double-rep src2/double-rep ;
218 PURE-INSN: ##min-float
220 use: src1/double-rep src2/double-rep ;
222 PURE-INSN: ##max-float
224 use: src1/double-rep src2/double-rep ;
228 use: src/double-rep ;
231 PURE-INSN: ##unary-float-function
236 PURE-INSN: ##binary-float-function
238 use: src1/double-rep src2/double-rep
241 ! Single/double float conversion
242 PURE-INSN: ##single>double-float
246 PURE-INSN: ##double>single-float
248 use: src/double-rep ;
250 ! Float/integer conversion
251 PURE-INSN: ##float>integer
253 use: src/double-rep ;
255 PURE-INSN: ##integer>float
260 PURE-INSN: ##zero-vector
264 PURE-INSN: ##fill-vector
268 PURE-INSN: ##gather-vector-2
270 use: src1/scalar-rep src2/scalar-rep
273 PURE-INSN: ##gather-vector-4
275 use: src1/scalar-rep src2/scalar-rep src3/scalar-rep src4/scalar-rep
278 PURE-INSN: ##shuffle-vector
283 PURE-INSN: ##shuffle-vector-imm
286 literal: shuffle rep ;
288 PURE-INSN: ##tail>head-vector
293 PURE-INSN: ##merge-vector-head
298 PURE-INSN: ##merge-vector-tail
303 PURE-INSN: ##signed-pack-vector
308 PURE-INSN: ##unsigned-pack-vector
313 PURE-INSN: ##unpack-vector-head
318 PURE-INSN: ##unpack-vector-tail
323 PURE-INSN: ##integer>float-vector
328 PURE-INSN: ##float>integer-vector
333 PURE-INSN: ##compare-vector
338 PURE-INSN: ##test-vector
344 INSN: ##test-vector-branch
349 INSN: _test-vector-branch
355 PURE-INSN: ##add-vector
360 PURE-INSN: ##saturated-add-vector
365 PURE-INSN: ##add-sub-vector
370 PURE-INSN: ##sub-vector
375 PURE-INSN: ##saturated-sub-vector
380 PURE-INSN: ##mul-vector
385 PURE-INSN: ##saturated-mul-vector
390 PURE-INSN: ##div-vector
395 PURE-INSN: ##min-vector
400 PURE-INSN: ##max-vector
405 PURE-INSN: ##dot-vector
410 PURE-INSN: ##horizontal-add-vector
415 PURE-INSN: ##horizontal-sub-vector
420 PURE-INSN: ##horizontal-shl-vector
425 PURE-INSN: ##horizontal-shr-vector
430 PURE-INSN: ##abs-vector
435 PURE-INSN: ##sqrt-vector
440 PURE-INSN: ##and-vector
445 PURE-INSN: ##andn-vector
450 PURE-INSN: ##or-vector
455 PURE-INSN: ##xor-vector
460 PURE-INSN: ##not-vector
465 PURE-INSN: ##shl-vector
467 use: src1 src2/int-scalar-rep
470 PURE-INSN: ##shr-vector
472 use: src1 src2/int-scalar-rep
475 ! Scalar/vector conversion
476 PURE-INSN: ##scalar>integer
481 PURE-INSN: ##integer>scalar
486 PURE-INSN: ##vector>scalar
491 PURE-INSN: ##scalar>vector
496 ! Boxing and unboxing aliens
497 PURE-INSN: ##box-alien
502 PURE-INSN: ##box-displaced-alien
504 use: displacement/int-rep base/int-rep
505 temp: temp1/int-rep temp2/int-rep
506 literal: base-class ;
508 PURE-INSN: ##unbox-any-c-ptr
513 : ##unbox-f ( dst src -- ) drop 0 ##load-immediate ;
514 : ##unbox-byte-array ( dst src -- ) byte-array-offset ##add-imm ;
516 PURE-INSN: ##unbox-alien
520 : ##unbox-c-ptr ( dst src class temp -- )
522 { [ over \ f class<= ] [ 2drop ##unbox-f ] }
523 { [ over simple-alien class<= ] [ 2drop ##unbox-alien ] }
524 { [ over byte-array class<= ] [ 2drop ##unbox-byte-array ] }
525 [ nip ##unbox-any-c-ptr ]
529 INSN: ##alien-unsigned-1
534 INSN: ##alien-unsigned-2
539 INSN: ##alien-unsigned-4
544 INSN: ##alien-signed-1
549 INSN: ##alien-signed-2
554 INSN: ##alien-signed-4
577 literal: offset rep ;
579 INSN: ##set-alien-integer-1
584 INSN: ##set-alien-integer-2
589 INSN: ##set-alien-integer-4
594 INSN: ##set-alien-cell
599 INSN: ##set-alien-float
602 use: value/float-rep ;
604 INSN: ##set-alien-double
607 use: value/double-rep ;
609 INSN: ##set-alien-vector
621 INSN: ##write-barrier
623 temp: card#/int-rep table/int-rep ;
627 literal: symbol library ;
631 literal: field-name ;
635 literal: params stack-frame ;
637 INSN: ##alien-indirect
638 literal: params stack-frame ;
640 INSN: ##alien-callback
641 literal: params stack-frame ;
643 INSN: ##callback-return
646 ! Instructions used by CFG IR only.
657 INSN: ##compare-branch
658 use: src1/int-rep src2/int-rep
661 INSN: ##compare-imm-branch
668 use: src1/int-rep src2/int-rep
672 PURE-INSN: ##compare-imm
679 INSN: ##compare-float-ordered-branch
680 use: src1/double-rep src2/double-rep
683 INSN: ##compare-float-unordered-branch
684 use: src1/double-rep src2/double-rep
687 PURE-INSN: ##compare-float-ordered
689 use: src1/double-rep src2/double-rep
693 PURE-INSN: ##compare-float-unordered
695 use: src1/double-rep src2/double-rep
699 ! Overflowing arithmetic
702 use: src1/int-rep src2/int-rep ;
706 use: src1/int-rep src2/int-rep ;
710 use: src1/int-rep src2/int-rep ;
713 temp: temp1/int-rep temp2/int-rep
714 literal: size data-values tagged-values uninitialized-locs ;
717 temp: temp1/int-rep temp2/int-rep
718 literal: callback-allowed? ;
720 ! Instructions used by machine IR only.
722 literal: stack-frame ;
725 literal: stack-frame ;
739 INSN: _dispatch-label
742 INSN: _compare-branch
744 use: src1/int-rep src2/int-rep
747 INSN: _compare-imm-branch
753 INSN: _compare-float-unordered-branch
755 use: src1/int-rep src2/int-rep
758 INSN: _compare-float-ordered-branch
760 use: src1/int-rep src2/int-rep
763 ! Overflowing arithmetic
767 use: src1/int-rep src2/int-rep ;
772 use: src1/int-rep src2/int-rep ;
777 use: src1/int-rep src2/int-rep ;
779 TUPLE: spill-slot { n integer } ;
780 C: <spill-slot> spill-slot
782 ! These instructions operate on machine registers and not
792 INSN: _spill-area-size
798 ##box-displaced-alien ;
801 UNION: ##read ##slot ##slot-imm ##vm-field-ptr ##alien-global ;
802 UNION: ##write ##set-slot ##set-slot-imm ;
804 ! Instructions that kill all live vregs but cannot trigger GC
805 UNION: partial-sync-insn
806 ##unary-float-function
807 ##binary-float-function ;
809 ! Instructions that kill all live vregs
810 UNION: kill-vreg-insn
818 ! Instructions that have complex expansions and require that the
819 ! output registers are not equal to any of the input registers
820 UNION: def-is-use-insn
822 ##box-displaced-alien
831 "insn-slots" word-prop [ type>> { def use temp } memq? ] any?
834 ] with-compilation-unit