Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Define hundreds of tests and scalar operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoheisig committed Aug 11, 2021
1 parent fc9cf5a commit 892ecdd
Show file tree
Hide file tree
Showing 32 changed files with 1,812 additions and 335 deletions.
38 changes: 38 additions & 0 deletions code/define-arefs.lisp
Expand Up @@ -203,3 +203,41 @@
collect `(define-setf-aref ,name))))

(define-arefs)

(in-package #:sb-simd-common)

;;; New we define reffers for scalars. Those can be defined simply in
;;; terms of built-in Common Lisp functions.
(macrolet ((define-reffer (type aref row-major-aref)
`(progn
(define-inline ,row-major-aref (array index)
(declare (type (array ,type) array))
(row-major-aref array index))
(define-inline (setf ,row-major-aref) (value array index)
(declare (type ,type value)
(type (array ,type) array))
(setf (row-major-aref array index) value))
(defun ,aref (array &rest subscripts)
(declare (type (array ,type) array))
(apply #'aref array subscripts))
(defun (setf ,aref) (value array &rest subscripts)
(declare (type ,type value)
(type (array ,type) array))
(setf (apply #'aref array subscripts) value))
(define-compiler-macro ,aref (array &rest subscripts)
`(aref (the (array ,',type) ,array) ,@subscripts))
(define-compiler-macro (setf ,aref) (value array &rest subscripts)
(let ((v (gensym "VALUE")))
`(let ((,v ,value))
(setf (aref (the (array ,',type) ,array) ,@subscripts)
,v)))))))
(define-reffer f32 f32-aref f32-row-major-aref)
(define-reffer f64 f64-aref f64-row-major-aref)
(define-reffer u8 u8-aref u8-row-major-aref)
(define-reffer u16 u16-aref u16-row-major-aref)
(define-reffer u32 u32-aref u32-row-major-aref)
(define-reffer u64 u64-aref u64-row-major-aref)
(define-reffer s8 s8-aref s8-row-major-aref)
(define-reffer s16 s16-aref s16-row-major-aref)
(define-reffer s32 s32-aref s32-row-major-aref)
(define-reffer s64 s64-aref s64-row-major-aref))
106 changes: 104 additions & 2 deletions code/define-commutatives.lisp
Expand Up @@ -50,10 +50,88 @@

(in-package #:sb-simd-common)

(define-commutative f32+ two-arg-f32+ 0f0)
(define-commutative f32-and two-arg-f32-and +f32-true+)
(define-commutative f32-or two-arg-f32-or +f32-false+)
(define-commutative f32-xor two-arg-f32-xor +f32-false+)
(define-commutative f32-max two-arg-f32-max)
(define-commutative f32-min two-arg-f32-min)
(define-commutative f32+ two-arg-f32+ 0f0)
(define-commutative f32* two-arg-f32* 1f0)

(define-commutative f64-and two-arg-f64-and +f64-true+)
(define-commutative f64-or two-arg-f64-or +f64-false+)
(define-commutative f64-xor two-arg-f64-xor +f64-false+)
(define-commutative f64-max two-arg-f64-max)
(define-commutative f64-min two-arg-f64-min)
(define-commutative f64+ two-arg-f64+ 0d0)
(define-commutative f64* two-arg-f64* 1d0)

(define-commutative u8-and two-arg-u8-and +u8-true+)
(define-commutative u8-or two-arg-u8-or +u8-false+)
(define-commutative u8-xor two-arg-u8-xor +u8-false+)
(define-commutative u8-max two-arg-u8-max)
(define-commutative u8-min two-arg-u8-min)
(define-commutative u8+ two-arg-u8+ 0)

(define-commutative u16-and two-arg-u16-and +u16-true+)
(define-commutative u16-or two-arg-u16-or +u16-false+)
(define-commutative u16-xor two-arg-u16-xor +u16-false+)
(define-commutative u16-max two-arg-u16-max)
(define-commutative u16-min two-arg-u16-min)
(define-commutative u16+ two-arg-u16+ 0)

(define-commutative u32-and two-arg-u32-and +u32-true+)
(define-commutative u32-or two-arg-u32-or +u32-false+)
(define-commutative u32-xor two-arg-u32-xor +u32-false+)
(define-commutative u32-max two-arg-u32-max)
(define-commutative u32-min two-arg-u32-min)
(define-commutative u32+ two-arg-u32+ 0)

(define-commutative u64-and two-arg-u64-and +u64-true+)
(define-commutative u64-or two-arg-u64-or +u64-false+)
(define-commutative u64-xor two-arg-u64-xor +u64-false+)
(define-commutative u64-max two-arg-u64-max)
(define-commutative u64-min two-arg-u64-min)
(define-commutative u64+ two-arg-u64+ 0)

(define-commutative s8-and two-arg-s8-and +s8-true+)
(define-commutative s8-or two-arg-s8-or +s8-false+)
(define-commutative s8-xor two-arg-s8-xor +s8-false+)
(define-commutative s8-max two-arg-s8-max)
(define-commutative s8-min two-arg-s8-min)
(define-commutative s8+ two-arg-s8+ 0)

(define-commutative s16-and two-arg-s16-and +s16-true+)
(define-commutative s16-or two-arg-s16-or +s16-false+)
(define-commutative s16-xor two-arg-s16-xor +s16-false+)
(define-commutative s16-max two-arg-s16-max)
(define-commutative s16-min two-arg-s16-min)
(define-commutative s16+ two-arg-s16+ 0)

(define-commutative s32-and two-arg-s32-and +s32-true+)
(define-commutative s32-or two-arg-s32-or +s32-false+)
(define-commutative s32-xor two-arg-s32-xor +s32-false+)
(define-commutative s32-max two-arg-s32-max)
(define-commutative s32-min two-arg-s32-min)
(define-commutative s32+ two-arg-s32+ 0)

(define-commutative s64-and two-arg-s64-and +s64-true+)
(define-commutative s64-or two-arg-s64-or +s64-false+)
(define-commutative s64-xor two-arg-s64-xor +s64-false+)
(define-commutative s64-max two-arg-s64-max)
(define-commutative s64-min two-arg-s64-min)
(define-commutative s64+ two-arg-s64+ 0)

(in-package #:sb-simd-sse)

(define-commutative f32-and two-arg-f32-and +f32-true+)
(define-commutative f32-or two-arg-f32-or +f32-false+)
(define-commutative f32-xor two-arg-f32-xor +f32-false+)
(define-commutative f32-max two-arg-f32-max)
(define-commutative f32-min two-arg-f32-min)
(define-commutative f32+ two-arg-f32+ 0f0)
(define-commutative f32* two-arg-f32* 1f0)

(define-commutative f32.4-and two-arg-f32.4-and +f32-true+)
(define-commutative f32.4-or two-arg-f32.4-or +f32-false+)
(define-commutative f32.4-xor two-arg-f32.4-xor +f32-false+)
Expand All @@ -64,6 +142,14 @@

(in-package #:sb-simd-sse2)

(define-commutative f64-and two-arg-f64-and +f64-true+)
(define-commutative f64-or two-arg-f64-or +f64-false+)
(define-commutative f64-xor two-arg-f64-xor +f64-false+)
(define-commutative f64-max two-arg-f64-max)
(define-commutative f64-min two-arg-f64-min)
(define-commutative f64+ two-arg-f64+ 0d0)
(define-commutative f64* two-arg-f64* 1d0)

(define-commutative f64.2-and two-arg-f64.2-and +f64-true+)
(define-commutative f64.2-or two-arg-f64.2-or +f64-false+)
(define-commutative f64.2-xor two-arg-f64.2-xor +f64-false+)
Expand Down Expand Up @@ -135,6 +221,22 @@

(in-package #:sb-simd-avx)

(define-commutative f32-and two-arg-f32-and +f32-true+)
(define-commutative f32-or two-arg-f32-or +f32-false+)
(define-commutative f32-xor two-arg-f32-xor +f32-false+)
(define-commutative f32-max two-arg-f32-max)
(define-commutative f32-min two-arg-f32-min)
(define-commutative f32+ two-arg-f32+ 0f0)
(define-commutative f32* two-arg-f32* 1f0)

(define-commutative f64-and two-arg-f64-and +f64-true+)
(define-commutative f64-or two-arg-f64-or +f64-false+)
(define-commutative f64-xor two-arg-f64-xor +f64-false+)
(define-commutative f64-max two-arg-f64-max)
(define-commutative f64-min two-arg-f64-min)
(define-commutative f64+ two-arg-f64+ 0d0)
(define-commutative f64* two-arg-f64* 1d0)

(define-commutative f32.4-and two-arg-f32.4-and +f32-true+)
(define-commutative f32.4-or two-arg-f32.4-or +f32-false+)
(define-commutative f32.4-xor two-arg-f32.4-xor +f32-false+)
Expand Down Expand Up @@ -200,7 +302,7 @@

(define-commutative s32.4-and two-arg-s32.4-and +s32-true+)
(define-commutative s32.4-or two-arg-s32.4-or +s32-false+)
(define-commutative s32.4-xor two-arg-s32.4-xor) +s32-false+
(define-commutative s32.4-xor two-arg-s32.4-xor +s32-false+)
(define-commutative s32.4+ two-arg-s32.4+ 0)
(define-commutative s32.4-mullo two-arg-s32.4-mullo 1)

Expand Down
131 changes: 126 additions & 5 deletions code/define-comparisons.lisp
Expand Up @@ -34,16 +34,84 @@
collect `(,',cmp ,a ,b)
until (null rest))))))))))))

(in-package #:sb-simd-common)

(define-comparison f32= two-arg-f32= u32-and +u32-true+)
(define-comparison f32< two-arg-f32< u32-and +u32-true+)
(define-comparison f32<= two-arg-f32<= u32-and +u32-true+)
(define-comparison f32> two-arg-f32> u32-and +u32-true+)
(define-comparison f32>= two-arg-f32>= u32-and +u32-true+)

(define-comparison f64= two-arg-f64= u64-and +u64-true+)
(define-comparison f64< two-arg-f64< u64-and +u64-true+)
(define-comparison f64<= two-arg-f64<= u64-and +u64-true+)
(define-comparison f64> two-arg-f64> u64-and +u64-true+)
(define-comparison f64>= two-arg-f64>= u64-and +u64-true+)

(define-comparison u8= two-arg-u8= u8-and +u8-true+)
(define-comparison u8< two-arg-u8< u8-and +u8-true+)
(define-comparison u8<= two-arg-u8<= u8-and +u8-true+)
(define-comparison u8> two-arg-u8> u8-and +u8-true+)
(define-comparison u8>= two-arg-u8>= u8-and +u8-true+)

(define-comparison u16= two-arg-u16= u16-and +u16-true+)
(define-comparison u16< two-arg-u16< u16-and +u16-true+)
(define-comparison u16<= two-arg-u16<= u16-and +u16-true+)
(define-comparison u16> two-arg-u16> u16-and +u16-true+)
(define-comparison u16>= two-arg-u16>= u16-and +u16-true+)

(define-comparison u32= two-arg-u32= u32-and +u32-true+)
(define-comparison u32< two-arg-u32< u32-and +u32-true+)
(define-comparison u32<= two-arg-u32<= u32-and +u32-true+)
(define-comparison u32> two-arg-u32> u32-and +u32-true+)
(define-comparison u32>= two-arg-u32>= u32-and +u32-true+)

(define-comparison u64= two-arg-u64= u64-and +u64-true+)
(define-comparison u64< two-arg-u64< u64-and +u64-true+)
(define-comparison u64<= two-arg-u64<= u64-and +u64-true+)
(define-comparison u64> two-arg-u64> u64-and +u64-true+)
(define-comparison u64>= two-arg-u64>= u64-and +u64-true+)

(define-comparison s8= two-arg-s8= u8-and +u8-true+)
(define-comparison s8< two-arg-s8< u8-and +u8-true+)
(define-comparison s8<= two-arg-s8<= u8-and +u8-true+)
(define-comparison s8> two-arg-s8> u8-and +u8-true+)
(define-comparison s8>= two-arg-s8>= u8-and +u8-true+)

(define-comparison s16= two-arg-s16= u16-and +u16-true+)
(define-comparison s16< two-arg-s16< u16-and +u16-true+)
(define-comparison s16<= two-arg-s16<= u16-and +u16-true+)
(define-comparison s16> two-arg-s16> u16-and +u16-true+)
(define-comparison s16>= two-arg-s16>= u16-and +u16-true+)

(define-comparison s32= two-arg-s32= u32-and +u32-true+)
(define-comparison s32< two-arg-s32< u32-and +u32-true+)
(define-comparison s32<= two-arg-s32<= u32-and +u32-true+)
(define-comparison s32> two-arg-s32> u32-and +u32-true+)
(define-comparison s32>= two-arg-s32>= u32-and +u32-true+)

(define-comparison s64= two-arg-s64= u64-and +u64-true+)
(define-comparison s64< two-arg-s64< u64-and +u64-true+)
(define-comparison s64<= two-arg-s64<= u64-and +u64-true+)
(define-comparison s64> two-arg-s64> u64-and +u64-true+)
(define-comparison s64>= two-arg-s64>= u64-and +u64-true+)

(in-package #:sb-simd-sse)

(define-comparison f32.4= two-arg-f32.4= sb-simd-sse2:f32.4-and +f32-true+)
(define-comparison f32.4< two-arg-f32.4< sb-simd-sse2:f32.4-and +f32-true+)
(define-comparison f32.4<= two-arg-f32.4<= sb-simd-sse2:f32.4-and +f32-true+)
(define-comparison f32.4> two-arg-f32.4> sb-simd-sse2:f32.4-and +f32-true+)
(define-comparison f32.4>= two-arg-f32.4>= sb-simd-sse2:f32.4-and +f32-true+)
(define-comparison f32= two-arg-f32= u32-and +u32-true+)
(define-comparison f32< two-arg-f32< u32-and +u32-true+)
(define-comparison f32<= two-arg-f32<= u32-and +u32-true+)
(define-comparison f32> two-arg-f32> u32-and +u32-true+)
(define-comparison f32>= two-arg-f32>= u32-and +u32-true+)

(in-package #:sb-simd-sse2)

(define-comparison f64= two-arg-f64= u64-and +u64-true+)
(define-comparison f64< two-arg-f64< u64-and +u64-true+)
(define-comparison f64<= two-arg-f64<= u64-and +u64-true+)
(define-comparison f64> two-arg-f64> u64-and +u64-true+)
(define-comparison f64>= two-arg-f64>= u64-and +u64-true+)

(define-comparison f32.4= two-arg-f32.4= sb-simd-sse2:u32.4-and +u32-true+)
(define-comparison f32.4< two-arg-f32.4< sb-simd-sse2:u32.4-and +u32-true+)
(define-comparison f32.4<= two-arg-f32.4<= sb-simd-sse2:u32.4-and +u32-true+)
Expand All @@ -56,6 +124,42 @@
(define-comparison f64.2> two-arg-f64.2> u64.2-and +u64-true+)
(define-comparison f64.2>= two-arg-f64.2>= u64.2-and +u64-true+)

(define-comparison u8.16= two-arg-u8.16= u8.16-and +u8-true+)
(define-comparison u8.16< two-arg-u8.16< u8.16-and +u8-true+)
(define-comparison u8.16<= two-arg-u8.16<= u8.16-and +u8-true+)
(define-comparison u8.16> two-arg-u8.16> u8.16-and +u8-true+)
(define-comparison u8.16>= two-arg-u8.16>= u8.16-and +u8-true+)

(define-comparison u16.8= two-arg-u16.8= u16.8-and +u16-true+)
(define-comparison u16.8< two-arg-u16.8< u16.8-and +u16-true+)
(define-comparison u16.8<= two-arg-u16.8<= u16.8-and +u16-true+)
(define-comparison u16.8> two-arg-u16.8> u16.8-and +u16-true+)
(define-comparison u16.8>= two-arg-u16.8>= u16.8-and +u16-true+)

(define-comparison u32.4= two-arg-u32.4= u32.4-and +u32-true+)
(define-comparison u32.4< two-arg-u32.4< u32.4-and +u32-true+)
(define-comparison u32.4<= two-arg-u32.4<= u32.4-and +u32-true+)
(define-comparison u32.4> two-arg-u32.4> u32.4-and +u32-true+)
(define-comparison u32.4>= two-arg-u32.4>= u32.4-and +u32-true+)

(define-comparison s8.16= two-arg-s8.16= u8.16-and +u8-true+)
(define-comparison s8.16< two-arg-s8.16< u8.16-and +u8-true+)
(define-comparison s8.16<= two-arg-s8.16<= u8.16-and +u8-true+)
(define-comparison s8.16> two-arg-s8.16> u8.16-and +u8-true+)
(define-comparison s8.16>= two-arg-s8.16>= u8.16-and +u8-true+)

(define-comparison s16.8= two-arg-s16.8= u16.8-and +u16-true+)
(define-comparison s16.8< two-arg-s16.8< u16.8-and +u16-true+)
(define-comparison s16.8<= two-arg-s16.8<= u16.8-and +u16-true+)
(define-comparison s16.8> two-arg-s16.8> u16.8-and +u16-true+)
(define-comparison s16.8>= two-arg-s16.8>= u16.8-and +u16-true+)

(define-comparison s32.4= two-arg-s32.4= u32.4-and +u32-true+)
(define-comparison s32.4< two-arg-s32.4< u32.4-and +u32-true+)
(define-comparison s32.4<= two-arg-s32.4<= u32.4-and +u32-true+)
(define-comparison s32.4> two-arg-s32.4> u32.4-and +u32-true+)
(define-comparison s32.4>= two-arg-s32.4>= u32.4-and +u32-true+)

(in-package #:sb-simd-sse4.1)

(define-comparison u64.2= two-arg-u64.2= u64.2-and +u64-true+)
Expand All @@ -68,8 +172,25 @@
(define-comparison u64.2> two-arg-u64.2> u64.2-and +u64-true+)
(define-comparison u64.2>= two-arg-u64.2>= u64.2-and +u64-true+)

(define-comparison s64.2< two-arg-s64.2< u64.2-and +u64-true+)
(define-comparison s64.2<= two-arg-s64.2<= u64.2-and +u64-true+)
(define-comparison s64.2> two-arg-s64.2> u64.2-and +u64-true+)
(define-comparison s64.2>= two-arg-s64.2>= u64.2-and +u64-true+)

(in-package #:sb-simd-avx)

(define-comparison f32= two-arg-f32= u32-and +u32-true+)
(define-comparison f32< two-arg-f32< u32-and +u32-true+)
(define-comparison f32<= two-arg-f32<= u32-and +u32-true+)
(define-comparison f32> two-arg-f32> u32-and +u32-true+)
(define-comparison f32>= two-arg-f32>= u32-and +u32-true+)

(define-comparison f64= two-arg-f64= u64-and +u64-true+)
(define-comparison f64< two-arg-f64< u64-and +u64-true+)
(define-comparison f64<= two-arg-f64<= u64-and +u64-true+)
(define-comparison f64> two-arg-f64> u64-and +u64-true+)
(define-comparison f64>= two-arg-f64>= u64-and +u64-true+)

(define-comparison f32.4= two-arg-f32.4= u32.4-and +u32-true+)
(define-comparison f32.4< two-arg-f32.4< u32.4-and +u32-true+)
(define-comparison f32.4<= two-arg-f32.4<= u32.4-and +u32-true+)
Expand Down
44 changes: 44 additions & 0 deletions code/define-modify-macros.lisp
@@ -1,10 +1,48 @@
(in-package #:sb-simd-common)

(define-modify-macro f32-incf (&optional (num 1f0)) two-arg-f32+)
(define-modify-macro f32-decf (&optional (num 1f0)) two-arg-f32-)

(define-modify-macro f64-incf (&optional (num 1d0)) two-arg-f64+)
(define-modify-macro f64-decf (&optional (num 1d0)) two-arg-f64-)

(define-modify-macro u8-incf (&optional (num 1)) two-arg-u8+)
(define-modify-macro u8-decf (&optional (num 1)) two-arg-u8-)

(define-modify-macro u16-incf (&optional (num 1)) two-arg-u16+)
(define-modify-macro u16-decf (&optional (num 1)) two-arg-u16-)

(define-modify-macro u32-incf (&optional (num 1)) two-arg-u32+)
(define-modify-macro u32-decf (&optional (num 1)) two-arg-u32-)

(define-modify-macro u64-incf (&optional (num 1)) two-arg-u64+)
(define-modify-macro u64-decf (&optional (num 1)) two-arg-u64-)

(define-modify-macro s8-incf (&optional (num 1)) two-arg-s8+)
(define-modify-macro s8-decf (&optional (num 1)) two-arg-s8-)

(define-modify-macro s16-incf (&optional (num 1)) two-arg-s16+)
(define-modify-macro s16-decf (&optional (num 1)) two-arg-s16-)

(define-modify-macro s32-incf (&optional (num 1)) two-arg-s32+)
(define-modify-macro s32-decf (&optional (num 1)) two-arg-s32-)

(define-modify-macro s64-incf (&optional (num 1)) two-arg-s64+)
(define-modify-macro s64-decf (&optional (num 1)) two-arg-s64-)

(in-package #:sb-simd-sse)

(define-modify-macro f32-incf (&optional (num 1f0)) two-arg-f32+)
(define-modify-macro f32-decf (&optional (num 1f0)) two-arg-f32-)

(define-modify-macro f32.4-incf (&optional (num 1f0)) two-arg-f32.4+)
(define-modify-macro f32.4-decf (&optional (num 1f0)) two-arg-f32.4-)

(in-package #:sb-simd-sse2)

(define-modify-macro f64-incf (&optional (num 1d0)) two-arg-f64+)
(define-modify-macro f64-decf (&optional (num 1d0)) two-arg-f64-)

(define-modify-macro f64.2-incf (&optional (num 1d0)) two-arg-f64.2+)
(define-modify-macro f64.2-decf (&optional (num 1d0)) two-arg-f64.2-)

Expand Down Expand Up @@ -34,6 +72,12 @@

(in-package #:sb-simd-avx)

(define-modify-macro f32-incf (&optional (num 1f0)) two-arg-f32+)
(define-modify-macro f32-decf (&optional (num 1f0)) two-arg-f32-)

(define-modify-macro f64-incf (&optional (num 1d0)) two-arg-f64+)
(define-modify-macro f64-decf (&optional (num 1d0)) two-arg-f64-)

(define-modify-macro f32.4-incf (&optional (num 1f0)) two-arg-f32.4+)
(define-modify-macro f32.4-decf (&optional (num 1f0)) two-arg-f32.4-)

Expand Down

0 comments on commit 892ecdd

Please sign in to comment.