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: ##sqrt-vector
358 PURE-INSN: ##horizontal-add-vector
363 ! Boxing and unboxing aliens
364 PURE-INSN: ##box-alien
369 PURE-INSN: ##box-displaced-alien
371 use: displacement/int-rep base/int-rep
372 temp: temp1/int-rep temp2/int-rep
373 literal: base-class ;
375 PURE-INSN: ##unbox-any-c-ptr
380 : ##unbox-f ( dst src -- ) drop 0 ##load-immediate ;
381 : ##unbox-byte-array ( dst src -- ) byte-array-offset ##add-imm ;
383 PURE-INSN: ##unbox-alien
387 : ##unbox-c-ptr ( dst src class temp -- )
389 { [ over \ f class<= ] [ 2drop ##unbox-f ] }
390 { [ over simple-alien class<= ] [ 2drop ##unbox-alien ] }
391 { [ over byte-array class<= ] [ 2drop ##unbox-byte-array ] }
392 [ nip ##unbox-any-c-ptr ]
396 INSN: ##alien-unsigned-1
400 INSN: ##alien-unsigned-2
404 INSN: ##alien-unsigned-4
408 INSN: ##alien-signed-1
412 INSN: ##alien-signed-2
416 INSN: ##alien-signed-4
437 INSN: ##set-alien-integer-1
438 use: src/int-rep value/int-rep ;
440 INSN: ##set-alien-integer-2
441 use: src/int-rep value/int-rep ;
443 INSN: ##set-alien-integer-4
444 use: src/int-rep value/int-rep ;
446 INSN: ##set-alien-cell
447 use: src/int-rep value/int-rep ;
449 INSN: ##set-alien-float
450 use: src/int-rep value/float-rep ;
452 INSN: ##set-alien-double
453 use: src/int-rep value/double-rep ;
455 INSN: ##set-alien-vector
456 use: src/int-rep value
465 INSN: ##write-barrier
467 temp: card#/int-rep table/int-rep ;
471 literal: symbol library ;
479 literal: params stack-frame ;
481 INSN: ##alien-indirect
482 literal: params stack-frame ;
484 INSN: ##alien-callback
485 literal: params stack-frame ;
487 INSN: ##callback-return
490 ! Instructions used by CFG IR only.
501 INSN: ##compare-branch
502 use: src1/int-rep src2/int-rep
505 INSN: ##compare-imm-branch
512 use: src1/int-rep src2/int-rep
516 PURE-INSN: ##compare-imm
523 INSN: ##compare-float-ordered-branch
524 use: src1/double-rep src2/double-rep
527 INSN: ##compare-float-unordered-branch
528 use: src1/double-rep src2/double-rep
531 PURE-INSN: ##compare-float-ordered
533 use: src1/double-rep src2/double-rep
537 PURE-INSN: ##compare-float-unordered
539 use: src1/double-rep src2/double-rep
543 ! Overflowing arithmetic
546 use: src1/int-rep src2/int-rep ;
550 use: src1/int-rep src2/int-rep ;
554 use: src1/int-rep src2/int-rep ;
557 temp: temp1/int-rep temp2/int-rep
558 literal: data-values tagged-values uninitialized-locs ;
561 temp: temp1/int-rep temp2/int-rep
562 literal: callback-allowed? ;
564 ! Instructions used by machine IR only.
566 literal: stack-frame ;
569 literal: stack-frame ;
583 INSN: _dispatch-label
586 INSN: _compare-branch
588 use: src1/int-rep src2/int-rep
591 INSN: _compare-imm-branch
597 INSN: _compare-float-unordered-branch
599 use: src1/int-rep src2/int-rep
602 INSN: _compare-float-ordered-branch
604 use: src1/int-rep src2/int-rep
607 ! Overflowing arithmetic
611 use: src1/int-rep src2/int-rep ;
616 use: src1/int-rep src2/int-rep ;
621 use: src1/int-rep src2/int-rep ;
623 TUPLE: spill-slot n ; C: <spill-slot> spill-slot
627 literal: data-values tagged-values uninitialized-locs ;
629 ! These instructions operate on machine registers and not
639 INSN: _spill-area-size
647 ##box-displaced-alien
651 UNION: ##read ##slot ##slot-imm ;
652 UNION: ##write ##set-slot ##set-slot-imm ;
654 ! Instructions that kill all live vregs but cannot trigger GC
655 UNION: partial-sync-insn
656 ##unary-float-function
657 ##binary-float-function ;
659 ! Instructions that kill all live vregs
660 UNION: kill-vreg-insn
668 ! Instructions that have complex expansions and require that the
669 ! output registers are not equal to any of the input registers
670 UNION: def-is-use-insn
680 "insn-slots" word-prop [ type>> { def use temp } memq? ] any?
683 ] with-compilation-unit