Advertisement
Guest User

Some SSE stuff

a guest
Nov 11th, 2013
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 4.96 KB | None | 0 0
  1. (defmacro define-fast-binary-op ((op-name) &rest define-vop-args)
  2.   (let ((x (gensym))
  3.         (y (gensym)))
  4.     `(progn
  5.        (sb-c::defknown ,op-name
  6.            ((simd-pack single-float)
  7.             (simd-pack single-float))
  8.            (simd-pack single-float)
  9.            (sb-c::flushable sb-c::always-translatable))
  10.        
  11.        (sb-vm::define-vop (,op-name)
  12.          ,@(append
  13.             `((:translate ,op-name)
  14.               (:policy :fast-safe))
  15.             define-vop-args))
  16.  
  17.        (declaim (inline ,op-name))
  18.        (defun ,op-name (,x ,y)
  19.          (declare (type (simd-pack single-float) ,x ,y))
  20.          (,op-name ,x ,y)))))
  21.  
  22. (define-fast-binary-op (sse-v4sf-mul)
  23.   (:args (x :scs (sb-vm::single-sse-reg)
  24.             :target dst)
  25.          (y :scs (sb-vm::single-sse-reg)))
  26.   (:arg-types sb-vm::simd-pack-single sb-vm::simd-pack-single)
  27.   (:results (dst :scs (sb-vm::single-sse-reg) :from (:argument 0)))
  28.   (:result-types sb-vm::simd-pack-single)
  29.   (:generator 0
  30.               (sb-vm::move dst x)
  31.               (sb-vm::inst sb-vm::mulps dst y)))
  32.  
  33. (define-fast-binary-op (sse-v4sf-div)
  34.   (:args (x :scs (sb-vm::single-sse-reg)
  35.             :target dst)
  36.          (y :scs (sb-vm::single-sse-reg)))
  37.   (:arg-types sb-vm::simd-pack-single sb-vm::simd-pack-single)
  38.   (:results (dst :scs (sb-vm::single-sse-reg) :from (:argument 0)))
  39.   (:result-types sb-vm::simd-pack-single)
  40.   (:generator 0
  41.               (sb-vm::move dst x)
  42.               (sb-vm::inst sb-vm::divps dst y)))
  43.  
  44. (define-fast-binary-op (sse-v4sf-add)
  45.   (:args (x :scs (sb-vm::single-sse-reg)
  46.             :target dst)
  47.          (y :scs (sb-vm::single-sse-reg)))
  48.   (:arg-types sb-vm::simd-pack-single sb-vm::simd-pack-single)
  49.   (:results (dst :scs (sb-vm::single-sse-reg) :from (:argument 0)))
  50.   (:result-types sb-vm::simd-pack-single)
  51.   (:generator 0
  52.               (sb-vm::move dst x)
  53.               (sb-vm::inst sb-vm::addps dst y)))
  54.  
  55. (define-fast-binary-op (sse-v4sf-sub)
  56.   (:args (x :scs (sb-vm::single-sse-reg)
  57.             :target dst)
  58.          (y :scs (sb-vm::single-sse-reg)))
  59.   (:arg-types sb-vm::simd-pack-single sb-vm::simd-pack-single)
  60.   (:results (dst :scs (sb-vm::single-sse-reg) :from (:argument 0)))
  61.   (:result-types sb-vm::simd-pack-single)
  62.   (:generator 0
  63.               (sb-vm::move dst x)
  64.               (sb-vm::inst sb-vm::subps dst y)))
  65.  
  66. (define-fast-binary-op (sse-v4sf-sp)
  67.   (:args (x :scs (sb-vm::single-sse-reg)
  68.             :target dst)
  69.          (y :scs (sb-vm::single-sse-reg)))
  70.   (:arg-types sb-vm::simd-pack-single sb-vm::simd-pack-single)
  71.   (:temporary (:sc sb-vm::single-sse-reg) tmp)
  72.   (:results (dst :scs (sb-vm::single-sse-reg) :from (:argument 0)))
  73.   (:result-types sb-vm::simd-pack-single)
  74.   (:generator 5
  75.               (sb-vm::inst sb-vm::xorps tmp tmp)
  76.               (sb-vm::move dst x)
  77.               (sb-vm::inst sb-vm::movss dst tmp)
  78.               (sb-vm::inst sb-vm::mulps dst y)
  79.               (sb-vm::inst sb-vm::haddps dst dst)
  80.               (sb-vm::inst sb-vm::haddps dst dst)))
  81.  
  82. (define-fast-binary-op (sse-v4sf-cp)
  83.   (:args (x :scs (sb-vm::single-sse-reg)
  84.             :target tmp-x)
  85.          (y :scs (sb-vm::single-sse-reg)
  86.             :target tmp-y))
  87.   (:arg-types sb-vm::simd-pack-single sb-vm::simd-pack-single)
  88.   (:temporary (:sc sb-vm::single-sse-reg :from (:argument 0)) tmp-x)
  89.   (:temporary (:sc sb-vm::single-sse-reg :from (:argument 1)) tmp-y)
  90.   (:temporary (:sc sb-vm::single-sse-reg) tmp-dst)
  91.   (:results (dst :scs (sb-vm::single-sse-reg)))
  92.   (:result-types sb-vm::simd-pack-single)
  93.   (:generator 6
  94.               (sb-vm::move tmp-x x)
  95.               (sb-vm::move tmp-y y)
  96.               (sb-vm::inst sb-vm::shufps tmp-x tmp-x #b01111000)
  97.               (sb-vm::inst sb-vm::shufps tmp-y tmp-y #b10011100)
  98.               (sb-vm::move dst tmp-x)
  99.               (sb-vm::inst sb-vm::mulps dst tmp-y)
  100.  
  101.               (sb-vm::inst sb-vm::shufps tmp-x x #b10011000)
  102.               (sb-vm::inst sb-vm::shufps tmp-y y #b01111100)
  103.               (sb-vm::move tmp-dst tmp-x)
  104.               (sb-vm::inst sb-vm::mulps tmp-dst tmp-y)
  105.  
  106.               (sb-vm::inst sb-vm::subps dst tmp-dst)
  107.  
  108.               (sb-vm::inst sb-vm::xorps tmp-dst tmp-dst)
  109.               (sb-vm::inst sb-vm::movss dst tmp-dst)))
  110.              
  111. (defun cp (v1 v2)
  112.   (declare (type (simple-array single-float) v1 v2)
  113.            (optimize (speed 3)))
  114.   (let ((res (make-array 3 :element-type 'single-float)))
  115.     (declare (type (simple-array single-float)))
  116.     (setf (aref res 0) (- (* (aref v1 1)
  117.                              (aref v2 2))
  118.                           (* (aref v1 2)
  119.                              (aref v2 1)))
  120.          
  121.           (aref res 1) (- (* (aref v1 2)
  122.                              (aref v2 0))
  123.                           (* (aref v1 0)
  124.                              (aref v2 2)))
  125.          
  126.           (aref res 2) (- (* (aref v1 0)
  127.                              (aref v2 1))
  128.                           (* (aref v1 1)
  129.                              (aref v2 0))))
  130.     res))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement