mips: fpu.lisp

the R5900's FPU (coprocessor 1): single precision only, not IEEE 754.

0/1 a fixed bit, name a field,   a bit the decoder ignores

mfc1 source

mfc1 rt fs

Move Word from Floating Point

r5900:

313029282726252423222120191817161514131211109876543210
01000100000rtfs00000000000
(defmips mfc1 (:only :r5900) (:asm "mfc1" rt fs) (:doc "Move Word from Floating Point")
  (set-gpr rt (reg32 (fpr fs))))

mtc1 source

mtc1 rt fs

Move Word to Floating Point

r5900:

313029282726252423222120191817161514131211109876543210
01000100100rtfs00000000000
(defmips mtc1 (:only :r5900) (:asm "mtc1" rt fs) (:doc "Move Word to Floating Point")
  (setf (fpr fs) (wrap 32 (gpr rt))))

cfc1 source

cfc1 rt rd

Move Control Word from Floating Point

r5900:

313029282726252423222120191817161514131211109876543210
01000100010rtrd00000000000
(defmips cfc1 (:only :r5900) (:asm "cfc1" rt rd) (:doc "Move Control Word from Floating Point")
  (set-gpr rt (reg32 (case rd (31 (mips-fcr31 cpu)) (0 #x2E00) (t 0)))))

ctc1 source

ctc1 rt rd

Move Control Word to Floating Point

r5900:

313029282726252423222120191817161514131211109876543210
01000100110rtrd00000000000
(defmips ctc1 (:only :r5900) (:asm "ctc1" rt rd) (:doc "Move Control Word to Floating Point")
  (when (= rd 31) (setf (mips-fcr31 cpu) (wrap 32 (gpr rt)))))

lwc1 source

lwc1 ft (simm imm) rs

Load Word to Floating Point

r5900:

313029282726252423222120191817161514131211109876543210
110001rsftimm
(defmips lwc1 (:only :r5900) (:asm "lwc1" ft (simm imm) rs) (:doc "Load Word to Floating Point")
  (let ((a (vaddr rs imm)))
    (if (/= (wrap 2 a) 0)
        (raise +exc-adel+)
        (setf (fpr ft) (mips-load 32 a)))))

swc1 source

swc1 ft (simm imm) rs

Store Word from Floating Point

r5900:

313029282726252423222120191817161514131211109876543210
111001rsftimm
(defmips swc1 (:only :r5900) (:asm "swc1" ft (simm imm) rs) (:doc "Store Word from Floating Point")
  (let ((a (vaddr rs imm)))
    (if (/= (wrap 2 a) 0)
        (raise +exc-ades+)
        (mips-store 32 a (fpr ft)))))

mov.s source

mov.s fd fs

Floating Point Move

r5900:

313029282726252423222120191817161514131211109876543210
0100011000000000fsfd000110
(defmips mov.s (:only :r5900) (:asm "mov.s" fd fs) (:doc "Floating Point Move")
  (setf (fpr fd) (fpr fs)))

add.s source

add.s fd fs ft

Floating Point Add

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfsfd000000
(defmips add.s (:only :r5900) (:asm "add.s" fd fs ft) (:doc "Floating Point Add")
  (fpu-set (fpr fd) (ee-fadd (fpr fs) (fpr ft)) +ef-ou+))

sub.s source

sub.s fd fs ft

Floating Point Subtract

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfsfd000001
(defmips sub.s (:only :r5900) (:asm "sub.s" fd fs ft) (:doc "Floating Point Subtract")
  (fpu-set (fpr fd) (ee-fsub (fpr fs) (fpr ft)) +ef-ou+))

mul.s source

mul.s fd fs ft

Floating Point Multiply

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfsfd000010
(defmips mul.s (:only :r5900) (:asm "mul.s" fd fs ft) (:doc "Floating Point Multiply")
  (fpu-set (fpr fd) (ee-fmul (fpr fs) (fpr ft)) +ef-ou+))

div.s source

div.s fd fs ft

Floating Point Divide

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfsfd000011
(defmips div.s (:only :r5900) (:asm "div.s" fd fs ft) (:doc "Floating Point Divide")
  (fpu-set (fpr fd) (ee-fdiv (fpr fs) (fpr ft)) (logior +ef-ou+ +ef-di+)))

sqrt.s source

sqrt.s fd ft

Floating Point Square Root

r5900:

313029282726252423222120191817161514131211109876543210
0100011000000000fsfd000100

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ft00000fd000100
(defmips sqrt.s (:only :r5900) (:asm "sqrt.s" fd ft) (:doc "Floating Point Square Root")
  (fpu-set (fpr fd) (ee-fsqrt (fpr ft)) +ef-di+))

rsqrt.s source

rsqrt.s fd fs ft

Floating Point Reciprocal Square Root

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfsfd010110
(defmips rsqrt.s (:only :r5900) (:asm "rsqrt.s" fd fs ft) (:doc "Floating Point Reciprocal Square Root")
  (fpu-set (fpr fd) (ee-frsqrt (fpr fs) (fpr ft)) (logior +ef-ou+ +ef-di+)))

abs.s source

abs.s fd fs

Floating Point Absolute Value

ABS.S, NEG.S: the sign bit only; O and U cleared

r5900:

313029282726252423222120191817161514131211109876543210
0100011000000000fsfd000101
(defmips abs.s (:only :r5900) (:asm "abs.s" fd fs) (:doc "Floating Point Absolute Value")
  (fpu-set (fpr fd) (logand (fpr fs) #x7FFFFFFF) +ef-ou+))

neg.s source

neg.s fd fs

Floating Point Negate

r5900:

313029282726252423222120191817161514131211109876543210
0100011000000000fsfd000111
(defmips neg.s (:only :r5900) (:asm "neg.s" fd fs) (:doc "Floating Point Negate")
  (fpu-set (fpr fd) (ee-fneg (fpr fs)) +ef-ou+))

adda.s source

adda.s fs ft

Floating Point Add to Accumulator

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfs00000011000
(defmips adda.s (:only :r5900) (:asm "adda.s" fs ft) (:doc "Floating Point Add to Accumulator")
  (fpu-set (mips-facc cpu) (ee-fadd (fpr fs) (fpr ft)) +ef-ou+))

suba.s source

suba.s fs ft

Floating Point Subtract to Accumulator

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfs00000011001
(defmips suba.s (:only :r5900) (:asm "suba.s" fs ft) (:doc "Floating Point Subtract to Accumulator")
  (fpu-set (mips-facc cpu) (ee-fsub (fpr fs) (fpr ft)) +ef-ou+))

mula.s source

mula.s fs ft

Floating Point Multiply to Accumulator

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfs00000011010
(defmips mula.s (:only :r5900) (:asm "mula.s" fs ft) (:doc "Floating Point Multiply to Accumulator")
  (fpu-set (mips-facc cpu) (ee-fmul (fpr fs) (fpr ft)) +ef-ou+))

madd.s source

madd.s fd fs ft

Floating Point Multiply-Add

MADD.S: "fd <- ACC + fs * ft"; MSUB.S: "fd <- ACC - fs * ft"

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfsfd011100
(defmips madd.s (:only :r5900) (:asm "madd.s" fd fs ft) (:doc "Floating Point Multiply-Add")
  (fpu-set (fpr fd) (fpu-madd (mips-facc cpu) (fpr fs) (fpr ft) nil) +ef-ou+))

msub.s source

msub.s fd fs ft

Floating Point Multiply-Subtract

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfsfd011101
(defmips msub.s (:only :r5900) (:asm "msub.s" fd fs ft) (:doc "Floating Point Multiply-Subtract")
  (fpu-set (fpr fd) (fpu-madd (mips-facc cpu) (fpr fs) (fpr ft) t) +ef-ou+))

madda.s source

madda.s fs ft

Floating Point Multiply-Add to Accumulator

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfs00000011110
(defmips madda.s (:only :r5900) (:asm "madda.s" fs ft) (:doc "Floating Point Multiply-Add to Accumulator")
  (fpu-set (mips-facc cpu) (fpu-madd (mips-facc cpu) (fpr fs) (fpr ft) nil) +ef-ou+))

msuba.s source

msuba.s fs ft

Floating Point Multiply-Subtract to Accumulator

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfs00000011111
(defmips msuba.s (:only :r5900) (:asm "msuba.s" fs ft) (:doc "Floating Point Multiply-Subtract to Accumulator")
  (fpu-set (mips-facc cpu) (fpu-madd (mips-facc cpu) (fpr fs) (fpr ft) t) +ef-ou+))

max.s source

max.s fd fs ft

Floating Point Maximum

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfsfd101000
(defmips max.s (:only :r5900) (:asm "max.s" fd fs ft) (:doc "Floating Point Maximum")
  (fpu-set (fpr fd) (ee-fmax (fpr fs) (fpr ft)) +ef-ou+))

min.s source

min.s fd fs ft

Floating Point Minimum

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfsfd101001
(defmips min.s (:only :r5900) (:asm "min.s" fd fs ft) (:doc "Floating Point Minimum")
  (fpu-set (fpr fd) (ee-fmin (fpr fs) (fpr ft)) +ef-ou+))

cvt.s.w source

cvt.s.w fd fs

Fixed-point Convert to Single Floating Point

r5900:

313029282726252423222120191817161514131211109876543210
0100011010000000fsfd100000
(defmips cvt.s.w (:only :r5900) (:asm "cvt.s.w" fd fs) (:doc "Fixed-point Convert to Single Floating Point")
  (setf (fpr fd) (wrap 32 (ee-fcvt-sw (fpr fs)))))

trunc.w.s source

cvt.w.s fd fs

Floating Point Convert to Word Fixed-point

CVT.W.S (binutils' trunc.w.s for the R5900): toward zero, saturating

r5900:

313029282726252423222120191817161514131211109876543210
0100011000000000fsfd100100
(defmips trunc.w.s (:only :r5900) (:asm "cvt.w.s" fd fs) (:doc "Floating Point Convert to Word Fixed-point")
  (setf (fpr fd) (ee-fcvt-ws (fpr fs))))

c.f.s source

c.f.s fs ft

Floating Point Compare False

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfs00000110000
(defmips c.f.s (:only :r5900) (:asm "c.f.s" fs ft) (:doc "Floating Point Compare False")
  (set-fcc nil))

c.eq.s source

c.eq.s fs ft

Floating Point Compare Equal

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfs00000110010
(defmips c.eq.s (:only :r5900) (:asm "c.eq.s" fs ft) (:doc "Floating Point Compare Equal")
  (set-fcc (= (ee-feq (fpr fs) (fpr ft)) 1)))

c.lt.s source

c.lt.s fs ft

Floating Point Compare Less Than

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfs00000110100
(defmips c.lt.s (:only :r5900) (:asm "c.lt.s" fs ft) (:doc "Floating Point Compare Less Than")
  (set-fcc (= (ee-flt (fpr fs) (fpr ft)) 1)))

c.le.s source

c.le.s fs ft

Floating Point Compare Less Than or Equal

r5900:

313029282726252423222120191817161514131211109876543210
01000110000ftfs00000110110
(defmips c.le.s (:only :r5900) (:asm "c.le.s" fs ft) (:doc "Floating Point Compare Less Than or Equal")
  (set-fcc (= (ee-fle (fpr fs) (fpr ft)) 1)))

bc1f source

bc1f (b-rel offset)

Branch on FP False

r5900:

313029282726252423222120191817161514131211109876543210
0100010100000000offset
(defmips bc1f (:only :r5900) (:asm "bc1f" (b-rel offset)) (:doc "Branch on FP False")
  (when (= (fcc) 0) (branch-to (branch-target offset))))

bc1t source

bc1t (b-rel offset)

Branch on FP True

r5900:

313029282726252423222120191817161514131211109876543210
0100010100000001offset
(defmips bc1t (:only :r5900) (:asm "bc1t" (b-rel offset)) (:doc "Branch on FP True")
  (when (= (fcc) 1) (branch-to (branch-target offset))))

bc1fl source

bc1fl (b-rel offset)

Branch on FP False Likely

r5900:

313029282726252423222120191817161514131211109876543210
0100010100000010offset
(defmips bc1fl (:only :r5900) (:asm "bc1fl" (b-rel offset)) (:doc "Branch on FP False Likely")
  (if (= (fcc) 0) (branch-to (branch-target offset)) (nullify)))

bc1tl source

bc1tl (b-rel offset)

Branch on FP True Likely

r5900:

313029282726252423222120191817161514131211109876543210
0100010100000011offset
(defmips bc1tl (:only :r5900) (:asm "bc1tl" (b-rel offset)) (:doc "Branch on FP True Likely")
  (if (= (fcc) 1) (branch-to (branch-target offset)) (nullify)))

Other definitions

(defmacro fpr) source
(defmacro fpr (n) `(aref (mips-fpr cpu) ,n))
(defconstant +fcr-c+) source
(defconstant +fcr-c+ #x800000)
(defmacro ef-cur) source
(defmacro ef-cur (f)
  `(logior (ash (bit-at ,f 0) 15) (ash (bit-at ,f 1) 14) (ash (bit-at ,f 2) 16) (ash (bit-at ,f 3) 17)))
(defmacro ef-sticky) source
(defmacro ef-sticky (f)
  `(logior (ash (bit-at ,f 0) 4) (ash (bit-at ,f 1) 3) (ash (bit-at ,f 2) 5) (ash (bit-at ,f 3) 6)))
(defun ee-fcr31) source
(defun ee-fcr31 (fcr flags track)
  "FCR31 after an operation that raised FLAGS and updates the flags TRACK
   (both EF-... sets): TRACK's current flags replaced, sticky ones added"
  (declare (type (unsigned-byte 32) fcr) (type (unsigned-byte 4) flags track))
  (let ((f (logand flags track)))
    (logior (logand fcr (wrap 32 (lognot (ef-cur track)))) (ef-cur f) (ef-sticky f))))
(defmacro fpu-set) source
(defmacro fpu-set (dest r track)
  `(let ((v ,r))
     (setf ,dest (wrap 32 v)
           (mips-fcr31 cpu) (ee-fcr31 (mips-fcr31 cpu) (bit-field v 32 4) ,track))))
(defconstant +ef-ou+) source
(defconstant +ef-ou+ 3)
(defconstant +ef-di+) source
(defconstant +ef-di+ 12)
(defmacro fpu-madd) source
(defmacro fpu-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 set-fcc) source
(defmacro set-fcc (test)
  `(setf (mips-fcr31 cpu) (if ,test
                              (logior (mips-fcr31 cpu) +fcr-c+)
                              (logand (mips-fcr31 cpu) (wrap 32 (lognot +fcr-c+))))))
(defmacro fcc) source
(defmacro fcc () `(bit-at (mips-fcr31 cpu) 23))

Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.