1 ! Copyright (C) 2008, 2011 Slava Pestov.
2 ! See https://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
89 FLUSHABLE-INSN: ##slot
91 use: obj/tagged-rep slot/int-rep
94 FLUSHABLE-INSN: ##slot-imm
100 use: src/tagged-rep obj/tagged-rep slot/int-rep
103 VREG-INSN: ##set-slot-imm
104 use: src/tagged-rep obj/tagged-rep
108 FOLDABLE-INSN: ##copy
113 ! Only used by compiler.cfg.cssa
114 FLUSHABLE-INSN: ##parallel-copy
117 FOLDABLE-INSN: ##tagged>integer
119 use: src/tagged-rep ;
124 use: src1/int-rep src2/int-rep ;
126 FOLDABLE-INSN: ##add-imm
133 use: src1/int-rep src2/int-rep ;
135 FOLDABLE-INSN: ##sub-imm
142 use: src1/int-rep src2/int-rep ;
144 FOLDABLE-INSN: ##mul-imm
151 use: src1/int-rep src2/int-rep ;
153 FOLDABLE-INSN: ##and-imm
160 use: src1/int-rep src2/int-rep ;
162 FOLDABLE-INSN: ##or-imm
169 use: src1/int-rep src2/int-rep ;
171 FOLDABLE-INSN: ##xor-imm
178 use: src1/int-rep src2/int-rep ;
180 FOLDABLE-INSN: ##shl-imm
187 use: src1/int-rep src2/int-rep ;
189 FOLDABLE-INSN: ##shr-imm
196 use: src1/int-rep src2/int-rep ;
198 FOLDABLE-INSN: ##sar-imm
205 use: src1/int-rep src2/int-rep ;
209 use: src1/int-rep src2/int-rep ;
219 FOLDABLE-INSN: ##log2
223 FOLDABLE-INSN: ##bit-count
227 FOLDABLE-INSN: ##bit-test
229 use: src1/int-rep src2/int-rep
233 FOLDABLE-INSN: ##add-float
235 use: src1/double-rep src2/double-rep ;
237 FOLDABLE-INSN: ##sub-float
239 use: src1/double-rep src2/double-rep ;
241 FOLDABLE-INSN: ##mul-float
243 use: src1/double-rep src2/double-rep ;
245 FOLDABLE-INSN: ##div-float
247 use: src1/double-rep src2/double-rep ;
249 FOLDABLE-INSN: ##min-float
251 use: src1/double-rep src2/double-rep ;
253 FOLDABLE-INSN: ##max-float
255 use: src1/double-rep src2/double-rep ;
257 FOLDABLE-INSN: ##sqrt
259 use: src/double-rep ;
261 ! Single/double float conversion
262 FOLDABLE-INSN: ##single>double-float
266 FOLDABLE-INSN: ##double>single-float
268 use: src/double-rep ;
270 ! Float/integer conversion
271 FOLDABLE-INSN: ##float>integer
273 use: src/double-rep ;
275 FOLDABLE-INSN: ##integer>float
280 FOLDABLE-INSN: ##zero-vector
284 FOLDABLE-INSN: ##fill-vector
288 FOLDABLE-INSN: ##gather-vector-2
290 use: src1/scalar-rep src2/scalar-rep
293 FOLDABLE-INSN: ##gather-int-vector-2
295 use: src1/int-rep src2/int-rep
298 FOLDABLE-INSN: ##gather-vector-4
300 use: src1/scalar-rep src2/scalar-rep src3/scalar-rep src4/scalar-rep
303 FOLDABLE-INSN: ##gather-int-vector-4
305 use: src1/int-rep src2/int-rep src3/int-rep src4/int-rep
308 FOLDABLE-INSN: ##select-vector
313 FOLDABLE-INSN: ##shuffle-vector
318 FOLDABLE-INSN: ##shuffle-vector-halves-imm
321 literal: shuffle rep ;
323 FOLDABLE-INSN: ##shuffle-vector-imm
326 literal: shuffle rep ;
328 FOLDABLE-INSN: ##tail>head-vector
333 FOLDABLE-INSN: ##merge-vector-head
338 FOLDABLE-INSN: ##merge-vector-tail
343 FOLDABLE-INSN: ##float-pack-vector
348 FOLDABLE-INSN: ##signed-pack-vector
353 FOLDABLE-INSN: ##unsigned-pack-vector
358 FOLDABLE-INSN: ##unpack-vector-head
363 FOLDABLE-INSN: ##unpack-vector-tail
368 FOLDABLE-INSN: ##integer>float-vector
373 FOLDABLE-INSN: ##float>integer-vector
378 FOLDABLE-INSN: ##compare-vector
383 FOLDABLE-INSN: ##move-vector-mask
388 FOLDABLE-INSN: ##test-vector
394 VREG-INSN: ##test-vector-branch
399 FOLDABLE-INSN: ##add-vector
404 FOLDABLE-INSN: ##saturated-add-vector
409 FOLDABLE-INSN: ##add-sub-vector
414 FOLDABLE-INSN: ##sub-vector
419 FOLDABLE-INSN: ##saturated-sub-vector
424 FOLDABLE-INSN: ##mul-vector
429 FOLDABLE-INSN: ##mul-high-vector
434 FOLDABLE-INSN: ##mul-horizontal-add-vector
439 FOLDABLE-INSN: ##saturated-mul-vector
444 FOLDABLE-INSN: ##div-vector
449 FOLDABLE-INSN: ##min-vector
454 FOLDABLE-INSN: ##max-vector
459 FOLDABLE-INSN: ##avg-vector
464 FOLDABLE-INSN: ##dot-vector
469 FOLDABLE-INSN: ##sad-vector
474 FOLDABLE-INSN: ##horizontal-add-vector
479 FOLDABLE-INSN: ##horizontal-sub-vector
484 FOLDABLE-INSN: ##horizontal-shl-vector-imm
489 FOLDABLE-INSN: ##horizontal-shr-vector-imm
494 FOLDABLE-INSN: ##abs-vector
499 FOLDABLE-INSN: ##sqrt-vector
504 FOLDABLE-INSN: ##and-vector
509 FOLDABLE-INSN: ##andn-vector
514 FOLDABLE-INSN: ##or-vector
519 FOLDABLE-INSN: ##xor-vector
524 FOLDABLE-INSN: ##not-vector
529 FOLDABLE-INSN: ##shl-vector-imm
534 FOLDABLE-INSN: ##shr-vector-imm
539 FOLDABLE-INSN: ##shl-vector
541 use: src1 src2/int-scalar-rep
544 FOLDABLE-INSN: ##shr-vector
546 use: src1 src2/int-scalar-rep
549 ! Scalar/vector conversion
550 FOLDABLE-INSN: ##scalar>integer
555 FOLDABLE-INSN: ##integer>scalar
560 FOLDABLE-INSN: ##vector>scalar
565 FOLDABLE-INSN: ##scalar>vector
570 ! Boxing and unboxing aliens
571 FOLDABLE-INSN: ##box-alien
576 FOLDABLE-INSN: ##box-displaced-alien
578 use: displacement/int-rep base/tagged-rep
580 literal: base-class ;
582 FOLDABLE-INSN: ##unbox-any-c-ptr
584 use: src/tagged-rep ;
586 FOLDABLE-INSN: ##unbox-alien
588 use: src/tagged-rep ;
590 ! Zero-extending and sign-extending integers
591 FOLDABLE-INSN: ##convert-integer
596 ! Raw memory accessors
597 FLUSHABLE-INSN: ##load-memory
599 use: base/int-rep displacement/int-rep
600 literal: scale offset rep c-type ;
602 FLUSHABLE-INSN: ##load-memory-imm
605 literal: offset rep c-type ;
607 VREG-INSN: ##store-memory
608 use: src base/int-rep displacement/int-rep
609 literal: scale offset rep c-type ;
611 VREG-INSN: ##store-memory-imm
612 use: src base/int-rep
613 literal: offset rep c-type ;
616 FLUSHABLE-INSN: ##allot
618 literal: size class-of
621 VREG-INSN: ##write-barrier
622 use: src/tagged-rep slot/int-rep
624 temp: temp1/int-rep temp2/int-rep ;
626 VREG-INSN: ##write-barrier-imm
629 temp: temp1/int-rep temp2/int-rep ;
631 FLUSHABLE-INSN: ##alien-global
633 literal: symbol library ;
635 FLUSHABLE-INSN: ##vm-field
639 VREG-INSN: ##set-vm-field
644 FOLDABLE-INSN: ##unbox
647 literal: unboxer rep ;
649 FOLDABLE-INSN: ##unbox-long-long
650 def: dst1/int-rep dst2/int-rep
654 FLUSHABLE-INSN: ##local-allot
656 literal: size align offset ;
661 literal: boxer rep gc-map ;
663 FOLDABLE-INSN: ##box-long-long
665 use: src1/int-rep src2/int-rep
666 literal: boxer gc-map ;
668 ! Alien call inputs and outputs are arrays of triples with shape
669 ! { vreg rep stack#/reg }
671 VREG-INSN: ##alien-invoke
672 literal: varargs? reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size symbols dll gc-map ;
674 VREG-INSN: ##alien-indirect
676 literal: varargs? reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size gc-map ;
678 VREG-INSN: ##alien-assembly
679 literal: varargs? reg-inputs stack-inputs reg-outputs dead-outputs cleanup stack-size quot ;
681 VREG-INSN: ##callback-inputs
682 literal: reg-outputs stack-outputs ;
684 VREG-INSN: ##callback-outputs
685 literal: reg-inputs ;
688 FLUSHABLE-INSN: ##phi
694 ! Tagged conditionals
695 VREG-INSN: ##compare-branch
696 use: src1/tagged-rep src2/tagged-rep
699 VREG-INSN: ##compare-imm-branch
703 FOLDABLE-INSN: ##compare
705 use: src1/tagged-rep src2/tagged-rep
709 FOLDABLE-INSN: ##compare-imm
715 ! Integer conditionals
716 VREG-INSN: ##compare-integer-branch
717 use: src1/int-rep src2/int-rep
720 VREG-INSN: ##compare-integer-imm-branch
724 VREG-INSN: ##test-branch
725 use: src1/int-rep src2/int-rep
728 VREG-INSN: ##test-imm-branch
732 FOLDABLE-INSN: ##compare-integer
734 use: src1/int-rep src2/int-rep
738 FOLDABLE-INSN: ##compare-integer-imm
744 FOLDABLE-INSN: ##test
746 use: src1/int-rep src2/int-rep
750 FOLDABLE-INSN: ##test-imm
757 VREG-INSN: ##compare-float-ordered-branch
758 use: src1/double-rep src2/double-rep
761 VREG-INSN: ##compare-float-unordered-branch
762 use: src1/double-rep src2/double-rep
765 FOLDABLE-INSN: ##compare-float-ordered
767 use: src1/double-rep src2/double-rep
771 FOLDABLE-INSN: ##compare-float-unordered
773 use: src1/double-rep src2/double-rep
777 ! Overflowing arithmetic
778 VREG-INSN: ##fixnum-add
780 use: src1/tagged-rep src2/tagged-rep
783 VREG-INSN: ##fixnum-sub
785 use: src1/tagged-rep src2/tagged-rep
788 VREG-INSN: ##fixnum-mul
790 use: src1/tagged-rep src2/int-rep
793 VREG-INSN: ##save-context
794 temp: temp1/int-rep temp2/int-rep ;
797 VREG-INSN: ##check-nursery-branch
799 temp: temp1/int-rep temp2/int-rep ;
804 ! Spills and reloads, inserted by register allocator
805 TUPLE: spill-slot { n integer } ;
806 C: <spill-slot> spill-slot
816 UNION: allocation-insn
819 ##box-displaced-alien ;
821 UNION: conditional-branch-insn
824 ##compare-integer-branch
825 ##compare-integer-imm-branch
828 ##compare-float-ordered-branch
829 ##compare-float-unordered-branch
831 ##check-nursery-branch
837 UNION: read-insn ##slot ##slot-imm ##vm-field ##alien-global ;
838 UNION: write-insn ##set-slot ##set-slot-imm ##set-vm-field ;
840 UNION: alien-call-insn
852 M: gc-map-insn clone call-next-method [ clone ] change-gc-map ;
854 TUPLE: gc-map gc-roots derived-roots ;
856 : <gc-map> ( -- gc-map ) gc-map new ;
858 UNION: def-is-use-insn
860 ##box-displaced-alien