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-imm
425 PURE-INSN: ##horizontal-shr-vector-imm
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-imm
470 PURE-INSN: ##shr-vector-imm
475 PURE-INSN: ##shl-vector
477 use: src1 src2/int-scalar-rep
480 PURE-INSN: ##shr-vector
482 use: src1 src2/int-scalar-rep
485 ! Scalar/vector conversion
486 PURE-INSN: ##scalar>integer
491 PURE-INSN: ##integer>scalar
496 PURE-INSN: ##vector>scalar
501 PURE-INSN: ##scalar>vector
506 ! Boxing and unboxing aliens
507 PURE-INSN: ##box-alien
512 PURE-INSN: ##box-displaced-alien
514 use: displacement/int-rep base/int-rep
516 literal: base-class ;
518 PURE-INSN: ##unbox-any-c-ptr
522 : ##unbox-f ( dst src -- ) drop 0 ##load-immediate ;
523 : ##unbox-byte-array ( dst src -- ) byte-array-offset ##add-imm ;
525 PURE-INSN: ##unbox-alien
529 : ##unbox-c-ptr ( dst src class -- )
531 { [ dup \ f class<= ] [ drop ##unbox-f ] }
532 { [ dup alien class<= ] [ drop ##unbox-alien ] }
533 { [ dup byte-array class<= ] [ drop ##unbox-byte-array ] }
534 [ drop ##unbox-any-c-ptr ]
538 INSN: ##alien-unsigned-1
543 INSN: ##alien-unsigned-2
548 INSN: ##alien-unsigned-4
553 INSN: ##alien-signed-1
558 INSN: ##alien-signed-2
563 INSN: ##alien-signed-4
586 literal: offset rep ;
588 INSN: ##set-alien-integer-1
593 INSN: ##set-alien-integer-2
598 INSN: ##set-alien-integer-4
603 INSN: ##set-alien-cell
608 INSN: ##set-alien-float
611 use: value/float-rep ;
613 INSN: ##set-alien-double
616 use: value/double-rep ;
618 INSN: ##set-alien-vector
630 INSN: ##write-barrier
631 use: src/int-rep slot/int-rep
632 temp: temp1/int-rep temp2/int-rep ;
634 INSN: ##write-barrier-imm
637 temp: temp1/int-rep temp2/int-rep ;
641 literal: symbol library ;
645 literal: field-name ;
649 literal: params stack-frame ;
651 INSN: ##alien-indirect
652 literal: params stack-frame ;
654 INSN: ##alien-callback
655 literal: params stack-frame ;
657 INSN: ##callback-return
660 ! Instructions used by CFG IR only.
671 INSN: ##compare-branch
672 use: src1/int-rep src2/int-rep
675 INSN: ##compare-imm-branch
682 use: src1/int-rep src2/int-rep
686 PURE-INSN: ##compare-imm
693 INSN: ##compare-float-ordered-branch
694 use: src1/double-rep src2/double-rep
697 INSN: ##compare-float-unordered-branch
698 use: src1/double-rep src2/double-rep
701 PURE-INSN: ##compare-float-ordered
703 use: src1/double-rep src2/double-rep
707 PURE-INSN: ##compare-float-unordered
709 use: src1/double-rep src2/double-rep
713 ! Overflowing arithmetic
716 use: src1/int-rep src2/int-rep ;
720 use: src1/int-rep src2/int-rep ;
724 use: src1/int-rep src2/int-rep ;
727 temp: temp1/int-rep temp2/int-rep
728 literal: size data-values tagged-values uninitialized-locs ;
731 temp: temp1/int-rep temp2/int-rep
732 literal: callback-allowed? ;
734 ! Instructions used by machine IR only.
736 literal: stack-frame ;
739 literal: stack-frame ;
753 INSN: _dispatch-label
756 INSN: _compare-branch
758 use: src1/int-rep src2/int-rep
761 INSN: _compare-imm-branch
767 INSN: _compare-float-unordered-branch
769 use: src1/int-rep src2/int-rep
772 INSN: _compare-float-ordered-branch
774 use: src1/int-rep src2/int-rep
777 ! Overflowing arithmetic
781 use: src1/int-rep src2/int-rep ;
786 use: src1/int-rep src2/int-rep ;
791 use: src1/int-rep src2/int-rep ;
793 TUPLE: spill-slot { n integer } ;
794 C: <spill-slot> spill-slot
796 ! These instructions operate on machine registers and not
806 INSN: _spill-area-size
812 ##box-displaced-alien ;
815 UNION: ##read ##slot ##slot-imm ##vm-field-ptr ##alien-global ;
816 UNION: ##write ##set-slot ##set-slot-imm ;
818 ! Instructions that kill all live vregs but cannot trigger GC
819 UNION: partial-sync-insn
820 ##unary-float-function
821 ##binary-float-function ;
823 ! Instructions that kill all live vregs
824 UNION: kill-vreg-insn
832 ! Instructions that have complex expansions and require that the
833 ! output registers are not equal to any of the input registers
834 UNION: def-is-use-insn
836 ##box-displaced-alien
845 "insn-slots" word-prop [ type>> { def use temp } member-eq? ] any?
848 ] with-compilation-unit