mips: enc.lisp

MIPS as a host: run-time encoders per model, made from the DEFMIPS encodings, and the emitter.

Other definitions

(defmacro define-mips-encoders) source
(defmacro define-mips-encoders ()
  `(progn
     ,@(loop for m in (mips-models)
             append (loop for i in (isa-insn-list (mips-model-isa m))
                          collect `(defun ,(mips-encoder-name m (insn-name i)) ,(mapcar #'first (insn-fields i))
                                     (declare ,@(mapcar (lambda (f) `(type (unsigned-byte 32) ,(first f)))
                                                        (insn-fields i)))
                                     (logior ,(insn-match i)
                                             ,@(mapcar (lambda (f)
                                                         `(ash (ldb (byte ,(third f) 0) ,(first f)) ,(second f)))
                                                       (insn-fields i))))))))
(defun mips-emit32) source
(defun mips-emit32 (code pos word)
  "write WORD at POS of CODE, little-endian; -> POS + 4"
  (declare (type (simple-array (unsigned-byte 8) (16384)) code)
           (type (unsigned-byte 32) pos word))
  (dotimes (i 4)
    (setf (aref code (+ pos i)) (ldb (byte 8 (* 8 i)) word)))
  (+ pos 4))

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