5de988116ba2a1b364f5bd3328b3e03a820ac842
[sb-simd.git] / generate-sse-instructions.lisp
blob5de988116ba2a1b364f5bd3328b3e03a820ac842
1 #|
2 Copyright (c) 2005 Risto Laakso
3 All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
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.
29 instruction reference:
31 http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/26568.pdf
34 TODO:
36 FXRSTOR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
37 FXSAVE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
39 LDMXCSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
41 MOVDQ2Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
43 MOVQ2DQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
45 (ib-forms:)
46 PSLLD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
47 PSLLDQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
48 PSLLQ. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
49 PSLLW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
50 PSRAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
51 PSRAW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
52 PSRLD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
53 PSRLDQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
54 PSRLQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
55 PSRLW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
57 STMXCSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
62 (declaim (optimize (debug 3)))
64 (defun emit-ops (ops)
65 (loop for op in ops
66 collect `(emit-byte segment ,op) into result
67 finally (return result)))
70 (defun gen-ops (&optional (stream t))
72 ;;; instructions like:
73 ;;; ADDPS xmm1, xmm2/mem128 0F 58 /r
74 (loop for (inst . ops) in
76 ;; single precision float
77 (addps #x0F #x58)
78 (addsubps #xF2 #x0F #xD0)
79 (andnps #x0F #x55)
80 (andps #x0F #x54)
81 (divps #x0F #x5E)
82 (haddps #xF2 #x0F #x7C)
83 (hsubps #xF2 #x0F #x7D)
84 (maxps #x0F #x5F)
85 (minps #x0F #x5D)
86 (mulps #x0F #x59)
87 (orps #x0F #x56)
88 (rcpps #x0F #x53)
89 (rsqrtps #x0F #x52)
90 (sqrtps #x0F #x51)
91 (subps #x0F #x5C)
92 (unpckhps #x0F #x15)
93 (unpcklps #x0F #x14)
94 (xorps #x0F #x57)
96 ;; double precision float
97 (addpd #x66 #x0F #x58)
98 (addsubpd #x66 #x0F #xD0)
99 (andnpd #x66 #x0F #x55)
100 (andpd #x66 #x0F #x54)
101 (divpd #x66 #x0F #x5E)
102 (haddpd #x66 #x0F #x7C)
103 (hsubpd #x66 #x0F #x7D)
104 (maxpd #x66 #x0F #x5F)
105 (minpd #x66 #x0F #x5D)
106 (mulpd #x66 #x0F #x59)
107 (orpd #x66 #x0F #x56)
108 (sqrtpd #x66 #x0F #x51)
109 (subpd #x66 #x0F #x5C)
110 (unpckhpd #x66 #x0F #x15)
111 (unpcklpd #x66 #x0F #x14)
112 (xorpd #x66 #x0F #x57)
114 ;; scalar double precision float
115 (addsd #xF2 #x0F #x58)
116 (comisd #x66 #x0F #x2F)
117 (divsd #xF2 #x0F #x5E)
118 (maxsd #xF2 #x0F #x5F)
119 (minsd #xF2 #x0F #x5D)
120 (mulsd #xF2 #x0F #x59)
121 (sqrtsd #xF2 #x0F #x51)
122 (subsd #xF2 #x0F #x5C)
123 (ucomisd #x66 #x0F #x2E)
125 ;; scalar single precision float
126 (addss #xF3 #x0F #x58)
127 (comiss #x0F #x2F)
128 (divss #xF3 #x0F #x5E)
129 (maxss #xF3 #x0F #x5F)
130 (minss #xF3 #x0F #x5D)
131 (mulss #xF3 #x0F #x59)
132 (rcpss #xF3 #x0F #x53)
133 (rsqrtss #xF3 #x0F #x52)
134 (sqrtss #xF3 #x0F #x51)
135 (subss #xF3 #x0F #x5C)
136 (ucomiss #x0F #x2E)
139 ;; packed integer
140 (packssdw #x66 #x0F #x6B)
141 (packsswb #x66 #x0F #x63)
142 (packuswb #x66 #x0F #x67)
144 (paddb #x66 #x0F #xFC)
145 (paddd #x66 #x0F #xFE)
146 (paddq #x66 #x0F #xD4)
147 (paddsb #x66 #x0F #xEC)
148 (paddsw #x66 #x0F #xED)
149 (paddusb #x66 #x0F #xDC)
150 (paddusw #x66 #x0F #xDD)
151 (paddw #x66 #x0F #xFD)
153 (pand #x66 #x0F #xDB)
154 (pandn #x66 #x0F #xDF)
156 (pavgb #x66 #x0F #xE0)
157 (pavgw #x66 #x0F #xE3)
159 (pcmpeqb #x66 #x0F #x74)
160 (pcmpeqd #x66 #x0F #x76)
161 (pcmpeqw #x66 #x0F #x75)
162 (pcmpgtb #x66 #x0F #x64)
163 (pcmpgtd #x66 #x0F #x66)
164 (pcmpgtw #x66 #x0F #x65)
166 (pmaddwd #x66 #x0F #xF5)
168 (pmaxsw #x66 #x0F #xEE)
169 (pmaxub #x66 #x0F #xDE)
171 (pminsw #x66 #x0F #xEA)
172 (pminub #x66 #x0F #xDA)
174 (pmovmskb #x66 #x0F #xD7)
176 (pmulhuw #x66 #x0F #xE4)
177 (pmulhw #x66 #x0F #xE5)
178 (pmullw #x66 #x0F #xD5)
179 (pmuludq #x66 #x0F #xF4)
181 (por #x66 #x0F #xEB)
183 (psadbw #x66 #x0F #xF6)
184 (pssld #x66 #x0F #xF2)
185 (psllq #x66 #x0F #xF3)
186 (psllw #x66 #x0F #xF1)
187 (psrad #x66 #x0F #xE2)
188 (psraw #x66 #x0F #xE2)
189 (psrld #x66 #x0F #xD2)
190 (psrlq #x66 #x0F #xD3)
191 (psrlw #x66 #x0F #xD1)
193 (psubb #x66 #x0F #xF8)
194 (psubd #x66 #x0F #xFA)
195 (psubq #x66 #x0F #xFB)
196 (psubsb #x66 #x0F #xE8)
197 (psubsw #x66 #x0F #xE9)
198 (psubusb #x66 #x0F #xD8)
199 (psubusw #x66 #x0F #xD9)
200 (psubw #x66 #x0F #xF9)
202 (punpckhbw #x66 #x0F #x68)
203 (punpckhdq #x66 #x0F #x6A)
204 (punpckhqdq #x66 #x0F #x6D)
205 (punpckhwd #x66 #x0F #x69)
206 (punpcklbw #x66 #x0F #x60)
207 (punpckldq #x66 #x0F #x62)
208 (punpcklqdq #x66 #x0F #x6C)
209 (punpcklwd #x66 #x0F #x61)
211 (pxor #x66 #x0F #xEF)
213 ;; convert
214 (cvtdq2pd #xF3 #x0F #xE6)
215 (cvtdq2ps #x0F #x5B)
216 (cvtpd2dq #xF2 #x0F #xE6)
217 (cvtpd2pi #x66 #x0F #x2D)
218 (cvtpd2ps #x66 #x0F #x5A)
219 (cvtpi2pd #x66 #x0F #x2A)
220 (cvtpi2ps #x0F #x2A)
221 (cvtps2dq #x66 #x0F #x5B)
222 (cvtps2pd #x0F #x5A)
223 (cvtps2pi #x0F #x2D)
224 (cvtsd2si #xF2 #x0F #x2D)
225 (cvtsd2ss #xF2 #x0F #x5A)
226 (cvtsi2sd #xF2 #x0F #x2A)
227 (cvtsi2ss #xF3 #x0F #x2A)
228 (cvtss2sd #xF3 #x0F #x5A)
229 (cvtss2si #xF3 #x0F #x2D)
230 (cvttpd2dq #x66 #x0F #xE6)
231 (cvttpd2pi #x66 #x0F #x2C)
232 (cvttps2dq #xF3 #x0F #x5B)
233 (cvttps2pi #x0F #x2C)
234 (cvttsd2si #xF2 #x0F #x2C)
235 (cvttss2si #xF3 #x0F #x2C)
237 ;; misc
238 (lddqu #xF2 #x0F #xF0)
239 (maskmovdqu #x66 #x0F #xF7)
240 (movddup #xF2 #x0F #x12)
241 (movhlps #x0F #x12)
242 (movlhps #x0F #x16)
243 (movmskpd #x66 #x0F #x50)
244 (movmskps #x0F #x50)
245 (movntdq #x66 #x0F #XE7)
246 (movntpd #x66 #x0F #x2B)
247 (movntps #x0F #x2B)
248 (movshdup #xF3 #x0F #x16)
249 (movsldup #xF3 #x0F #x12)
252 (format stream "~S~%~%"
253 `(define-instruction ,(intern (symbol-name inst)) (segment dst src)
254 (:emitter
255 ,@(emit-ops ops)
256 (emit-ea segment src (reg-tn-encoding dst))))))
259 ;; INSTRUCTIONS WITH /r IB8
260 (loop for (inst . ops) in
262 (pextrw #X66 #x0F #xC5)
263 (pinsrw #x66 #x0F #xC4)
265 (pshufd #x66 #x0F #x70)
266 (pshufhw #xF3 #x0F #x70)
267 (pshuflw #xF2 #x0F #x70)
269 (shufpd #x66 #x0F #xC6)
270 (shufps #x0F #xC6)
274 (format stream "~S~%~%"
275 `(define-instruction ,(intern (symbol-name inst)) (segment dst src byte)
276 (:emitter
277 ,@(emit-ops ops)
278 (emit-ea segment src (reg-tn-encoding dst))
279 (emit-sized-immediate segment :byte byte)
280 ))))
282 ;; COMPARE
283 (loop for (inst . ops) in
285 (cmppd #x66 #x0F #xC2)
286 (cmpps #x0F #xC2)
287 (cmpsd #xF2 #x0F #xC2)
288 (cmpss #xF3 #x0F #xC2)
291 (format stream "~S~%~%"
292 `(define-instruction ,(intern (symbol-name inst)) (segment dst src cond)
293 (:emitter
294 ,@(emit-ops ops)
295 (emit-ea segment src (reg-tn-encoding dst))
296 (emit-sized-immediate segment :byte (cdr (assoc cond
297 '((:eq . #b000) (:e . #b000) (:z . #b000)
298 (:l . #b001) (:nge . #b001)
299 (:le . #b010) (:ng . #b010)
300 (:unord . #b011)
301 (:ne . #b100) (:nz . #b100)
302 (:nl . #b101) (:ge . #b101)
303 (:nle . #b110) (:g . #b110)
304 (:ord . #b111)
305 ))))
306 ))))
308 ;; MOVES
309 (loop for (inst ops-m2r ops-r2m) in
311 (movapd (#x66 #x0F #x28) (#x66 #x0F #x29))
312 (movaps (#x0F #x28) (#x0F #x29))
314 (movd (#x66 #x0F #x6E) (#x66 #x0F #x7E))
316 (movdqa (#x66 #x0F #x6F) (#x66 #x0F #x7F))
317 (movdqu (#xF3 #x0F #x6F) (#xF3 #x0F #x7F))
319 (movhpd (#x66 #x0F #x16) (#x66 #x0F #x17))
320 (movhps (#x0F #x16) (#x0F #x17))
322 (movlpd (#x66 #x0F #x12) (#x66 #x0F #x13))
323 (movlps (#x0F #x12) (#x0F #x13))
325 (movq (#xF3 #x0F #x7E) (#x66 #x0F #xD6))
327 (movsd (#xF2 #x0F #x10) (#xF2 #x0F #x11))
329 (movss (#xF3 #x0F #x10) (#xF3 #x0F #x11))
331 (movupd (#x66 #x0F #x10) (#x66 #x0F #x11))
332 (movups (#x0F #x10) (#x0F #x11))
335 (format stream "~S~%~%"
336 `(define-instruction ,(intern (symbol-name inst)) (segment dst src)
337 (:emitter
338 (cond ((sse-register-p dst)
339 ,@(emit-ops ops-m2r)
340 (emit-ea segment src (reg-tn-encoding dst)))
341 (t ,@(emit-ops ops-r2m)
342 (emit-ea segment dst (reg-tn-encoding src)))))))))
344 (defun gen-ops-to-file (filename)
345 (with-open-file (stream filename :direction :output :if-exists :supersede)
346 (gen-ops stream)))