Comment 2 for bug 310191

Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

;;; Here's a quick version for x86-64 as a discussion point re. API.
;;;
;;; Specifying the word-width in the API is an issue.
;;;
;;; It should also be able to byte-swap vectors of unsigned 8 using
;;; any byte-width upto, dunno, 128 bits?

(in-package :sb-c)

(defknown byte-swap (word) word
    (unsafe))

(in-package :sb-vm)

(define-vop (fast-byte-swap fast-safe-arith-op)
  (:translate sb-c::byte-swap)
  (:args (x :scs (unsigned-reg) :target res))
  (:arg-types unsigned-num)
  (:results (res :scs (unsigned-reg)))
  (:result-types unsigned-num)
  (:generator 1
   (move res x)
   (inst bswap res)))

(defun byte-swap-vector (vector)
  (declare (type (simple-array (unsigned-byte 64) (*)) vector))
  (dotimes (i (length vector))
    (setf (aref vector i) (sb-c::byte-swap (aref vector i))))
  vector)