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
55 ! Dummy instruction that simply inhibits TCO
66 use: obj/int-rep slot/int-rep ;
74 use: src/int-rep obj/int-rep slot/int-rep ;
77 use: src/int-rep obj/int-rep
80 ! String element access
83 use: obj/int-rep index/int-rep
86 INSN: ##set-string-nth-fast
87 use: src/int-rep obj/int-rep index/int-rep
98 use: src1/int-rep src2/int-rep ;
107 use: src1/int-rep src2/int-rep ;
116 use: src1/int-rep src2/int-rep ;
125 use: src1/int-rep src2/int-rep ;
134 use: src1/int-rep src2/int-rep ;
143 use: src1/int-rep src2/int-rep ;
152 use: src1/int-rep src2/int-rep ;
161 use: src1/int-rep src2/int-rep ;
170 use: src1/int-rep src2/int-rep ;
179 use: src1/int-rep src2/int-rep ;
183 use: src1/int-rep src2/int-rep ;
193 ! Bignum/integer conversion
194 PURE-INSN: ##integer>bignum
199 PURE-INSN: ##bignum>integer
205 PURE-INSN: ##unbox-float
209 PURE-INSN: ##box-float
214 PURE-INSN: ##add-float
216 use: src1/double-rep src2/double-rep ;
218 PURE-INSN: ##sub-float
220 use: src1/double-rep src2/double-rep ;
222 PURE-INSN: ##mul-float
224 use: src1/double-rep src2/double-rep ;
226 PURE-INSN: ##div-float
228 use: src1/double-rep src2/double-rep ;
230 PURE-INSN: ##min-float
232 use: src1/double-rep src2/double-rep ;
234 PURE-INSN: ##max-float
236 use: src1/double-rep src2/double-rep ;
240 use: src/double-rep ;
243 PURE-INSN: ##unary-float-function
248 PURE-INSN: ##binary-float-function
250 use: src1/double-rep src2/double-rep
253 ! Single/double float conversion
254 PURE-INSN: ##single>double-float
258 PURE-INSN: ##double>single-float
260 use: src/double-rep ;
262 ! Float/integer conversion
263 PURE-INSN: ##float>integer
265 use: src/double-rep ;
267 PURE-INSN: ##integer>float
273 PURE-INSN: ##box-vector
279 PURE-INSN: ##unbox-vector
284 PURE-INSN: ##broadcast-vector
289 PURE-INSN: ##gather-vector-2
291 use: src1/scalar-rep src2/scalar-rep
294 PURE-INSN: ##gather-vector-4
296 use: src1/scalar-rep src2/scalar-rep src3/scalar-rep src4/scalar-rep
299 PURE-INSN: ##add-vector
304 PURE-INSN: ##saturated-add-vector
309 PURE-INSN: ##add-sub-vector
314 PURE-INSN: ##sub-vector
319 PURE-INSN: ##saturated-sub-vector
324 PURE-INSN: ##mul-vector
329 PURE-INSN: ##saturated-mul-vector
334 PURE-INSN: ##div-vector
339 PURE-INSN: ##min-vector
344 PURE-INSN: ##max-vector
349 PURE-INSN: ##horizontal-add-vector
354 PURE-INSN: ##abs-vector
359 PURE-INSN: ##sqrt-vector
364 PURE-INSN: ##and-vector
369 PURE-INSN: ##or-vector
374 PURE-INSN: ##xor-vector
379 PURE-INSN: ##shl-vector
381 use: src1 src2/scalar-rep
384 PURE-INSN: ##shr-vector
386 use: src1 src2/scalar-rep
389 ! Scalar/integer conversion
390 PURE-INSN: ##scalar>integer
395 PURE-INSN: ##integer>scalar
400 ! Boxing and unboxing aliens
401 PURE-INSN: ##box-alien
406 PURE-INSN: ##box-displaced-alien
408 use: displacement/int-rep base/int-rep
409 temp: temp1/int-rep temp2/int-rep
410 literal: base-class ;
412 PURE-INSN: ##unbox-any-c-ptr
417 : ##unbox-f ( dst src -- ) drop 0 ##load-immediate ;
418 : ##unbox-byte-array ( dst src -- ) byte-array-offset ##add-imm ;
420 PURE-INSN: ##unbox-alien
424 : ##unbox-c-ptr ( dst src class temp -- )
426 { [ over \ f class<= ] [ 2drop ##unbox-f ] }
427 { [ over simple-alien class<= ] [ 2drop ##unbox-alien ] }
428 { [ over byte-array class<= ] [ 2drop ##unbox-byte-array ] }
429 [ nip ##unbox-any-c-ptr ]
433 INSN: ##alien-unsigned-1
437 INSN: ##alien-unsigned-2
441 INSN: ##alien-unsigned-4
445 INSN: ##alien-signed-1
449 INSN: ##alien-signed-2
453 INSN: ##alien-signed-4
474 INSN: ##set-alien-integer-1
475 use: src/int-rep value/int-rep ;
477 INSN: ##set-alien-integer-2
478 use: src/int-rep value/int-rep ;
480 INSN: ##set-alien-integer-4
481 use: src/int-rep value/int-rep ;
483 INSN: ##set-alien-cell
484 use: src/int-rep value/int-rep ;
486 INSN: ##set-alien-float
487 use: src/int-rep value/float-rep ;
489 INSN: ##set-alien-double
490 use: src/int-rep value/double-rep ;
492 INSN: ##set-alien-vector
493 use: src/int-rep value
502 INSN: ##write-barrier
504 temp: card#/int-rep table/int-rep ;
508 literal: symbol library ;
512 literal: field-name ;
516 literal: params stack-frame ;
518 INSN: ##alien-indirect
519 literal: params stack-frame ;
521 INSN: ##alien-callback
522 literal: params stack-frame ;
524 INSN: ##callback-return
527 ! Instructions used by CFG IR only.
538 INSN: ##compare-branch
539 use: src1/int-rep src2/int-rep
542 INSN: ##compare-imm-branch
549 use: src1/int-rep src2/int-rep
553 PURE-INSN: ##compare-imm
560 INSN: ##compare-float-ordered-branch
561 use: src1/double-rep src2/double-rep
564 INSN: ##compare-float-unordered-branch
565 use: src1/double-rep src2/double-rep
568 PURE-INSN: ##compare-float-ordered
570 use: src1/double-rep src2/double-rep
574 PURE-INSN: ##compare-float-unordered
576 use: src1/double-rep src2/double-rep
580 ! Overflowing arithmetic
583 use: src1/int-rep src2/int-rep ;
587 use: src1/int-rep src2/int-rep ;
591 use: src1/int-rep src2/int-rep ;
594 temp: temp1/int-rep temp2/int-rep
595 literal: data-values tagged-values uninitialized-locs ;
598 temp: temp1/int-rep temp2/int-rep
599 literal: callback-allowed? ;
601 ! Instructions used by machine IR only.
603 literal: stack-frame ;
606 literal: stack-frame ;
620 INSN: _dispatch-label
623 INSN: _compare-branch
625 use: src1/int-rep src2/int-rep
628 INSN: _compare-imm-branch
634 INSN: _compare-float-unordered-branch
636 use: src1/int-rep src2/int-rep
639 INSN: _compare-float-ordered-branch
641 use: src1/int-rep src2/int-rep
644 ! Overflowing arithmetic
648 use: src1/int-rep src2/int-rep ;
653 use: src1/int-rep src2/int-rep ;
658 use: src1/int-rep src2/int-rep ;
660 TUPLE: spill-slot { n integer } ;
661 C: <spill-slot> spill-slot
665 literal: data-values tagged-values uninitialized-locs ;
667 ! These instructions operate on machine registers and not
677 INSN: _spill-area-size
685 ##box-displaced-alien
689 UNION: ##read ##slot ##slot-imm ;
690 UNION: ##write ##set-slot ##set-slot-imm ;
692 ! Instructions that kill all live vregs but cannot trigger GC
693 UNION: partial-sync-insn
694 ##unary-float-function
695 ##binary-float-function ;
697 ! Instructions that kill all live vregs
698 UNION: kill-vreg-insn
706 ! Instructions that have complex expansions and require that the
707 ! output registers are not equal to any of the input registers
708 UNION: def-is-use-insn
713 ##unary-float-function
714 ##binary-float-function ;
721 "insn-slots" word-prop [ type>> { def use temp } memq? ] any?
724 ] with-compilation-unit