the vector units' micro mode: upper (FMAC) and lower (integer, load/store, FDIV, EFU, branch) instructions as two ISAs, and the pair's execution.
0/1 a fixed bit, name a field, a bit the decoder ignores
lqd dest ft is
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | dest | ft | is | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | |||||||||||
(deflower lqd "1000000 dest:4 ft:5 is:5 01101 111110" (:asm "lqd" dest ft is)
(let ((q (wrap 16 (- (vi is) 1)))) (set-vi is q) (vu-lanes ft (dmem q l))))
sqd dest fs it
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | dest | it | fs | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |||||||||||
(deflower sqd "1000000 dest:4 it:5 fs:5 01101 111111" (:asm "sqd" dest fs it)
(let ((q (wrap 16 (- (vi it) 1))))
(set-vi it q)
(dotimes (l 4) (when (= (ldb (byte 1 (- 3 l)) dest) 1) (set-dmem q l (vf fs l))))))
div fs fsf ft ftf
FDIV: Q <- fs.fsf / ft.ftf, sqrt ft.ftf, fs.fsf / sqrt ft.ftf
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | ftf | fsf | ft | fs | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | ||||||||||
(deflower div "1000000 ftf:2 fsf:2 ft:5 fs:5 01110 111100" (:asm "div" fs fsf ft ftf)
(let ((r (isa.mips::ee-fdiv (vf fs fsf) (vf ft ftf))))
(setf (vu-q cpu) (wrap 32 r)) (vu-set-fdiv cpu (ldb (byte 4 32) r))))
sqrt ft ftf
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | ftf | fsf | ft | fs | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | ||||||||||
(deflower sqrt "1000000 ftf:2 fsf:2 ft:5 fs:5 01110 111101" (:asm "sqrt" ft ftf)
(let ((r (isa.mips::ee-fsqrt (vf ft ftf))))
(setf (vu-q cpu) (wrap 32 r)) (vu-set-fdiv cpu (ldb (byte 4 32) r))))
rsqrt fs fsf ft ftf
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | ftf | fsf | ft | fs | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | ||||||||||
(deflower rsqrt "1000000 ftf:2 fsf:2 ft:5 fs:5 01110 111110" (:asm "rsqrt" fs fsf ft ftf)
(let ((r (isa.mips::ee-frsqrt (vf fs fsf) (vf ft ftf))))
(setf (vu-q cpu) (wrap 32 r)) (vu-set-fdiv cpu (ldb (byte 4 32) r))))
waitq
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
(deflower waitq "1000000 .... ..... ..... 01110 111111" (:asm "waitq"))
mtir it fs fsf
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | it | fs | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | |||||||||||
(deflower mtir "1000000 . fsf:2 . it:5 fs:5 01111 111100" (:asm "mtir" it fs fsf)
(set-vi it (ldb (byte 16 0) (vf fs fsf))))
mfir dest ft is
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | dest | ft | is | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | |||||||||||
(deflower mfir "1000000 dest:4 ft:5 is:5 01111 111101" (:asm "mfir" dest ft is)
(vu-lanes ft (wrap 32 (sext 16 (vi is)))))
ilwr dest it is
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | dest | it | is | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | |||||||||||
(deflower ilwr "1000000 dest:4 it:5 is:5 01111 111110" (:asm "ilwr" dest it is)
(set-vi it (ldb (byte 16 0) (dmem (vi is) (cond ((dest-p 0) 0) ((dest-p 1) 1) ((dest-p 2) 2) (t 3))))))
iswr dest it is
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | dest | it | is | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |||||||||||
(deflower iswr "1000000 dest:4 it:5 is:5 01111 111111" (:asm "iswr" dest it is)
(dotimes (l 4) (when (= (ldb (byte 1 (- 3 l)) dest) 1) (set-dmem (vi is) l (vi it)))))
rnext dest ft
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | dest | ft | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | ||||||||||||
(deflower rnext "1000000 dest:4 ft:5 ..... 10000 111100" (:asm "rnext" dest ft)
(vu-rnext cpu) (vu-lanes ft (vu-r cpu)))
rget dest ft
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | dest | ft | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | ||||||||||||
(deflower rget "1000000 dest:4 ft:5 ..... 10000 111101" (:asm "rget" dest ft) (vu-lanes ft (vu-r cpu)))
rinit fs fsf
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | ||||||||||||
(deflower rinit "1000000 . fsf:2 . ..... fs:5 10000 111110" (:asm "rinit" fs fsf)
(setf (vu-r cpu) (logior #x3F800000 (logand (vf fs fsf) #x7FFFFF))))
rxor fs fsf
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | ||||||||||||
(deflower rxor "1000000 . fsf:2 . ..... fs:5 10000 111111" (:asm "rxor" fs fsf)
(setf (vu-r cpu) (logior #x3F800000 (logand (logxor (vu-r cpu) (vf fs fsf)) #x7FFFFF))))
mfp dest ft
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | dest | ft | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | ||||||||||||
(deflower mfp "1000000 dest:4 ft:5 ..... 11001 111100" (:asm "mfp" dest ft) (vu-lanes ft (vu-preg cpu)))
xtop it
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | it | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | |||||||||||||
(deflower xtop "1000000 .... it:5 ..... 11010 111100" (:asm "xtop" it) (set-vi it (vu-xtop cpu 0)))
xitop it
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | it | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | |||||||||||||
(deflower xitop "1000000 .... it:5 ..... 11010 111101" (:asm "xitop" it) (set-vi it (vu-xtop cpu 1)))
xgkick is
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | is | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | |||||||||||||
(deflower xgkick "1000000 .... ..... is:5 11011 111100" (:asm "xgkick" is) (vu-xgkick cpu (vi is)))
esadd fs
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | ||||||||||||
(deflower esadd "1000000 . fsf:2 . ..... fs:5 11100 111100" (:asm "esadd" fs) (efu (efu-sq3)))
ersadd fs
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | ||||||||||||
(deflower ersadd "1000000 . fsf:2 . ..... fs:5 11100 111101" (:asm "ersadd" fs)
(efu (let ((s (efu-sq3))) (if (fzero-p :f32 s) 0 (f/ (fconst :f32 1.0) s)))))
eleng fs
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | ||||||||||||
(deflower eleng "1000000 . fsf:2 . ..... fs:5 11100 111110" (:asm "eleng" fs)
(efu (fsqrt :f32 :rne (fabs :f32 (efu-sq3)))))
erleng fs
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | ||||||||||||
(deflower erleng "1000000 . fsf:2 . ..... fs:5 11100 111111" (:asm "erleng" fs)
(efu (let ((s (fsqrt :f32 :rne (fabs :f32 (efu-sq3))))) (if (fzero-p :f32 s) 0 (f/ (fconst :f32 1.0) s)))))
eatanxy fs
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | ||||||||||||
(deflower eatanxy "1000000 . fsf:2 . ..... fs:5 11101 111100" (:asm "eatanxy" fs)
(efu (if (fzero-p :f32 x) 0 (vu-atan (f/ y x)))))
eatanxz fs
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | ||||||||||||
(deflower eatanxz "1000000 . fsf:2 . ..... fs:5 11101 111101" (:asm "eatanxz" fs)
(efu (if (fzero-p :f32 x) 0 (vu-atan (f/ z x)))))
esum fs
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | ||||||||||||
(deflower esum "1000000 . fsf:2 . ..... fs:5 11101 111110" (:asm "esum" fs) (efu (f+ (f+ (f+ x y) z) w)))
esqrt fs fsf
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | ||||||||||||
(deflower esqrt "1000000 . fsf:2 . ..... fs:5 11110 111100" (:asm "esqrt" fs fsf) (efu (fsqrt :f32 :rne (fabs :f32 e))))
ersqrt fs fsf
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | ||||||||||||
(deflower ersqrt "1000000 . fsf:2 . ..... fs:5 11110 111101" (:asm "ersqrt" fs fsf)
(efu (if (fzero-p :f32 e) 0 (f/ (fconst :f32 1.0) (fsqrt :f32 :rne (fabs :f32 e))))))
ercpr fs fsf
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | ||||||||||||
(deflower ercpr "1000000 . fsf:2 . ..... fs:5 11110 111110" (:asm "ercpr" fs fsf)
(efu (if (fzero-p :f32 e) 0 (f/ (fconst :f32 1.0) e))))
waitp
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
(deflower waitp "1000000 .... ..... ..... 11110 111111" (:asm "waitp"))
esin fs fsf
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | ||||||||||||
(deflower esin "1000000 . fsf:2 . ..... fs:5 11111 111100" (:asm "esin" fs fsf) (efu (fsin :f32 e)))
eatan fs fsf
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | ||||||||||||
(deflower eatan "1000000 . fsf:2 . ..... fs:5 11111 111101" (:asm "eatan" fs fsf) (efu (vu-atan e)))
eexp fs fsf
| 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 | 0 | 0 | 0 | 0 | 0 | 0 | fsf | fs | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | ||||||||||||
(deflower eexp "1000000 . fsf:2 . ..... fs:5 11111 111110" (:asm "eexp" fs fsf) (efu (fexp :f32 (fneg :f32 e))))
(defisa vu-upper) source(defisa vu-upper :width 32 :endian :little :state vu
:doc "the PS2 vector units' upper (FMAC) instructions [VUUM]")(defisa vu-lower) source(defisa vu-lower :width 32 :endian :little :state vu
:doc "the PS2 vector units' lower instructions [VUUM]")(defmacro vf) source(defmacro vf (r l)
`(if (= ,r 0) (if (= ,l 3) #x3F800000 0) (aref (vu-vf cpu) (+ (* 4 ,r) ,l))))(defmacro set-vf) source(defmacro set-vf (r l v)
`(unless (= ,r 0) (setf (aref (vu-vf cpu) (+ (* 4 ,r) ,l)) (wrap 32 ,v))))(defmacro vacc) source(defmacro vacc (l) `(aref (vu-acc cpu) ,l))(defmacro vi) source(defmacro vi (n) `(if (= ,n 0) 0 (aref (vu-vi cpu) ,n)))(defmacro set-vi) source(defmacro set-vi (n v) `(unless (= ,n 0) (setf (aref (vu-vi cpu) ,n) (wrap 16 ,v))))(defmacro dest-p) source(defmacro dest-p (l) `(= (ldb (byte 1 ,(- 3 l)) dest) 1))(defmacro lane-of) source(defmacro lane-of (sel) `(ldb (byte 2 0) ,sel))(defmacro dmem-addr) source(defmacro dmem-addr (q l) `(+ (vu-data-base cpu) (logand (+ (* 16 ,q) (* 4 ,l)) (vu-data-mask cpu))))(defmacro dmem) source(defmacro dmem (q l) `(bswap 32 (mem-read 32 (dmem-addr ,q ,l))))(defmacro set-dmem) source(defmacro set-dmem (q l v) `(mem-write 32 (dmem-addr ,q ,l) (bswap 32 (wrap 32 ,v))))(defmacro lane-mac) source(defmacro lane-mac (r l)
(let ((sh (- 3 l)))
`(logior (ash (b2i (= (ldb (byte 31 0) ,r) 0)) ,sh) (ash (ldb (byte 1 31) ,r) ,(+ 4 sh))
(ash (ldb (byte 1 33) ,r) ,(+ 8 sh)) (ash (ldb (byte 1 32) ,r) ,(+ 12 sh)))))(defun vu-set-mac) source(defun vu-set-mac (cpu mac)
"MAC <- MAC; status Z S U O from it, and their sticky copies (bits 6-9)"
(declare (type vu 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 (vu-mac cpu) mac
(vu-status cpu) (logior (logand (vu-status cpu) #xFF0) new (ash new 6)))))(defun vu-set-fdiv) source(defun vu-set-fdiv (cpu flags)
"status I (4) and D (5) from eefloat FLAGS, and their sticky copies (10, 11)"
(declare (type vu cpu) (type (unsigned-byte 4) flags))
(let ((new (logior (ash (ldb (byte 1 3) flags) 4) (ash (ldb (byte 1 2) flags) 5))))
(setf (vu-status cpu) (logior (logand (vu-status cpu) #xFCF) new (ash new 6)))))(defmacro vu-madd) source(defmacro vu-madd (acc a b sub)
`(let* ((p (isa.mips::ee-fmul ,a ,b))
(r (isa.mips::ee-fadd ,acc (wrap 32 ,(if sub '(isa.mips::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) :isa.vu))))
`(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))))
(vu-set-mac cpu (logior ,@(loop for l below 4 for r in rs
collect `(if (dest-p ,l) (lane-mac ,r ,l) 0)))))))(defmacro vu-lanes) source(defmacro vu-lanes (to form)
(let ((rs (loop for l below 4 collect (intern (format nil "R~D" l) :isa.vu))))
`(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 defupper) source(defmacro defupper (name enc &rest body)
`(definsn vu-upper ,name ,(concatenate 'string "....... dest:4 ft:5 fs:5 " enc) ,@body))(defun vu-upper-illegal) source(defun vu-upper-illegal (cpu insn)
(declare (type vu cpu) (type (unsigned-byte 32) insn) (ignore cpu insn))
nil)(define-executor vu-upper-execute) source(define-executor vu-upper-execute vu-upper :illegal vu-upper-illegal)(define-decoder vu-decode-upper) source(define-decoder vu-decode-upper vu-upper)(defmacro deflower) source(defmacro deflower (name enc &rest body)
`(definsn vu-lower ,name ,enc ,@body))(defmacro imm11) source(defmacro imm11 () '(sext 11 imm))(defmacro branch) source(defmacro branch (target) `(setf (vu-npc cpu) (wrap 32 ,target)))(defmacro branch-rel) source(defmacro branch-rel () '(+ (vu-tpc cpu) 8 (* 8 (imm11))))(defun vu-rnext) source(defun vu-rnext (cpu)
(declare (type vu cpu))
(let* ((r (vu-r cpu)) (x (logxor (ldb (byte 1 4) r) (ldb (byte 1 22) r))))
(setf (vu-r cpu) (logior #x3F800000 (logand (logior (ash r 1) x) #x7FFFFF)))))(defmacro f+) source(defmacro f+ (a b) `(fadd :f32 :rne ,a ,b))(defmacro f*) source(defmacro f* (a b) `(fmul :f32 :rne ,a ,b))(defmacro f/) source(defmacro f/ (a b) `(fdiv :f32 :rne ,a ,b))(defun vu-atan) source(defun vu-atan (x)
"arctangent: x / (1 + 0.28 x^2) within [-1, 1], pi/2 - atan(1/x) outside (the EFU's own
series [VUUM] \"EATAN\" is an approximation too)"
(declare (type (unsigned-byte 32) x))
(if (= (fle :f32 (fabs :f32 x) (fconst :f32 1.0)) 1)
(f/ x (f+ (fconst :f32 1.0) (f* (f* (fconst :f32 0.28) x) x)))
(let ((r (f/ (fconst :f32 1.0) x)))
(fsub :f32 :rne (if (= (flt :f32 0 x) 1) (fconst :f32 1.5707964) (fconst :f32 -1.5707964))
(f/ r (f+ (fconst :f32 1.0) (f* (f* (fconst :f32 0.28) r) r)))))))Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.