the R5900's coprocessor 2: VU0 in macro mode (its upper and lower instructions issued by the EE core), moves to and from it.
0/1 a fixed bit, name a field, a bit the decoder ignores
qmtc2 rt fs
Move Quadword to VU0 Floating-Point Register
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | rt | fs | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||
(defmips qmtc2 (:asm "qmtc2" rt fs) (:doc "Move Quadword to VU0 Floating-Point Register") (qmtc2-body))
qmtc2.i rt fs
Move Quadword to VU0, Interlocked
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | rt | fs | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | ||||||||
(defmips qmtc2.i (:asm "qmtc2.i" rt fs) (:doc "Move Quadword to VU0, Interlocked") (qmtc2-body))
cfc2 rt is
Move Control from VU0
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | rt | is | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||
(defmips cfc2 (:only :r5900) (:asm "cfc2" rt is) (:doc "Move Control from VU0") (cfc2-body))
cfc2.i rt is
Move Control from VU0, Interlocked
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | rt | is | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | ||||||||
(defmips cfc2.i (:asm "cfc2.i" rt is) (:doc "Move Control from VU0, Interlocked") (cfc2-body))
ctc2 rt is
Move Control to VU0
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | rt | is | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||
(defmips ctc2 (:only :r5900) (:asm "ctc2" rt is) (:doc "Move Control to VU0") (ctc2-body))
ctc2.i rt is
Move Control to VU0, Interlocked
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | rt | is | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | ||||||||
(defmips ctc2.i (:asm "ctc2.i" rt is) (:doc "Move Control to VU0, Interlocked") (ctc2-body))
lqc2 ft (simm imm) rs
Load Quadword to VU0
LQC2, SQC2: "vAddr <- sign_extend(offset) + GPR[base]", a quadword; the low four address bits are ignored as for LQ (PCSX2's memRead128 aligns)
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 1 | 0 | 1 | 1 | 0 | rs | ft | imm | |||||||||||||||||||||||
(defmips lqc2 (:asm "lqc2" ft (simm imm) rs) (:doc "Load Quadword to VU0")
(set-vfq ft (mips-load 128 (logand (vaddr rs imm) #xFFFFFFF0))))
sqc2 ft (simm imm) rs
Store Quadword from VU0
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 | 0 | rs | ft | imm | |||||||||||||||||||||||
(defmips sqc2 (:asm "sqc2" ft (simm imm) rs) (:doc "Store Quadword from VU0")
(mips-store 128 (logand (vaddr rs imm) #xFFFFFFF0) (vfq ft)))
bc2f (b-rel offset)
Branch on COP2 False
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | offset | |||||||||||||||
(defmips bc2f (:only :r5900) (:asm "bc2f" (b-rel offset)) (:doc "Branch on COP2 False")
(when (= (cpcond2) 0) (branch-to (branch-target offset))))
bc2t (b-rel offset)
Branch on COP2 True
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | offset | |||||||||||||||
(defmips bc2t (:only :r5900) (:asm "bc2t" (b-rel offset)) (:doc "Branch on COP2 True")
(when (= (cpcond2) 1) (branch-to (branch-target offset))))
bc2fl (b-rel offset)
Branch on COP2 False Likely
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | offset | |||||||||||||||
(defmips bc2fl (:only :r5900) (:asm "bc2fl" (b-rel offset)) (:doc "Branch on COP2 False Likely")
(if (= (cpcond2) 0) (branch-to (branch-target offset)) (nullify)))
bc2tl (b-rel offset)
Branch on COP2 True Likely
r5900:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | offset | |||||||||||||||
(defmips bc2tl (:only :r5900) (:asm "bc2tl" (b-rel offset)) (:doc "Branch on COP2 True Likely")
(if (= (cpcond2) 1) (branch-to (branch-target offset)) (nullify)))
(defconstant +vu-status+) source(defconstant +vu-status+ 16)(defconstant +vu-mac+) source(defconstant +vu-mac+ 17)(defconstant +vu-clip+) source(defconstant +vu-clip+ 18)(defconstant +vu-r+) source(defconstant +vu-r+ 20)(defconstant +vu-i+) source(defconstant +vu-i+ 21)(defconstant +vu-q+) source(defconstant +vu-q+ 22)(defconstant +vu-tpc+) source(defconstant +vu-tpc+ 26)(defconstant +vu-cmsar0+) source(defconstant +vu-cmsar0+ 27)(defconstant +vu-stat+) source(defconstant +vu-stat+ 29)(defconstant +vu0-mem+) source(defconstant +vu0-mem+ #x11004000)(defmacro vf) source(defmacro vf (r l)
`(if (= ,r 0) (if (= ,l 3) #x3F800000 0) (aref (mips-vf cpu) (+ (* 4 ,r) ,l))))(defmacro set-vf) source(defmacro set-vf (r l v)
`(unless (= ,r 0) (setf (aref (mips-vf cpu) (+ (* 4 ,r) ,l)) (wrap 32 ,v))))(defmacro vacc) source(defmacro vacc (l) `(aref (mips-vacc cpu) ,l))(defmacro vc2) source(defmacro vc2 (n) `(aref (mips-cop2c cpu) ,n))(defmacro vi) source(defmacro vi (n) `(if (= ,n 0) 0 (bit-field (vc2 ,n) 0 16)))(defmacro set-vi) source(defmacro set-vi (n v) `(unless (= ,n 0) (setf (vc2 ,n) (wrap 16 ,v))))(defmacro dest-p) source(defmacro dest-p (l) `(= (bit-at dest ,(- 3 l)) 1))(defmacro vu0-addr) source(defmacro vu0-addr (q l) `(+ +vu0-mem+ (* 16 (wrap 8 ,q)) ,(* 4 l)))(defmacro vu-lane-mac) source(defmacro vu-lane-mac (r l)
(let ((sh (- 3 l)))
`(logior (ash (b2i (= (bit-field ,r 0 31) 0)) ,sh) (ash (bit-at ,r 31) ,(+ 4 sh))
(ash (bit-at ,r 33) ,(+ 8 sh)) (ash (bit-at ,r 32) ,(+ 12 sh)))))(defun vu0-set-mac) source(defun vu0-set-mac (cpu mac)
"MAC <- MAC; Status Z S U O from it, and their sticky bits"
(declare (type mips cpu) (type (unsigned-byte 16) mac))
(let ((new (logior (b2i (/= (logand mac #xF) 0)) (ash (b2i (/= (logand mac #xF0) 0)) 1)
(ash (b2i (/= (logand mac #xF00) 0)) 2) (ash (b2i (/= (logand mac #xF000) 0)) 3))))
(setf (vc2 +vu-mac+) mac
(vc2 +vu-status+) (logior (logand (vc2 +vu-status+) #xFF0) new (ash new 6)))))(defun vu0-set-fdiv) source(defun vu0-set-fdiv (cpu flags)
"Status I and D from eefloat FLAGS (EF-I, EF-D), and their sticky bits"
(declare (type mips cpu) (type (unsigned-byte 4) flags))
(let ((new (logior (ash (bit-at flags 3) 4) (ash (bit-at flags 2) 5))))
(setf (vc2 +vu-status+) (logior (logand (vc2 +vu-status+) #xFCF) new (ash new 6)))))(defmacro vu-madd) source(defmacro vu-madd (acc a b sub)
`(let* ((p (ee-fmul ,a ,b))
(r (ee-fadd ,acc (wrap 32 ,(if sub '(ee-fneg (wrap 32 p)) 'p)))))
(logior r (logand p #xF00000000))))(defmacro vu-fmac) source(defmacro vu-fmac (kind op src)
(let ((rs (loop for l below 4 collect (intern (format nil "R~D" l)))))
`(let ,(loop for l below 4 for r in rs collect `(,r ,(vu-op-form op `(vf fs ,l) (vu-src src l) l)))
,@(loop for l below 4 for r in rs
collect `(when (dest-p ,l)
,(if (eq kind :acc) `(setf (vacc ,l) (wrap 32 ,r)) `(set-vf fd ,l ,r))))
(vu0-set-mac cpu (logior ,@(loop for l below 4 for r in rs
collect `(if (dest-p ,l) (vu-lane-mac ,r ,l) 0)))))))(defmacro vu-fmac-family) source(defmacro vu-fmac-family (base op docname)
(flet ((name (suffix) (intern (format nil "~A~A" (symbol-name base) suffix) :isa.mips)))
`(progn
,@(loop for (suffix kind src what) in
'(("" :fd :ft "") ("I" :fd :i " by I") ("Q" :fd :q " by Q")
("X" :fd 0 " by ft.x") ("Y" :fd 1 " by ft.y") ("Z" :fd 2 " by ft.z") ("W" :fd 3 " by ft.w")
("A" :acc :ft " to ACC") ("AI" :acc :i " by I to ACC") ("AQ" :acc :q " by Q to ACC")
("AX" :acc 0 " by ft.x to ACC") ("AY" :acc 1 " by ft.y to ACC")
("AZ" :acc 2 " by ft.z to ACC") ("AW" :acc 3 " by ft.w to ACC"))
collect `(defmips ,(name suffix)
(:asm ,(string-downcase (symbol-name (name suffix)))
dest ,@(if (eq kind :fd) '(fd) nil) fs ,@(if (member src '(:i :q)) nil '(ft)))
(:doc ,(format nil "VU0 ~A~A" docname what))
(vu-fmac ,kind ,op ,src))))))(defmacro vu-lanes) source(defmacro vu-lanes (to form)
(let ((rs (loop for l below 4 collect (intern (format nil "R~D" l)))))
`(let ,(loop for l below 4 for r in rs collect `(,r ,(subst l 'l form)))
,@(loop for l below 4 for r in rs collect `(when (dest-p ,l) (set-vf ,to ,l ,r))))))(defmacro vu-minmax-family) source(defmacro vu-minmax-family (base fn docname)
(flet ((name (suffix) (intern (format nil "~A~A" (symbol-name base) suffix) :isa.mips)))
`(progn
,@(loop for (suffix src) in '(("" :ft) ("I" :i) ("X" 0) ("Y" 1) ("Z" 2) ("W" 3))
collect `(defmips ,(name suffix)
(:asm ,(string-downcase (symbol-name (name suffix)))
dest fd fs ,@(if (eq src :i) nil '(ft)))
(:doc ,(format nil "VU0 ~A" docname))
(vu-lanes fd (,fn (vf fs l) ,(vu-src src 'l))))))))(defmacro vu-cvt-family) source(defmacro vu-cvt-family (base fn docname)
`(progn
,@(loop for n in '(0 4 12 15)
collect (let ((name (intern (format nil "~A~D" (symbol-name base) n) :isa.mips)))
`(defmips ,name (:asm ,(string-downcase (symbol-name name)) dest ft fs)
(:doc ,(format nil "VU0 ~A ~D" docname n))
(vu-lanes ft (,fn (vf fs l) ,n)))))))(defmacro vu-store-lanes) source(defmacro vu-store-lanes (q)
`(progn ,@(loop for l below 4
collect `(when (dest-p ,l) (mips-store 32 (vu0-addr ,q ,l) (vf fs ,l))))))(defmacro vu-ilwr) source(defmacro vu-ilwr (l) `(set-vi it (mips-load 32 (vu0-addr (vi is) ,l))))(defmacro vu-iswr) source(defmacro vu-iswr (l) `(mips-store 32 (vu0-addr (vi is) ,l) (vi it)))(defmacro vfq) source(defmacro vfq (r) `(logior (vf ,r 0) (ash (vf ,r 1) 32) (ash (vf ,r 2) 64) (ash (vf ,r 3) 96)))(defmacro set-vfq) source(defmacro set-vfq (r v)
`(let ((x ,v))
,@(loop for l below 4 collect `(set-vf ,r ,l (bit-field x ,(* 32 l) 32)))))(defmacro qmfc2-body) source(defmacro qmfc2-body () '(set-gprq rt (vfq fs)))(defmacro qmtc2-body) source(defmacro qmtc2-body () '(set-vfq fs (gprq rt)))(defmipsmacro cfc2-body) source(defmipsmacro cfc2-body ()
'(set-gpr rt (reg32 (cond ((= is 0) 0)
((= is +vu-r+) (bit-field (vc2 +vu-r+) 0 23))
(t (vc2 is))))))(defmacro ctc2-body) source(defmacro ctc2-body ()
'(let ((v (wrap 32 (gpr rt))))
(case is
((0 17 26 29) nil)
(16 (setf (vc2 16) (logior (logand (vc2 16) #x3F) (logand v #xFC0))))
(18 (setf (vc2 18) (wrap 24 v)))
(20 (setf (vc2 20) (logior #x3F800000 (bit-field v 0 23))))
(28 (setf (vc2 28) (logand v #x0C0C)))
(t (setf (vc2 is) (if (< is 16) (wrap 16 v) v))))))(defmacro cpcond2) source(defmacro cpcond2 () `(bit-at (vc2 +vu-stat+) 8))Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.