the vector units' micro mode: upper (FMAC) and lower (integer, load/store, FDIV, EFU, branch) instructions as two ISAs, and the pair's execution.
(defmacro efu) source(defmacro efu (form)
`(setf (vu-preg cpu) (let ((x (vf fs 0)) (y (vf fs 1)) (z (vf fs 2)) (w (vf fs 3)) (e (vf fs fsf)))
(declare (ignorable x y z w e))
,form)))(defmacro efu-sq3) source(defmacro efu-sq3 () '(f+ (f+ (f* x x) (f* y y)) (f* z z)))(defun vu-lower-illegal) source(defun vu-lower-illegal (cpu insn)
(declare (type vu cpu) (type (unsigned-byte 32) insn) (ignore cpu insn))
nil)(define-executor vu-lower-execute) source(define-executor vu-lower-execute vu-lower :illegal vu-lower-illegal)(define-decoder vu-decode-lower) source(define-decoder vu-decode-lower vu-lower)(defun vu-xgkick) source(defun vu-xgkick (cpu addr)
"XGKICK: the GIF packet at data memory quadword ADDR to PATH1 (the machine's)"
(declare (type vu cpu) (type (unsigned-byte 16) addr) (ignore cpu addr))
nil)(defun vu-xtop) source(defun vu-xtop (cpu which)
"XTOP (WHICH 0) / XITOP (1): VIF1's TOP / ITOP (the machine's)"
(declare (type vu cpu) (type (unsigned-byte 8) which) (ignore cpu which))
0)(defun vu-step) source(defun vu-step (cpu)
"the pair at TPC -> 1 when the program has ended (the pair after one with E has run)"
(declare (type vu cpu))
(let* ((pc (vu-tpc cpu))
(a (+ (vu-micro-base cpu) (logand pc (vu-micro-mask cpu))))
(lower (bswap 32 (mem-read 32 a)))
(upper (bswap 32 (mem-read 32 (+ a 4))))
(target (vu-npc cpu)) (end 0))
(declare (type (unsigned-byte 32) target))
(setf (vu-npc cpu) #xFFFFFFFF)
;; the upper's destination keeps its old value for the lower, and wins over it
(let* ((special (= (ldb (byte 4 2) upper) 15))
(d (if special (ldb (byte 5 16) upper) (ldb (byte 5 6) upper)))
(o0 (aref (vu-vf cpu) (* 4 d))) (o1 (aref (vu-vf cpu) (+ 1 (* 4 d))))
(o2 (aref (vu-vf cpu) (+ 2 (* 4 d)))) (o3 (aref (vu-vf cpu) (+ 3 (* 4 d)))))
(vu-upper-execute cpu upper)
(if (logbitp 31 upper)
(setf (vu-i cpu) lower)
(let ((n0 (aref (vu-vf cpu) (* 4 d))) (n1 (aref (vu-vf cpu) (+ 1 (* 4 d))))
(n2 (aref (vu-vf cpu) (+ 2 (* 4 d)))) (n3 (aref (vu-vf cpu) (+ 3 (* 4 d)))))
(setf (aref (vu-vf cpu) (* 4 d)) o0 (aref (vu-vf cpu) (+ 1 (* 4 d))) o1
(aref (vu-vf cpu) (+ 2 (* 4 d))) o2 (aref (vu-vf cpu) (+ 3 (* 4 d))) o3)
(vu-lower-execute cpu lower)
(setf (aref (vu-vf cpu) (* 4 d)) n0 (aref (vu-vf cpu) (+ 1 (* 4 d))) n1
(aref (vu-vf cpu) (+ 2 (* 4 d))) n2 (aref (vu-vf cpu) (+ 3 (* 4 d))) n3))))
(setf (vu-steps cpu) (wrap 64 (+ (vu-steps cpu) 1)))
;; E: the next pair is the last; a branch taken here jumps after the next pair
(when (= (vu-running cpu) 2) (setq end 1))
(when (logbitp 30 upper) (setf (vu-running cpu) 2))
(if (/= target #xFFFFFFFF)
(setf (vu-tpc cpu) (logand target (vu-micro-mask cpu)))
(setf (vu-tpc cpu) (logand (+ pc 8) (vu-micro-mask cpu))))
(when (= end 1)
(setf (vu-running cpu) 0 (vu-npc cpu) #xFFFFFFFF))
end))(defun vu-run) source(defun vu-run (cpu pc)
"run the micro program at PC (bytes) to its end (at most 16M pairs)"
(declare (type vu cpu) (type (unsigned-byte 32) pc))
(setf (vu-tpc cpu) (logand pc (vu-micro-mask cpu)) (vu-running cpu) 1 (vu-npc cpu) #xFFFFFFFF
(vu-programs cpu) (wrap 64 (+ (vu-programs cpu) 1)))
(let ((n 0))
(declare (type (unsigned-byte 32) n))
(loop
(when (or (= (vu-step cpu) 1) (>= n #xFFFFFF)) (return))
(setq n (+ n 1))))
(setf (vu-running cpu) 0)
nil)Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.