1 ! Copyright (C) 2008, 2011 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors compiler.cfg.instructions.syntax kernel math
5 IN: compiler.cfg.instructions
9 V{ } clone insn-classes set-global
12 : new-insn ( ... class -- insn ) f swap boa ; inline
16 TUPLE: vreg-insn < insn ;
18 TUPLE: flushable-insn < vreg-insn ;
20 TUPLE: foldable-insn < flushable-insn ;
23 FOLDABLE-INSN: ##load-integer
27 FOLDABLE-INSN: ##load-reference
31 ! These four are inserted by representation selection
32 FLUSHABLE-INSN: ##load-tagged
36 FLUSHABLE-INSN: ##load-float
40 FLUSHABLE-INSN: ##load-double
44 FLUSHABLE-INSN: ##load-vector
49 FLUSHABLE-INSN: ##peek
86 FLUSHABLE-INSN: ##slot
88 use: obj/tagged-rep slot/int-rep
91 FLUSHABLE-INSN: ##slot-imm
97 use: src/tagged-rep obj/tagged-rep slot/int-rep
100 VREG-INSN: ##set-slot-imm
101 use: src/tagged-rep obj/tagged-rep
105 FOLDABLE-INSN: ##copy
110 ! Only used by compiler.cfg.cssa
111 FLUSHABLE-INSN: ##parallel-copy
114 FOLDABLE-INSN: ##tagged>integer
116 use: src/tagged-rep ;
121 use: src1/int-rep src2/int-rep ;
123 FOLDABLE-INSN: ##add-imm
130 use: src1/int-rep src2/int-rep ;
132 FOLDABLE-INSN: ##sub-imm
139 use: src1/int-rep src2/int-rep ;
141 FOLDABLE-INSN: ##mul-imm
148 use: src1/int-rep src2/int-rep ;
150 FOLDABLE-INSN: ##and-imm
157 use: src1/int-rep src2/int-rep ;
159 FOLDABLE-INSN: ##or-imm
166 use: src1/int-rep src2/int-rep ;
168 FOLDABLE-INSN: ##xor-imm
175 use: src1/int-rep src2/int-rep ;
177 FOLDABLE-INSN: ##shl-imm
184 use: src1/int-rep src2/int-rep ;
186 FOLDABLE-INSN: ##shr-imm
193 use: src1/int-rep src2/int-rep ;
195 FOLDABLE-INSN: ##sar-imm
202 use: src1/int-rep src2/int-rep ;
206 use: src1/int-rep src2/int-rep ;
216 FOLDABLE-INSN: ##log2
220 FOLDABLE-INSN: ##bit-count
225 FOLDABLE-INSN: ##add-float
227 use: src1/double-rep src2/double-rep ;
229 FOLDABLE-INSN: ##sub-float
231 use: src1/double-rep src2/double-rep ;
233 FOLDABLE-INSN: ##mul-float
235 use: src1/double-rep src2/double-rep ;
237 FOLDABLE-INSN: ##div-float
239 use: src1/double-rep src2/double-rep ;
241 FOLDABLE-INSN: ##min-float
243 use: src1/double-rep src2/double-rep ;
245 FOLDABLE-INSN: ##max-float
247 use: src1/double-rep src2/double-rep ;
249 FOLDABLE-INSN: ##sqrt
251 use: src/double-rep ;
253 ! Single/double float conversion
254 FOLDABLE-INSN: ##single>double-float
258 FOLDABLE-INSN: ##double>single-float
260 use: src/double-rep ;
262 ! Float/integer conversion
263 FOLDABLE-INSN: ##float>integer
265 use: src/double-rep ;
267 FOLDABLE-INSN: ##integer>float
272 FOLDABLE-INSN: ##zero-vector
276 FOLDABLE-INSN: ##fill-vector
280 FOLDABLE-INSN: ##gather-vector-2
282 use: src1/scalar-rep src2/scalar-rep
285 FOLDABLE-INSN: ##gather-int-vector-2
287 use: src1/int-rep src2/int-rep
290 FOLDABLE-INSN: ##gather-vector-4
292 use: src1/scalar-rep src2/scalar-rep src3/scalar-rep src4/scalar-rep
295 FOLDABLE-INSN: ##gather-int-vector-4
297 use: src1/int-rep src2/int-rep src3/int-rep src4/int-rep
300 FOLDABLE-INSN: ##select-vector
305 FOLDABLE-INSN: ##shuffle-vector
310 FOLDABLE-INSN: ##shuffle-vector-halves-imm
313 literal: shuffle rep ;
315 FOLDABLE-INSN: ##shuffle-vector-imm
318 literal: shuffle rep ;
320 FOLDABLE-INSN: ##tail>head-vector
325 FOLDABLE-INSN: ##merge-vector-head
330 FOLDABLE-INSN: ##merge-vector-tail
335 FOLDABLE-INSN: ##float-pack-vector
340 FOLDABLE-INSN: ##signed-pack-vector
345 FOLDABLE-INSN: ##unsigned-pack-vector
350 FOLDABLE-INSN: ##unpack-vector-head
355 FOLDABLE-INSN: ##unpack-vector-tail
360 FOLDABLE-INSN: ##integer>float-vector
365 FOLDABLE-INSN: ##float>integer-vector
370 FOLDABLE-INSN: ##compare-vector
375 FOLDABLE-INSN: ##move-vector-mask
380 FOLDABLE-INSN: ##test-vector
386 VREG-INSN: ##test-vector-branch
391 FOLDABLE-INSN: ##add-vector
396 FOLDABLE-INSN: ##saturated-add-vector
401 FOLDABLE-INSN: ##add-sub-vector
406 FOLDABLE-INSN: ##sub-vector
411 FOLDABLE-INSN: ##saturated-sub-vector
416 FOLDABLE-INSN: ##mul-vector
421 FOLDABLE-INSN: ##mul-high-vector
426 FOLDABLE-INSN: ##mul-horizontal-add-vector
431 FOLDABLE-INSN: ##saturated-mul-vector
436 FOLDABLE-INSN: ##div-vector
441 FOLDABLE-INSN: ##min-vector
446 FOLDABLE-INSN: ##max-vector
451 FOLDABLE-INSN: ##avg-vector
456 FOLDABLE-INSN: ##dot-vector
461 FOLDABLE-INSN: ##sad-vector
466 FOLDABLE-INSN: ##horizontal-add-vector
471 FOLDABLE-INSN: ##horizontal-sub-vector
476 FOLDABLE-INSN: ##horizontal-shl-vector-imm
481 FOLDABLE-INSN: ##horizontal-shr-vector-imm
486 FOLDABLE-INSN: ##abs-vector
491 FOLDABLE-INSN: ##sqrt-vector
496 FOLDABLE-INSN: ##and-vector
501 FOLDABLE-INSN: ##andn-vector
506 FOLDABLE-INSN: ##or-vector
511 FOLDABLE-INSN: ##xor-vector
516 FOLDABLE-INSN: ##not-vector
521 FOLDABLE-INSN: ##shl-vector-imm
526 FOLDABLE-INSN: ##shr-vector-imm
531 FOLDABLE-INSN: ##shl-vector
533 use: src1 src2/int-scalar-rep
536 FOLDABLE-INSN: ##shr-vector
538 use: src1 src2/int-scalar-rep
541 ! Scalar/vector conversion
542 FOLDABLE-INSN: ##scalar>integer
547 FOLDABLE-INSN: ##integer>scalar
552 FOLDABLE-INSN: ##vector>scalar
557 FOLDABLE-INSN: ##scalar>vector
562 ! Boxing and unboxing aliens
563 FOLDABLE-INSN: ##box-alien
568 FOLDABLE-INSN: ##box-displaced-alien
570 use: displacement/int-rep base/tagged-rep
572 literal: base-class ;
574 FOLDABLE-INSN: ##unbox-any-c-ptr
576 use: src/tagged-rep ;
578 FOLDABLE-INSN: ##unbox-alien
580 use: src/tagged-rep ;
582 ! Zero-extending and sign-extending integers
583 FOLDABLE-INSN: ##convert-integer
588 ! Raw memory accessors
589 FLUSHABLE-INSN: ##load-memory
591 use: base/int-rep displacement/int-rep
592 literal: scale offset rep c-type ;
594 FLUSHABLE-INSN: ##load-memory-imm
597 literal: offset rep c-type ;
599 VREG-INSN: ##store-memory
600 use: src base/int-rep displacement/int-rep
601 literal: scale offset rep c-type ;
603 VREG-INSN: ##store-memory-imm
604 use: src base/int-rep
605 literal: offset rep c-type ;
608 FLUSHABLE-INSN: ##allot
610 literal: size class-of
613 VREG-INSN: ##write-barrier
614 use: src/tagged-rep slot/int-rep
616 temp: temp1/int-rep temp2/int-rep ;
618 VREG-INSN: ##write-barrier-imm
621 temp: temp1/int-rep temp2/int-rep ;
623 FLUSHABLE-INSN: ##alien-global
625 literal: symbol library ;
627 FLUSHABLE-INSN: ##vm-field
631 VREG-INSN: ##set-vm-field
636 FOLDABLE-INSN: ##unbox
639 literal: unboxer rep ;
641 FOLDABLE-INSN: ##unbox-long-long
642 def: dst1/int-rep dst2/int-rep
646 FLUSHABLE-INSN: ##local-allot
648 literal: size align offset ;
653 literal: boxer rep gc-map ;
655 FOLDABLE-INSN: ##box-long-long
657 use: src1/int-rep src2/int-rep
658 literal: boxer gc-map ;
660 ! Alien call inputs and outputs are arrays of triples with shape
661 ! { vreg rep stack#/reg }
663 VREG-INSN: ##alien-invoke
664 literal: reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size symbols dll gc-map ;
666 VREG-INSN: ##alien-indirect
668 literal: reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size gc-map ;
670 VREG-INSN: ##alien-assembly
671 literal: reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size quot ;
673 VREG-INSN: ##callback-inputs
674 literal: reg-outputs stack-outputs ;
676 VREG-INSN: ##callback-outputs
677 literal: reg-inputs ;
680 FLUSHABLE-INSN: ##phi
686 ! Tagged conditionals
687 VREG-INSN: ##compare-branch
688 use: src1/tagged-rep src2/tagged-rep
691 VREG-INSN: ##compare-imm-branch
695 FOLDABLE-INSN: ##compare
697 use: src1/tagged-rep src2/tagged-rep
701 FOLDABLE-INSN: ##compare-imm
707 ! Integer conditionals
708 VREG-INSN: ##compare-integer-branch
709 use: src1/int-rep src2/int-rep
712 VREG-INSN: ##compare-integer-imm-branch
716 VREG-INSN: ##test-branch
717 use: src1/int-rep src2/int-rep
720 VREG-INSN: ##test-imm-branch
724 FOLDABLE-INSN: ##compare-integer
726 use: src1/int-rep src2/int-rep
730 FOLDABLE-INSN: ##compare-integer-imm
736 FOLDABLE-INSN: ##test
738 use: src1/int-rep src2/int-rep
742 FOLDABLE-INSN: ##test-imm
749 VREG-INSN: ##compare-float-ordered-branch
750 use: src1/double-rep src2/double-rep
753 VREG-INSN: ##compare-float-unordered-branch
754 use: src1/double-rep src2/double-rep
757 FOLDABLE-INSN: ##compare-float-ordered
759 use: src1/double-rep src2/double-rep
763 FOLDABLE-INSN: ##compare-float-unordered
765 use: src1/double-rep src2/double-rep
769 ! Overflowing arithmetic
770 VREG-INSN: ##fixnum-add
772 use: src1/tagged-rep src2/tagged-rep
775 VREG-INSN: ##fixnum-sub
777 use: src1/tagged-rep src2/tagged-rep
780 VREG-INSN: ##fixnum-mul
782 use: src1/tagged-rep src2/int-rep
785 VREG-INSN: ##save-context
786 temp: temp1/int-rep temp2/int-rep ;
789 VREG-INSN: ##check-nursery-branch
791 temp: temp1/int-rep temp2/int-rep ;
796 ! Spills and reloads, inserted by register allocator
797 TUPLE: spill-slot { n integer } ;
798 C: <spill-slot> spill-slot
811 ##box-displaced-alien ;
813 UNION: conditional-branch-insn
816 ##compare-integer-branch
817 ##compare-integer-imm-branch
820 ##compare-float-ordered-branch
821 ##compare-float-unordered-branch
823 ##check-nursery-branch
829 UNION: ##read ##slot ##slot-imm ##vm-field ##alien-global ;
830 UNION: ##write ##set-slot ##set-slot-imm ##set-vm-field ;
832 UNION: alien-call-insn
844 M: gc-map-insn clone call-next-method [ clone ] change-gc-map ;
846 TUPLE: gc-map scrub-d scrub-r gc-roots derived-roots ;
848 : <gc-map> ( -- gc-map ) gc-map new ;
850 ! Instructions that clobber registers. They receive inputs and
851 ! produce outputs in spill slots.
852 UNION: hairy-clobber-insn
859 ! Instructions that clobber registers but are allowed to produce
860 ! outputs in registers. Inputs are in spill slots, except for
861 ! inputs coalesced with the output, in which case that input
862 ! will be in a register.
869 UNION: def-is-use-insn
871 ##box-displaced-alien