2 Copyright
(c) 2005 Risto Laakso
5 Redistribution and use in source and binary forms
, with or without
6 modification
, are permitted provided that the following conditions
8 1. Redistributions of source code must retain the above copyright
9 notice
, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice
, this list of conditions and the following disclaimer in the
12 documentation and
/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR
``AS IS
'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES
, INCLUDING
, BUT NOT LIMITED TO
, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT
, INDIRECT
,
20 INCIDENTAL
, SPECIAL
, EXEMPLARY
, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT
21 NOT LIMITED TO
, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES
; LOSS OF USE,
22 DATA
, OR PROFITS
; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY
, WHETHER IN CONTRACT
, STRICT LIABILITY
, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE
) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE
, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 (defun vect-ea (vect &optional
(idx nil
))
29 `(make-ea :dword
:base
,vect
,@(if idx
`(:index
,idx
))
30 :disp
(- (* vector-data-offset n-word-bytes
) other-pointer-lowtag
)))
32 (defun gen-vops-to-file (filename)
33 (with-open-file (stream filename
:direction
:output
:if-exists
:supersede
)
36 (defun gen-vops (&optional
(stream t
))
38 (format stream
"(in-package :sb-vm)~%~%")
41 (loop for
(op-name type mov-inst op-inst elem-width
) in
44 (add single-float movups addps
4)
45 (addsub single-float movups addsubps
4)
46 ;; (andnot single-float movups andnps 4)
47 ;; (and single-float movups andps 4)
48 (div single-float movups divps
4)
49 (hadd single-float movups haddps
4)
50 (hsub single-float movups hsubps
4)
51 (max single-float movups maxps
4)
52 (min single-float movups minps
4)
53 (mul single-float movups mulps
4)
54 ;; (or single-float movups orps 4)
55 (sub single-float movups subps
4)
56 ;; (xor single-float movups xorps 4)
59 (add double-float movupd addpd
8)
60 (addsub double-float movupd addsubpd
8)
61 ;; (andnot double-float movupd andnpd 8)
62 ;; (and double-float movupd andpd 8)
63 (div double-float movupd divpd
8)
64 (hadd double-float movupd haddpd
8)
65 (hsub double-float movupd hsubpd
8)
66 (max double-float movupd maxpd
8)
67 (min double-float movupd minpd
8)
68 (mul double-float movupd mulpd
8)
69 ;; (or double-float movupd orpd 8)
70 (sub double-float movupd subpd
8)
71 ;; (xor double-float movupd xorpd 8)
74 (add unsigned-byte-8 movdqu paddb
1)
75 (avg unsigned-byte-8 movdqu pavgb
1)
76 (max unsigned-byte-8 movdqu pmaxub
1)
77 (min unsigned-byte-8 movdqu pminub
1)
78 (sub unsigned-byte-8 movdqu psubb
1)
80 (and unsigned-byte-8 movdqu pand
1)
81 (andn unsigned-byte-8 movdqu pandn
1)
82 (or unsigned-byte-8 movdqu por
1)
83 (xor unsigned-byte-8 movdqu pxor
1)
86 (add unsigned-byte-16 movdqu paddw
2)
87 (avg unsigned-byte-16 movdqu pavgw
2)
88 (sub unsigned-byte-16 movdqu psubw
2)
90 (and unsigned-byte-16 movdqu pand
2)
91 (andn unsigned-byte-16 movdqu pandn
2)
92 (or unsigned-byte-16 movdqu por
2)
93 (xor unsigned-byte-16 movdqu pxor
2)
95 (shl unsigned-byte-16 movdqu psllw
2)
96 (shr unsigned-byte-16 movdqu psrlw
2)
99 (add signed-byte-16 movdqu paddw
2)
100 (max signed-byte-16 movdqu pmaxsw
2)
101 (min signed-byte-16 movdqu pminsw
2)
102 (sub signed-byte-16 movdqu psubw
2)
104 (and signed-byte-16 movdqu pand
2)
105 (andn signed-byte-16 movdqu pandn
2)
106 (or signed-byte-16 movdqu por
2)
107 (xor signed-byte-16 movdqu pxor
2)
109 (shl signed-byte-16 movdqu psllw
2)
110 (shr signed-byte-16 movdqu psraw
2)
114 (format stream
"~S~%~%"
115 `(define-vop (,(intern (let ((name (format nil
"%SSE-~A/SIMPLE-ARRAY-~A-1" op-name type
)))
116 (format t
"; defining VOP ~A..~%" name
)
121 ;;(:guard (member :sse2 *backend-subfeatures*))
124 (result :scs
(descriptor-reg))
125 (vect1 :scs
(descriptor-reg))
126 (vect2 :scs
(descriptor-reg))
127 (index :scs
(unsigned-reg)))
130 ,(intern (format nil
"SIMPLE-ARRAY-~A" type
))
131 ,(intern (format nil
"SIMPLE-ARRAY-~A" type
))
132 ,(intern (format nil
"SIMPLE-ARRAY-~A" type
))
135 (:temporary
(:sc xmm-reg
) sse-temp1
)
136 (:temporary
(:sc xmm-reg
) sse-temp2
)
140 ;; scale index by 4 (size-of single-float)
141 (inst shl index
,(floor (log elem-width
2)))
144 (inst ,mov-inst sse-temp1
,(vect-ea 'vect1
'index
))
145 (inst ,mov-inst sse-temp2
,(vect-ea 'vect2
'index
))
148 (inst ,op-inst sse-temp1 sse-temp2
)
151 (inst ,mov-inst
,(vect-ea 'result
'index
) sse-temp1
)
154 ;; TWO-ARG SSE VOPs w/ DIFFERENT ARG TYPES
155 (loop for
(op-name type1 type2 mov-inst1 mov-inst2 op-inst elem-width
) in
157 (andnot single-float unsigned-byte-8 movups movdqu andnps
4)
158 (and single-float unsigned-byte-8 movups movdqu andps
4)
159 (or single-float unsigned-byte-8 movups movdqu orps
4)
160 (xor single-float unsigned-byte-8 movups movdqu xorps
4)
162 (andnot double-float unsigned-byte-8 movupd movdqu andnpd
4)
163 (and double-float unsigned-byte-8 movupd movdqu andpd
4)
164 (or double-float unsigned-byte-8 movupd movdqu orpd
4)
165 (xor double-float unsigned-byte-8 movupd movdqu xorpd
4)
168 (format stream
"~S~%~%"
169 `(define-vop (,(intern (let ((name (format nil
"%SSE-~A/SIMPLE-ARRAY-~A/SIMPLE-ARRAY-~A-1" op-name type1 type2
)))
170 (format t
"; defining VOP ~A..~%" name
)
175 ;;(:guard (member :sse2 *backend-subfeatures*))
178 (result :scs
(descriptor-reg))
179 (vect1 :scs
(descriptor-reg))
180 (vect2 :scs
(descriptor-reg))
181 (index :scs
(unsigned-reg)))
184 ,(intern (format nil
"SIMPLE-ARRAY-~A" type2
))
185 ,(intern (format nil
"SIMPLE-ARRAY-~A" type1
))
186 ,(intern (format nil
"SIMPLE-ARRAY-~A" type2
))
189 (:temporary
(:sc xmm-reg
) sse-temp1
)
190 (:temporary
(:sc xmm-reg
) sse-temp2
)
194 ;; scale index by 4 (size-of single-float)
195 (inst shl index
,(floor (log elem-width
2)))
198 (inst ,mov-inst1 sse-temp1
,(vect-ea 'vect1
'index
))
199 (inst ,mov-inst2 sse-temp2
,(vect-ea 'vect2
))
202 (inst ,op-inst sse-temp1 sse-temp2
)
205 (inst ,mov-inst2
,(vect-ea 'result
'index
) sse-temp1
)
209 ;; SINGLE-ARG SSE VOPs
210 (loop for
(op-name type mov-inst op-inst elem-width
) in
212 (recip single-float movups rcpps
4)
213 (rsqrt single-float movups rsqrtps
4)
214 (sqrt single-float movups sqrtps
4)
215 (sqrt double-float movupd sqrtpd
8)
218 (format stream
"~S~%~%"
219 `(define-vop (,(intern (let ((name (format nil
"%SSE-~A/SIMPLE-ARRAY-~A-1" op-name type
)))
220 (format t
"; defining VOP ~A..~%" name
)
224 ;;(:guard (member :sse2 *backend-subfeatures*))
227 (result :scs
(descriptor-reg))
228 (vect1 :scs
(descriptor-reg))
229 (index :scs
(unsigned-reg)))
232 ,(intern (format nil
"SIMPLE-ARRAY-~A" type
))
233 ,(intern (format nil
"SIMPLE-ARRAY-~A" type
))
236 (:temporary
(:sc xmm-reg
) sse-temp1
)
237 (:temporary
(:sc xmm-reg
) sse-temp2
)
241 ;; scale index by 4 (size-of single-float)
242 (inst shl index
,(floor (log elem-width
2)))
245 (inst ,mov-inst sse-temp1
,(vect-ea 'vect1
'index
))
248 (inst ,op-inst sse-temp2 sse-temp1
)
251 (inst ,mov-inst
,(vect-ea 'result
'index
) sse-temp2
)
255 (loop for
(op-name type mov-inst op-inst elem-width
) in
257 (cmp single-float movups cmpps
4)
258 (cmp double-float movupd cmppd
8)
261 (format stream
"~S~%~%"
262 `(define-vop (,(intern (let ((name (format nil
"%SSE-~A/SIMPLE-ARRAY-~A-1" op-name type
)))
263 (format t
"; defining VOP ~A..~%" name
)
268 ;;(:guard (member :sse2 *backend-subfeatures*))
271 (result :scs
(descriptor-reg))
272 (vect1 :scs
(descriptor-reg))
273 (vect2 :scs
(descriptor-reg))
274 (index :scs
(unsigned-reg)))
279 ,(intern (format nil
"SIMPLE-ARRAY-~A" type
))
280 ,(intern (format nil
"SIMPLE-ARRAY-~A" type
))
281 ,(intern (format nil
"SIMPLE-ARRAY-~A" type
))
286 (:temporary
(:sc xmm-reg
) sse-temp1
)
287 (:temporary
(:sc xmm-reg
) sse-temp2
)
291 ;; scale index by 4 (size-of single-float)
292 (inst shl index
,(floor (log elem-width
2)))
295 (inst ,mov-inst sse-temp1
,(vect-ea 'vect1
'index
))
296 (inst ,mov-inst sse-temp2
,(vect-ea 'vect2
'index
))
299 (inst ,op-inst sse-temp1 sse-temp2 cond
)
302 (inst ,mov-inst
,(vect-ea 'result
'index
) sse-temp1
)