spu: state.lisp

the SPU's architected state, local store and the SPU ISA.

Other definitions

(defconstant +spu-lslr+) source
(defconstant +spu-lslr+ #x3FFFF)
(defconstant +spu-running+) source
(defconstant +spu-running+ 1)
(defconstant +spu-stopped+) source
(defconstant +spu-stopped+ 2)
(defconstant +spu-halted+) source
(defconstant +spu-halted+ 4)
(defconstant +spu-waiting+) source
(defconstant +spu-waiting+ 8)
(defstruct spu) source
(defstruct (spu (:conc-name spu-))
  (gpr (make-array 128 :element-type '(unsigned-byte 128) :initial-element 0)
   :type (simple-array (unsigned-byte 128) (128)))
  (ls (make-array 262144 :element-type '(unsigned-byte 8) :initial-element 0)
   :type (simple-array (unsigned-byte 8) (262144)))
  (pc 0 :type (unsigned-byte 32))       ; LS address of the instruction being executed
  (npc 0 :type (unsigned-byte 32))      ; LS address of the next instruction
  (fpscr 0 :type (unsigned-byte 128))   ; FPSCR, SPU ISA layout
  (srr0 0 :type (unsigned-byte 32))     ; interrupt return address
  (status 0 :type (unsigned-byte 32))   ; +spu-running+ ... flags
  (stop-code 0 :type (unsigned-byte 32)) ; 14-bit code of the last stop / stopd
  (wait-ch 0 :type (unsigned-byte 8))   ; channel of a +spu-waiting+ stall
  (insn-count 0 :type (unsigned-byte 64))
  ;; channels (src/isa/spu/chan.lisp)
  (event-stat 0 :type (unsigned-byte 32))   ; pending events (unmasked)
  (event-mask 0 :type (unsigned-byte 32))
  (sig1 0 :type (unsigned-byte 32))
  (sig1-count 0 :type (unsigned-byte 1))
  (sig2 0 :type (unsigned-byte 32))
  (sig2-count 0 :type (unsigned-byte 1))
  (dec 0 :type (unsigned-byte 32))          ; decrementer (does not count yet)
  (in-mbox (make-array 4 :element-type '(unsigned-byte 32) :initial-element 0)
   :type (simple-array (unsigned-byte 32) (4)))  ; FIFO, element 0 oldest
  (in-mbox-count 0 :type (unsigned-byte 3))
  (out-mbox 0 :type (unsigned-byte 32))
  (out-mbox-count 0 :type (unsigned-byte 1))
  (out-intr-mbox 0 :type (unsigned-byte 32))
  (out-intr-mbox-count 0 :type (unsigned-byte 1))
  ;; MFC command parameters and tag state (src/isa/spu/mfc.lisp)
  (mfc-lsa 0 :type (unsigned-byte 32))
  (mfc-eah 0 :type (unsigned-byte 32))
  (mfc-eal 0 :type (unsigned-byte 32))
  (mfc-size 0 :type (unsigned-byte 32))
  (mfc-tag 0 :type (unsigned-byte 32))
  (mfc-tag-mask 0 :type (unsigned-byte 32))
  (mfc-tag-update 0 :type (unsigned-byte 32))  ; 0 immediate, 1 any, 2 all
  (mfc-tag-req 0 :type (unsigned-byte 1))      ; a tag status update request is pending
  (mfc-tag-busy 0 :type (unsigned-byte 32))    ; bit n: tag group n has commands queued
  (mfc-stall-stat 0 :type (unsigned-byte 32))
  (mfc-atomic-stat 0 :type (unsigned-byte 32))
  (mfc-atomic-count 0 :type (unsigned-byte 1))
  (mfc-error 0 :type (unsigned-byte 32))       ; command of a faulting DMA, 0 if none
  ;; the SPU command queue (16 entries). Commands are performed as they are
  ;; enqueued for now, so the queue is empty between instructions.
  (mfc-qcmd (make-array 16 :element-type '(unsigned-byte 8) :initial-element 0)
   :type (simple-array (unsigned-byte 8) (16)))
  (mfc-qtag (make-array 16 :element-type '(unsigned-byte 8) :initial-element 0)
   :type (simple-array (unsigned-byte 8) (16)))
  (mfc-qsize (make-array 16 :element-type '(unsigned-byte 32) :initial-element 0)
   :type (simple-array (unsigned-byte 32) (16)))
  (mfc-qlsa (make-array 16 :element-type '(unsigned-byte 32) :initial-element 0)
   :type (simple-array (unsigned-byte 32) (16)))
  (mfc-qea (make-array 16 :element-type '(unsigned-byte 64) :initial-element 0)
   :type (simple-array (unsigned-byte 64) (16)))
  (mfc-qcount 0 :type (unsigned-byte 5))
  ;; lock-line reservation (getllar / putllc): the line's EA and a snapshot
  (llr-ea 0 :type (unsigned-byte 32))
  (llr-valid 0 :type (unsigned-byte 1))
  (llr-data (make-array 128 :element-type '(unsigned-byte 8) :initial-element 0)
   :type (simple-array (unsigned-byte 8) (128))))
(defmacro gpr) source
(defmacro gpr (n) `(aref (spu-gpr cpu) ,n))
(defmacro ls-byte) source
(defmacro ls-byte (addr) `(aref (spu-ls cpu) (logand ,addr ,+spu-lslr+)))
(defun spu-ls-load) source
(defun spu-ls-load (cpu addr nbytes)
  "NBYTES big-endian bytes at LS address ADDR (wrapping)"
  (declare (type spu cpu) (type (unsigned-byte 32) addr) (type (unsigned-byte 5) nbytes))
  (let ((v 0))
    (declare (type (unsigned-byte 128) v))
    (dotimes (i nbytes)
      (setq v (wrap 128 (logior (ash v 8) (ls-byte (+ addr i))))))
    v))
(defun spu-ls-store) source
(defun spu-ls-store (cpu addr nbytes value)
  "store the low NBYTES bytes of VALUE big-endian at LS address ADDR (wrapping)"
  (declare (type spu cpu) (type (unsigned-byte 32) addr) (type (unsigned-byte 5) nbytes)
           (type (unsigned-byte 128) value))
  (dotimes (i nbytes)
    (setf (ls-byte (+ addr i)) (ldb (byte 8 (* 8 (- nbytes 1 i))) value)))
  nil)
(defmacro ls-read) source
(defmacro ls-read (n addr)
  `(the (unsigned-byte ,n) (spu-ls-load cpu ,addr ,(floor n 8))))
(defmacro ls-write) source
(defmacro ls-write (n addr value)
  `(spu-ls-store cpu ,addr ,(floor n 8) (ldb (byte ,n 0) ,value)))
(defmacro pref32) source
(defmacro pref32 (x) `(set-lane 32 0 0 ,x))
(defmacro lane-mask) source
(defmacro lane-mask (w test) `(if ,test ,(ones w) 0))
(defmacro slot32) source
(defmacro slot32 (n) `(lane 32 (gpr ,n) 0))
(defisa spu) source
(defisa spu :width 32 :endian :big :state spu
  :doc "Cell Synergistic Processor Unit, SPU ISA 1.2")
(defmacro defspu) source
(defmacro defspu (name form op asm &body body)
  `(definsn spu ,name ,(spu-encoding form op)
     (:asm ,(string-downcase (symbol-name name)) ,@asm)
     ,@body))

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