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: ##sub-vector
313 PURE-INSN: ##mul-vector
318 PURE-INSN: ##div-vector
323 PURE-INSN: ##min-vector
328 PURE-INSN: ##max-vector
333 PURE-INSN: ##sqrt-vector
338 PURE-INSN: ##horizontal-add-vector
343 ! Boxing and unboxing aliens
344 PURE-INSN: ##box-alien
349 PURE-INSN: ##box-displaced-alien
351 use: displacement/int-rep base/int-rep
352 temp: temp1/int-rep temp2/int-rep
353 literal: base-class ;
355 PURE-INSN: ##unbox-any-c-ptr
360 : ##unbox-f ( dst src -- ) drop 0 ##load-immediate ;
361 : ##unbox-byte-array ( dst src -- ) byte-array-offset ##add-imm ;
363 PURE-INSN: ##unbox-alien
367 : ##unbox-c-ptr ( dst src class temp -- )
369 { [ over \ f class<= ] [ 2drop ##unbox-f ] }
370 { [ over simple-alien class<= ] [ 2drop ##unbox-alien ] }
371 { [ over byte-array class<= ] [ 2drop ##unbox-byte-array ] }
372 [ nip ##unbox-any-c-ptr ]
376 INSN: ##alien-unsigned-1
380 INSN: ##alien-unsigned-2
384 INSN: ##alien-unsigned-4
388 INSN: ##alien-signed-1
392 INSN: ##alien-signed-2
396 INSN: ##alien-signed-4
417 INSN: ##set-alien-integer-1
418 use: src/int-rep value/int-rep ;
420 INSN: ##set-alien-integer-2
421 use: src/int-rep value/int-rep ;
423 INSN: ##set-alien-integer-4
424 use: src/int-rep value/int-rep ;
426 INSN: ##set-alien-cell
427 use: src/int-rep value/int-rep ;
429 INSN: ##set-alien-float
430 use: src/int-rep value/float-rep ;
432 INSN: ##set-alien-double
433 use: src/int-rep value/double-rep ;
435 INSN: ##set-alien-vector
436 use: src/int-rep value
445 INSN: ##write-barrier
447 temp: card#/int-rep table/int-rep ;
451 literal: symbol library ;
455 literal: params stack-frame ;
457 INSN: ##alien-indirect
458 literal: params stack-frame ;
460 INSN: ##alien-callback
461 literal: params stack-frame ;
463 INSN: ##callback-return
466 ! Instructions used by CFG IR only.
477 INSN: ##compare-branch
478 use: src1/int-rep src2/int-rep
481 INSN: ##compare-imm-branch
488 use: src1/int-rep src2/int-rep
492 PURE-INSN: ##compare-imm
499 INSN: ##compare-float-ordered-branch
500 use: src1/double-rep src2/double-rep
503 INSN: ##compare-float-unordered-branch
504 use: src1/double-rep src2/double-rep
507 PURE-INSN: ##compare-float-ordered
509 use: src1/double-rep src2/double-rep
513 PURE-INSN: ##compare-float-unordered
515 use: src1/double-rep src2/double-rep
519 ! Overflowing arithmetic
522 use: src1/int-rep src2/int-rep ;
526 use: src1/int-rep src2/int-rep ;
530 use: src1/int-rep src2/int-rep ;
533 temp: temp1/int-rep temp2/int-rep
534 literal: data-values tagged-values uninitialized-locs ;
537 temp: temp1/int-rep temp2/int-rep
538 literal: callback-allowed? ;
540 ! Instructions used by machine IR only.
542 literal: stack-frame ;
545 literal: stack-frame ;
559 INSN: _dispatch-label
562 INSN: _compare-branch
564 use: src1/int-rep src2/int-rep
567 INSN: _compare-imm-branch
573 INSN: _compare-float-unordered-branch
575 use: src1/int-rep src2/int-rep
578 INSN: _compare-float-ordered-branch
580 use: src1/int-rep src2/int-rep
583 ! Overflowing arithmetic
587 use: src1/int-rep src2/int-rep ;
592 use: src1/int-rep src2/int-rep ;
597 use: src1/int-rep src2/int-rep ;
599 TUPLE: spill-slot n ; C: <spill-slot> spill-slot
603 literal: data-values tagged-values uninitialized-locs ;
605 ! These instructions operate on machine registers and not
615 INSN: _spill-area-size
623 ##box-displaced-alien
627 UNION: ##read ##slot ##slot-imm ;
628 UNION: ##write ##set-slot ##set-slot-imm ;
630 ! Instructions that kill all live vregs but cannot trigger GC
631 UNION: partial-sync-insn
632 ##unary-float-function
633 ##binary-float-function ;
635 ! Instructions that kill all live vregs
636 UNION: kill-vreg-insn
644 ! Instructions that have complex expansions and require that the
645 ! output registers are not equal to any of the input registers
646 UNION: def-is-use-insn
656 "insn-slots" word-prop [ type>> { def use temp } memq? ] any?
659 ] with-compilation-unit