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
76 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 ;
197 ! Bignum/integer conversion
198 PURE-INSN: ##integer>bignum
203 PURE-INSN: ##bignum>integer
209 PURE-INSN: ##unbox-float
213 PURE-INSN: ##box-float
218 PURE-INSN: ##add-float
220 use: src1/double-rep src2/double-rep ;
222 PURE-INSN: ##sub-float
224 use: src1/double-rep src2/double-rep ;
226 PURE-INSN: ##mul-float
228 use: src1/double-rep src2/double-rep ;
230 PURE-INSN: ##div-float
232 use: src1/double-rep src2/double-rep ;
234 PURE-INSN: ##min-float
236 use: src1/double-rep src2/double-rep ;
238 PURE-INSN: ##max-float
240 use: src1/double-rep src2/double-rep ;
244 use: src/double-rep ;
247 PURE-INSN: ##unary-float-function
252 PURE-INSN: ##binary-float-function
254 use: src1/double-rep src2/double-rep
257 ! Single/double float conversion
258 PURE-INSN: ##single>double-float
262 PURE-INSN: ##double>single-float
264 use: src/double-rep ;
266 ! Float/integer conversion
267 PURE-INSN: ##float>integer
269 use: src/double-rep ;
271 PURE-INSN: ##integer>float
277 PURE-INSN: ##box-vector
283 PURE-INSN: ##unbox-vector
288 PURE-INSN: ##broadcast-vector
293 PURE-INSN: ##gather-vector-2
295 use: src1/scalar-rep src2/scalar-rep
298 PURE-INSN: ##gather-vector-4
300 use: src1/scalar-rep src2/scalar-rep src3/scalar-rep src4/scalar-rep
303 PURE-INSN: ##add-vector
308 PURE-INSN: ##saturated-add-vector
313 PURE-INSN: ##add-sub-vector
318 PURE-INSN: ##sub-vector
323 PURE-INSN: ##saturated-sub-vector
328 PURE-INSN: ##mul-vector
333 PURE-INSN: ##saturated-mul-vector
338 PURE-INSN: ##div-vector
343 PURE-INSN: ##min-vector
348 PURE-INSN: ##max-vector
353 PURE-INSN: ##horizontal-add-vector
358 PURE-INSN: ##abs-vector
363 PURE-INSN: ##sqrt-vector
368 PURE-INSN: ##and-vector
373 PURE-INSN: ##or-vector
378 PURE-INSN: ##xor-vector
383 ! Boxing and unboxing aliens
384 PURE-INSN: ##box-alien
389 PURE-INSN: ##box-displaced-alien
391 use: displacement/int-rep base/int-rep
392 temp: temp1/int-rep temp2/int-rep
393 literal: base-class ;
395 PURE-INSN: ##unbox-any-c-ptr
400 : ##unbox-f ( dst src -- ) drop 0 ##load-immediate ;
401 : ##unbox-byte-array ( dst src -- ) byte-array-offset ##add-imm ;
403 PURE-INSN: ##unbox-alien
407 : ##unbox-c-ptr ( dst src class temp -- )
409 { [ over \ f class<= ] [ 2drop ##unbox-f ] }
410 { [ over simple-alien class<= ] [ 2drop ##unbox-alien ] }
411 { [ over byte-array class<= ] [ 2drop ##unbox-byte-array ] }
412 [ nip ##unbox-any-c-ptr ]
416 INSN: ##alien-unsigned-1
420 INSN: ##alien-unsigned-2
424 INSN: ##alien-unsigned-4
428 INSN: ##alien-signed-1
432 INSN: ##alien-signed-2
436 INSN: ##alien-signed-4
457 INSN: ##set-alien-integer-1
458 use: src/int-rep value/int-rep ;
460 INSN: ##set-alien-integer-2
461 use: src/int-rep value/int-rep ;
463 INSN: ##set-alien-integer-4
464 use: src/int-rep value/int-rep ;
466 INSN: ##set-alien-cell
467 use: src/int-rep value/int-rep ;
469 INSN: ##set-alien-float
470 use: src/int-rep value/float-rep ;
472 INSN: ##set-alien-double
473 use: src/int-rep value/double-rep ;
475 INSN: ##set-alien-vector
476 use: src/int-rep value
485 INSN: ##write-barrier
487 temp: card#/int-rep table/int-rep ;
491 literal: symbol library ;
495 literal: field-name ;
499 literal: params stack-frame ;
501 INSN: ##alien-indirect
502 literal: params stack-frame ;
504 INSN: ##alien-callback
505 literal: params stack-frame ;
507 INSN: ##callback-return
510 ! Instructions used by CFG IR only.
521 INSN: ##compare-branch
522 use: src1/int-rep src2/int-rep
525 INSN: ##compare-imm-branch
532 use: src1/int-rep src2/int-rep
536 PURE-INSN: ##compare-imm
543 INSN: ##compare-float-ordered-branch
544 use: src1/double-rep src2/double-rep
547 INSN: ##compare-float-unordered-branch
548 use: src1/double-rep src2/double-rep
551 PURE-INSN: ##compare-float-ordered
553 use: src1/double-rep src2/double-rep
557 PURE-INSN: ##compare-float-unordered
559 use: src1/double-rep src2/double-rep
563 ! Overflowing arithmetic
566 use: src1/int-rep src2/int-rep ;
570 use: src1/int-rep src2/int-rep ;
574 use: src1/int-rep src2/int-rep ;
577 temp: temp1/int-rep temp2/int-rep
578 literal: data-values tagged-values uninitialized-locs ;
581 temp: temp1/int-rep temp2/int-rep
582 literal: callback-allowed? ;
584 ! Instructions used by machine IR only.
586 literal: stack-frame ;
589 literal: stack-frame ;
603 INSN: _dispatch-label
606 INSN: _compare-branch
608 use: src1/int-rep src2/int-rep
611 INSN: _compare-imm-branch
617 INSN: _compare-float-unordered-branch
619 use: src1/int-rep src2/int-rep
622 INSN: _compare-float-ordered-branch
624 use: src1/int-rep src2/int-rep
627 ! Overflowing arithmetic
631 use: src1/int-rep src2/int-rep ;
636 use: src1/int-rep src2/int-rep ;
641 use: src1/int-rep src2/int-rep ;
643 TUPLE: spill-slot n ; C: <spill-slot> spill-slot
647 literal: data-values tagged-values uninitialized-locs ;
649 ! These instructions operate on machine registers and not
659 INSN: _spill-area-size
667 ##box-displaced-alien
671 UNION: ##read ##slot ##slot-imm ;
672 UNION: ##write ##set-slot ##set-slot-imm ;
674 ! Instructions that kill all live vregs but cannot trigger GC
675 UNION: partial-sync-insn
676 ##unary-float-function
677 ##binary-float-function ;
679 ! Instructions that kill all live vregs
680 UNION: kill-vreg-insn
688 ! Instructions that have complex expansions and require that the
689 ! output registers are not equal to any of the input registers
690 UNION: def-is-use-insn
700 "insn-slots" word-prop [ type>> { def use temp } memq? ] any?
703 ] with-compilation-unit