1 ;;;; the instruction set definition for the PPC
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
14 ;(def-assembler-params
15 ; :scheduler-p nil ; t when we trust the scheduler not to "fill delay slots"
18 ;;;; Constants, types, conversion functions, some disassembler stuff.
20 (defun reg-tn-encoding (tn)
21 (declare (type tn tn))
26 (if (eq (sb-name (sc-sb (tn-sc tn))) 'registers)
28 (error "~S isn't a register." tn)))))
30 (defun fp-reg-tn-encoding (tn)
31 (declare (type tn tn))
32 (unless (eq (sb-name (sc-sb (tn-sc tn))) 'float-registers)
33 (error "~S isn't a floating-point register." tn))
36 ;(sb!disassem:set-disassem-params :instruction-alignment 32)
38 (defvar *disassem-use-lisp-reg-names* t)
40 (!def-vm-support-routine location-number (loc)
47 (ecase (sb-name (sc-sb (tn-sc loc)))
49 ;; Can happen if $ZERO or $NULL are passed in.
52 (unless (zerop (tn-offset loc))
55 (+ (tn-offset loc) 32))))
65 (defparameter reg-symbols
68 (cond ((null name) nil)
69 (t (make-symbol (concatenate 'string "$" name)))))
72 (sb!disassem:define-arg-type reg
73 :printer #'(lambda (value stream dstate)
74 (declare (type stream stream) (fixnum value))
75 (let ((regname (aref reg-symbols value)))
76 (princ regname stream)
77 (sb!disassem:maybe-note-associated-storage-ref
83 (defparameter float-reg-symbols
85 (loop for n from 0 to 31 collect (make-symbol (format nil "$F~d" n)))
88 (sb!disassem:define-arg-type fp-reg
89 :printer #'(lambda (value stream dstate)
90 (declare (type stream stream) (fixnum value))
91 (let ((regname (aref float-reg-symbols value)))
92 (princ regname stream)
93 (sb!disassem:maybe-note-associated-storage-ref
99 (eval-when (:compile-toplevel :load-toplevel :execute)
100 (defparameter bo-kind-names
101 #(:bo-dnzf :bo-dnzfp :bo-dzf :bo-dzfp :bo-f :bo-fp nil nil
102 :bo-dnzt :bo-dnztp :bo-dzt :bo-dztp :bo-t :bo-tp nil nil
103 :bo-dnz :bo-dnzp :bo-dz :bo-dzp :bo-u nil nil nil
104 nil nil nil nil nil nil nil nil)))
106 (sb!disassem:define-arg-type bo-field
107 :printer #'(lambda (value stream dstate)
108 (declare (ignore dstate)
111 (princ (svref bo-kind-names value) stream)))
113 (eval-when (:compile-toplevel :load-toplevel :execute)
114 (defun valid-bo-encoding (enc)
115 (or (if (integerp enc)
116 (and (= enc (logand #x1f enc))
117 (not (null (svref bo-kind-names enc)))
119 (and enc (position enc bo-kind-names)))
120 (error "Invalid BO field spec: ~s" enc)))
124 (defparameter cr-bit-names #(:lt :gt :eq :so))
125 (defparameter cr-bit-inverse-names #(:ge :le :ne :ns))
127 (defparameter cr-field-names #(:cr0 :cr1 :cr2 :cr3 :cr4 :cr5 :cr6 :cr7))
129 (defun valid-cr-bit-encoding (enc &optional error-p)
130 (or (if (integerp enc)
131 (and (= enc (logand 3 enc))
133 (position enc cr-bit-names)
134 (if error-p (error "Invalid condition bit specifier : ~s" enc))))
136 (defun valid-cr-field-encoding (enc)
137 (let* ((field (if (integerp enc)
138 (and (= enc (logand #x7 enc)))
139 (position enc cr-field-names))))
142 (error "Invalid condition register field specifier : ~s" enc))))
144 (defun valid-bi-encoding (enc)
148 (and (= enc (logand 31 enc)) enc)
149 (position enc cr-bit-names))
150 (+ (valid-cr-field-encoding (car enc))
151 (valid-cr-bit-encoding (cadr enc))))
152 (error "Invalid BI field spec : ~s" enc)))
154 (sb!disassem:define-arg-type bi-field
155 :printer #'(lambda (value stream dstate)
156 (declare (ignore dstate)
158 (type (unsigned-byte 5) value))
159 (let* ((bitname (svref cr-bit-names (logand 3 value)))
160 (crfield (ash value -2)))
161 (declare (type (unsigned-byte 3) crfield))
163 (princ bitname stream)
164 (princ (list (svref cr-field-names crfield) bitname) stream)))))
166 (sb!disassem:define-arg-type crf
167 :printer #'(lambda (value stream dstate)
168 (declare (ignore dstate)
170 (type (unsigned-byte 3) value))
171 (princ (svref cr-field-names value) stream)))
173 (sb!disassem:define-arg-type relative-label
175 :use-label #'(lambda (value dstate)
176 (declare (type (signed-byte 14) value)
177 (type sb!disassem:disassem-state dstate))
178 (+ (ash value 2) (sb!disassem:dstate-cur-addr dstate))))
180 (eval-when (:compile-toplevel :load-toplevel :execute)
181 (defparameter trap-values-alist '((:t . 31) (:lt . 16) (:le . 20) (:eq . 4) (:lng . 6)
182 (:ge .12) (:ne . 24) (:ng . 20) (:llt . 2) (:f . 0)
183 (:lle . 6) (:lge . 5) (:lgt . 1) (:lnl . 5))))
186 (defun valid-tcond-encoding (enc)
187 (or (and (if (integerp enc) (= (logand 31 enc) enc)) enc)
188 (cdr (assoc enc trap-values-alist))
189 (error "Unknown trap condition: ~s" enc)))
191 (sb!disassem:define-arg-type to-field
193 :printer #'(lambda (value stream dstate)
194 (declare (ignore dstate)
197 (princ (or (car (rassoc value trap-values-alist))
201 (defun snarf-error-junk (sap offset &optional length-only)
202 (let* ((length (sb!sys:sap-ref-8 sap offset))
203 (vector (make-array length :element-type '(unsigned-byte 8))))
204 (declare (type sb!sys:system-area-pointer sap)
205 (type (unsigned-byte 8) length)
206 (type (simple-array (unsigned-byte 8) (*)) vector))
208 (values 0 (1+ length) nil nil))
210 (sb!kernel:copy-from-system-area sap (* sb!vm:n-byte-bits (1+ offset))
211 vector (* sb!vm:n-word-bits
212 sb!vm:vector-data-offset)
213 (* length sb!vm:n-byte-bits))
214 (collect ((sc-offsets)
216 (lengths 1) ; the length byte
218 (error-number (sb!c:read-var-integer vector index)))
221 (when (>= index length)
223 (let ((old-index index))
224 (sc-offsets (sb!c:read-var-integer vector index))
225 (lengths (- index old-index))))
231 (defun emit-conditional-branch (segment bo bi target &optional aa-p lk-p)
232 (declare (type boolean aa-p lk-p))
233 (let* ((bo (valid-bo-encoding bo))
234 (bi (valid-bi-encoding bi))
235 (aa-bit (if aa-p 1 0))
236 (lk-bit (if lk-p 1 0)))
237 (if aa-p ; Not bloody likely, bwth.
238 (emit-b-form-inst segment 16 bo bi target aa-bit lk-bit)
239 ;; the target may be >32k away, in which case we have to invert the
240 ;; test and do an absolute branch
242 ;; We emit either 4 or 8 bytes, so I think we declare this as
243 ;; preserving 4 byte alignment. If this gives us no joy, we can
244 ;; stick a nop in the long branch and then we will be
245 ;; preserving 8 byte alignment
246 segment 8 2 ; 2^2 is 4 byte alignment. I think
247 #'(lambda (segment posn magic-value)
248 (let ((delta (ash (- (label-position target posn magic-value) posn)
250 (when (typep delta '(signed-byte 14))
251 (emit-back-patch segment 4
252 #'(lambda (segment posn)
255 (ash (- (label-position target) posn) -2)
258 #'(lambda (segment posn)
259 (let ((bo (logxor 8 bo))) ;; invert the test
260 (emit-b-form-inst segment 16 bo bi
261 2 ; skip over next instruction
263 (emit-back-patch segment 4
264 #'(lambda (segment posn)
265 (emit-i-form-branch segment target lk-p)))))
270 ; non-absolute I-form: B, BL.
271 (defun emit-i-form-branch (segment target &optional lk-p)
272 (let* ((lk-bit (if lk-p 1 0)))
275 (note-fixup segment :b target)
276 (emit-i-form-inst segment 18 0 0 lk-bit))
278 (emit-back-patch segment 4
279 #'(lambda (segment posn)
283 (ash (- (label-position target) posn) -2)
287 (eval-when (:compile-toplevel :execute :load-toplevel)
288 (defparameter *spr-numbers-alist* '((:xer 1) (:lr 8) (:ctr 9))))
290 (sb!disassem:define-arg-type spr
291 :printer #'(lambda (value stream dstate)
292 (declare (ignore dstate)
293 (type (unsigned-byte 10) value))
294 (let* ((name (car (rassoc value *spr-numbers-alist*))))
297 (princ value stream)))))
299 (eval-when (:compile-toplevel :load-toplevel :execute)
300 (defparameter jump-printer
301 #'(lambda (value stream dstate)
302 (let ((addr (ash value 2)))
303 (sb!disassem:maybe-note-assembler-routine addr t dstate)
304 (write addr :base 16 :radix t :stream stream)))))
308 ;;;; dissassem:define-instruction-formats
310 (eval-when (:compile-toplevel :execute)
311 (defmacro ppc-byte (startbit &optional (endbit startbit))
312 (unless (and (typep startbit '(unsigned-byte 32))
313 (typep endbit '(unsigned-byte 32))
314 (>= endbit startbit))
316 ``(byte ,(1+ ,(- endbit startbit)) ,(- 31 ,endbit)))
318 (defparameter *ppc-field-specs-alist*
319 `((aa :field ,(ppc-byte 30))
320 (ba :field ,(ppc-byte 11 15) :type 'bi-field)
321 (bb :field ,(ppc-byte 16 20) :type 'bi-field)
322 (bd :field ,(ppc-byte 16 29) :type 'relative-label)
323 (bf :field ,(ppc-byte 6 8) :type 'crf)
324 (bfa :field ,(ppc-byte 11 13) :type 'crf)
325 (bi :field ,(ppc-byte 11 15) :type 'bi-field)
326 (bo :field ,(ppc-byte 6 10) :type 'bo-field)
327 (bt :field ,(ppc-byte 6 10) :type 'bi-field)
328 (d :field ,(ppc-byte 16 31) :sign-extend t)
329 (flm :field ,(ppc-byte 7 14) :sign-extend nil)
330 (fra :field ,(ppc-byte 11 15) :type 'fp-reg)
331 (frb :field ,(ppc-byte 16 20) :type 'fp-reg)
332 (frc :field ,(ppc-byte 21 25) :type 'fp-reg)
333 (frs :field ,(ppc-byte 6 10) :type 'fp-reg)
334 (frt :field ,(ppc-byte 6 10) :type 'fp-reg)
335 (fxm :field ,(ppc-byte 12 19) :sign-extend nil)
336 (l :field ,(ppc-byte 10) :sign-extend nil)
337 (li :field ,(ppc-byte 6 29) :sign-extend t :type 'relative-label)
338 (li-abs :field ,(ppc-byte 6 29) :sign-extend t :printer jump-printer)
339 (lk :field ,(ppc-byte 31))
340 (mb :field ,(ppc-byte 21 25) :sign-extend nil)
341 (me :field ,(ppc-byte 26 30) :sign-extend nil)
342 (nb :field ,(ppc-byte 16 20) :sign-extend nil)
343 (oe :field ,(ppc-byte 21))
344 (ra :field ,(ppc-byte 11 15) :type 'reg)
345 (rb :field ,(ppc-byte 16 20) :type 'reg)
346 (rc :field ,(ppc-byte 31))
347 (rs :field ,(ppc-byte 6 10) :type 'reg)
348 (rt :field ,(ppc-byte 6 10) :type 'reg)
349 (sh :field ,(ppc-byte 16 20) :sign-extend nil)
350 (si :field ,(ppc-byte 16 31) :sign-extend t)
351 (spr :field ,(ppc-byte 11 20) :type 'spr)
352 (to :field ,(ppc-byte 6 10) :type 'to-field)
353 (u :field ,(ppc-byte 16 19) :sign-extend nil)
354 (ui :field ,(ppc-byte 16 31) :sign-extend nil)
355 (xo21-30 :field ,(ppc-byte 21 30) :sign-extend nil)
356 (xo22-30 :field ,(ppc-byte 22 30) :sign-extend nil)
357 (xo26-30 :field ,(ppc-byte 26 30) :sign-extend nil)))
361 (sb!disassem:define-instruction-format (instr 32)
362 (op :field (byte 6 26))
363 (other :field (byte 26 0)))
365 (sb!disassem:define-instruction-format (xinstr 32 :default-printer '(:name :tab data))
366 (op-to-a :field (byte 16 16))
367 (data :field (byte 16 0)))
369 (sb!disassem:define-instruction-format (sc 32 :default-printer '(:name :tab rest))
370 (op :field (byte 6 26))
371 (rest :field (byte 26 0) :value 2))
375 (macrolet ((def-ppc-iformat ((name &optional default-printer) &rest specs)
376 (flet ((specname-field (specname)
377 (or (assoc specname *ppc-field-specs-alist*)
378 (error "Unknown ppc instruction field spec ~s" specname))))
379 (labels ((spec-field (spec)
381 (specname-field spec)
383 (cdr (specname-field (cadr spec)))))))
384 (collect ((field (list '(op :field (byte 6 26)))))
386 (field (spec-field spec)))
387 `(sb!disassem:define-instruction-format (,name 32 ,@(if default-printer `(:default-printer ,default-printer)))
390 (def-ppc-iformat (i '(:name :tab li))
393 (def-ppc-iformat (i-abs '(:name :tab li-abs))
396 (def-ppc-iformat (b '(:name :tab bo "," bi "," bd))
399 (def-ppc-iformat (d '(:name :tab rt "," d "(" ra ")"))
402 (def-ppc-iformat (d-si '(:name :tab rt "," ra "," si ))
405 (def-ppc-iformat (d-rs '(:name :tab rs "," d "(" ra ")"))
408 (def-ppc-iformat (d-rs-ui '(:name :tab ra "," rs "," ui))
411 (def-ppc-iformat (d-crf-si)
414 (def-ppc-iformat (d-crf-ui)
417 (def-ppc-iformat (d-to '(:name :tab to "," ra "," si))
420 (def-ppc-iformat (d-frt '(:name :tab frt "," d "(" ra ")"))
423 (def-ppc-iformat (d-frs '(:name :tab frs "," d "(" ra ")"))
428 ;;; There are around ... oh, 28 or so ... variants on the "X" format.
429 ;;; Some of them are only used by one instruction; some are used by dozens.
430 ;;; Some aren't used by instructions that we generate ...
432 (def-ppc-iformat (x '(:name :tab rt "," ra "," rb))
433 rt ra rb (xo xo21-30))
435 (def-ppc-iformat (x-1 '(:name :tab rt "," ra "," nb))
436 rt ra nb (xo xo21-30))
438 (def-ppc-iformat (x-4 '(:name :tab rt))
441 (def-ppc-iformat (x-5 '(:name :tab ra "," rs "," rb))
442 rs ra rb (xo xo21-30) rc)
444 (def-ppc-iformat (x-7 '(:name :tab ra "," rs "," rb))
445 rs ra rb (xo xo21-30))
447 (def-ppc-iformat (x-8 '(:name :tab ra "," rs "," nb))
448 rs ra nb (xo xo21-30))
450 (def-ppc-iformat (x-9 '(:name :tab ra "," rs "," sh))
451 rs ra sh (xo xo21-30) rc)
453 (def-ppc-iformat (x-10 '(:name :tab ra "," rs))
454 rs ra (xo xo21-30) rc)
456 (def-ppc-iformat (x-14 '(:name :tab bf "," l "," ra "," rb))
457 bf l ra rb (xo xo21-30))
459 (def-ppc-iformat (x-15 '(:name :tab bf "," l "," fra "," frb))
460 bf l fra frb (xo xo21-30))
462 (def-ppc-iformat (x-18 '(:name :tab bf))
465 (def-ppc-iformat (x-19 '(:name :tab to "," ra "," rb))
466 to ra rb (xo xo21-30))
468 (def-ppc-iformat (x-20 '(:name :tab frt "," ra "," rb))
469 frt ra rb (xo xo21-30))
471 (def-ppc-iformat (x-21 '(:name :tab frt "," rb))
472 frt rb (xo xo21-30) rc)
474 (def-ppc-iformat (x-22 '(:name :tab frt))
477 (def-ppc-iformat (x-23 '(:name :tab ra "," frs "," rb))
478 frs ra rb (xo xo21-30))
480 (def-ppc-iformat (x-24 '(:name :tab bt))
483 (def-ppc-iformat (x-25 '(:name :tab ra "," rb))
486 (def-ppc-iformat (x-26 '(:name :tab rb))
489 (def-ppc-iformat (x-27 '(:name))
495 (def-ppc-iformat (xl '(:name :tab bt "," ba "," bb))
496 bt ba bb (xo xo21-30))
498 (def-ppc-iformat (xl-bo-bi '(:name :tab bo "," bi))
499 bo bi (xo xo21-30) lk)
501 (def-ppc-iformat (xl-cr '(:name :tab bf "," bfa))
504 (def-ppc-iformat (xl-xo '(:name))
510 (def-ppc-iformat (xfx)
513 (def-ppc-iformat (xfx-fxm '(:name :tab fxm "," rs))
516 (def-ppc-iformat (xfl '(:name :tab flm "," frb))
517 flm frb (xo xo21-30) rc)
522 (def-ppc-iformat (xo '(:name :tab rt "," ra "," rb))
523 rt ra rb oe (xo xo22-30) rc)
525 (def-ppc-iformat (xo-oe '(:name :tab rt "," ra "," rb))
526 rt ra rb (xo xo22-30) rc)
528 (def-ppc-iformat (xo-a '(:name :tab rt "," ra))
529 rt ra oe (xo xo22-30) rc)
534 (def-ppc-iformat (a '(:name :tab frt "," fra "," frb "," frc))
535 frt fra frb frc (xo xo26-30) rc)
537 (def-ppc-iformat (a-tab '(:name :tab frt "," fra "," frb))
538 frt fra frb (xo xo26-30) rc)
540 (def-ppc-iformat (a-tac '(:name :tab frt "," fra "," frc))
541 frt fra frc (xo xo26-30) rc)
543 (def-ppc-iformat (a-tbc '(:name :tab frt "," frb "," frc))
544 frt frb frc (xo xo26-30) rc)
547 (def-ppc-iformat (m '(:name :tab ra "," rs "," rb "," mb "," me))
550 (def-ppc-iformat (m-sh '(:name :tab ra "," rs "," sh "," mb "," me))
556 ;;;; Primitive emitters.
559 (define-bitfield-emitter emit-word 32
562 (define-bitfield-emitter emit-short 16
565 (define-bitfield-emitter emit-i-form-inst 32
566 (byte 6 26) (byte 24 2) (byte 1 1) (byte 1 0))
568 (define-bitfield-emitter emit-b-form-inst 32
569 (byte 6 26) (byte 5 21) (byte 5 16) (byte 14 2) (byte 1 1) (byte 1 0))
571 (define-bitfield-emitter emit-sc-form-inst 32
572 (byte 6 26) (byte 26 0))
574 (define-bitfield-emitter emit-d-form-inst 32
575 (byte 6 26) (byte 5 21) (byte 5 16) (byte 16 0))
577 ; Also used for XL-form. What's the difference ?
578 (define-bitfield-emitter emit-x-form-inst 32
579 (byte 6 26) (byte 5 21) (byte 5 16) (byte 5 11) (byte 10 1) (byte 1 0))
581 (define-bitfield-emitter emit-xfx-form-inst 32
582 (byte 6 26) (byte 5 21) (byte 10 11) (byte 10 1) (byte 1 0))
584 (define-bitfield-emitter emit-xfl-form-inst 32
585 (byte 6 26) (byte 10 16) (byte 5 11) (byte 10 1) (byte 1 0))
588 (define-bitfield-emitter emit-xo-form-inst 32
589 (byte 6 26) (byte 5 21) (byte 5 16) (byte 5 11) (byte 1 10) (byte 9 1) (byte 1 0))
591 (define-bitfield-emitter emit-a-form-inst 32
592 (byte 6 26) (byte 5 21) (byte 5 16) (byte 5 11) (byte 5 6) (byte 5 1) (byte 1 0))
597 (defun unimp-control (chunk inst stream dstate)
598 (declare (ignore inst))
599 (flet ((nt (x) (if stream (sb!disassem:note x dstate))))
600 (case (xinstr-data chunk dstate)
603 (sb!disassem:handle-break-args #'snarf-error-junk stream dstate))
606 (sb!disassem:handle-break-args #'snarf-error-junk stream dstate))
607 (#.sb!vm:object-not-list-trap
608 (nt "Object not list trap"))
609 (#.sb!vm:breakpoint-trap
610 (nt "Breakpoint trap"))
611 (#.sb!vm:pending-interrupt-trap
612 (nt "Pending interrupt trap"))
615 (#.sb!vm:fun-end-breakpoint-trap
616 (nt "Function end breakpoint trap"))
617 (#.sb!vm:object-not-instance-trap
618 (nt "Object not instance trap"))
621 (eval-when (:compile-toplevel :execute)
623 (defun classify-dependencies (deplist)
624 (collect ((reads) (writes))
625 (dolist (dep deplist)
628 (writes (writes dep))))
629 (values (reads) (writes)))))
631 (macrolet ((define-xo-instruction
632 (name op xo oe-p rc-p always-reads-xer always-writes-xer cost)
633 `(define-instruction ,name (segment rt ra rb)
634 (:printer xo ((op ,op ) (xo ,xo) (oe ,(if oe-p 1 0)) (rc ,(if rc-p 1 0))))
635 (:dependencies (reads ra) (reads rb) ,@(if always-reads-xer '((reads :xer)))
636 (writes rt) ,@(if rc-p '((writes :ccr))) ,@(if (or oe-p always-writes-xer) '((writes :xer))) )
640 (emit-xo-form-inst segment ,op
647 (define-xo-oe-instruction
648 (name op xo rc-p always-reads-xer always-writes-xer cost)
649 `(define-instruction ,name (segment rt ra rb)
650 (:printer xo-oe ((op ,op) (xo ,xo) (rc ,(if rc-p 1 0))))
651 (:dependencies (reads ra) (reads rb) ,@(if always-reads-xer '((reads :xer)))
652 (writes rt) ,@(if rc-p '((writes :ccr))) ,@(if always-writes-xer '((writes :xer))))
656 (emit-xo-form-inst segment ,op
663 (define-4-xo-instructions
664 (base op xo &key always-reads-xer always-writes-xer (cost 1))
666 (define-xo-instruction ,base ,op ,xo nil nil ,always-reads-xer ,always-writes-xer ,cost)
667 (define-xo-instruction ,(symbolicate base ".") ,op ,xo nil t ,always-reads-xer ,always-writes-xer ,cost)
668 (define-xo-instruction ,(symbolicate base "O") ,op ,xo t nil ,always-reads-xer ,always-writes-xer ,cost)
669 (define-xo-instruction ,(symbolicate base "O.") ,op ,xo t t ,always-reads-xer ,always-writes-xer ,cost)))
671 (define-2-xo-oe-instructions (base op xo &key always-reads-xer always-writes-xer (cost 1))
673 (define-xo-oe-instruction ,base ,op ,xo nil ,always-reads-xer ,always-writes-xer ,cost)
674 (define-xo-oe-instruction ,(symbolicate base ".") ,op ,xo t ,always-reads-xer ,always-writes-xer ,cost)))
676 (define-xo-a-instruction (name op xo oe-p rc-p always-reads-xer always-writes-xer cost)
677 `(define-instruction ,name (segment rt ra)
678 (:printer xo-a ((op ,op) (xo ,xo) (rc ,(if rc-p 1 0)) (oe ,(if oe-p 1 0))))
679 (:dependencies (reads ra) ,@(if always-reads-xer '((reads :xer)))
680 (writes rt) ,@(if rc-p '((writes :ccr))) ,@(if always-writes-xer '((writes :xer))) )
684 (emit-xo-form-inst segment ,op
692 (define-4-xo-a-instructions (base op xo &key always-reads-xer always-writes-xer (cost 1))
694 (define-xo-a-instruction ,base ,op ,xo nil nil ,always-reads-xer ,always-writes-xer ,cost)
695 (define-xo-a-instruction ,(symbolicate base ".") ,op ,xo nil t ,always-reads-xer ,always-writes-xer ,cost)
696 (define-xo-a-instruction ,(symbolicate base "O") ,op ,xo t nil ,always-reads-xer ,always-writes-xer ,cost)
697 (define-xo-a-instruction ,(symbolicate base "O.") ,op ,xo t t ,always-reads-xer ,always-writes-xer ,cost)))
699 (define-x-instruction (name op xo &key (cost 2) other-dependencies)
700 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
701 `(define-instruction ,name (segment rt ra rb)
702 (:printer x ((op ,op) (xo ,xo)))
705 (:dependencies (reads ra) (reads rb) ,@ other-reads
706 (writes rt) ,@other-writes)
708 (emit-x-form-inst segment ,op
715 (define-x-20-instruction (name op xo &key (cost 2) other-dependencies)
716 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
717 `(define-instruction ,name (segment frt ra rb)
718 (:printer x-20 ((op ,op) (xo ,xo)))
721 (:dependencies (reads ra) (reads rb) ,@other-reads
722 (writes frt) ,@other-writes)
724 (emit-x-form-inst segment ,op
725 (fp-reg-tn-encoding frt)
731 (define-x-5-instruction (name op xo rc-p &key (cost 1) other-dependencies)
732 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
733 `(define-instruction ,name (segment ra rs rb)
734 (:printer x-5 ((op ,op) (xo ,xo) (rc ,(if rc-p 1 0))))
737 (:dependencies (reads rb) (reads rs) ,@other-reads
738 (writes ra) ,@other-writes)
740 (emit-x-form-inst segment ,op
748 (define-x-5-st-instruction (name op xo rc-p &key (cost 1) other-dependencies)
749 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
750 `(define-instruction ,name (segment rs ra rb)
751 (:printer x-5 ((op ,op) (xo ,xo) (rc ,(if rc-p 1 0))))
754 (:dependencies (reads ra) (reads rb) (reads rs) ,@other-reads
757 (emit-x-form-inst segment ,op
764 (define-x-23-st-instruction (name op xo &key (cost 1) other-dependencies)
765 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
766 `(define-instruction ,name (segment frs ra rb)
767 (:printer x-23 ((op ,op) (xo ,xo)))
770 (:dependencies (reads ra) (reads rb) (reads frs) ,@other-reads
773 (emit-x-form-inst segment ,op
774 (fp-reg-tn-encoding frs)
780 (define-x-10-instruction (name op xo rc-p &key (cost 1) other-dependencies)
781 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
782 `(define-instruction ,name (segment ra rs)
783 (:printer x-10 ((op ,op) (xo ,xo) (rc ,(if rc-p 1 0))))
786 (:dependencies (reads rs) ,@other-reads
787 (writes ra) ,@other-writes)
789 (emit-x-form-inst segment ,op
796 (define-2-x-5-instructions (name op xo &key (cost 1) other-dependencies)
798 (define-x-5-instruction ,name ,op ,xo nil :cost ,cost :other-dependencies ,other-dependencies)
799 (define-x-5-instruction ,(symbolicate name ".") ,op ,xo t :cost ,cost
800 :other-dependencies ,other-dependencies)))
802 (define-2-x-10-instructions (name op xo &key (cost 1) other-dependencies)
804 (define-x-10-instruction ,name ,op ,xo nil :cost ,cost :other-dependencies ,other-dependencies)
805 (define-x-10-instruction ,(symbolicate name ".") ,op ,xo t :cost ,cost
806 :other-dependencies ,other-dependencies)))
809 (define-x-21-instruction (name op xo rc-p &key (cost 4) other-dependencies)
810 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
811 `(define-instruction ,name (segment frt frb)
812 (:printer x-21 ((op ,op) (xo ,xo) (rc ,(if rc-p 1 0))))
815 (:dependencies (reads frb) ,@other-reads
816 (writes frt) ,@other-writes)
818 (emit-x-form-inst segment ,op
819 (fp-reg-tn-encoding frt)
821 (fp-reg-tn-encoding frb)
825 (define-2-x-21-instructions (name op xo &key (cost 4) other-dependencies)
827 (define-x-21-instruction ,name ,op ,xo nil :cost ,cost :other-dependencies ,other-dependencies)
828 (define-x-21-instruction ,(symbolicate name ".") ,op ,xo t :cost ,cost
829 :other-dependencies ,other-dependencies)))
832 (define-d-si-instruction (name op &key (fixup nil) (cost 1) other-dependencies)
833 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
834 `(define-instruction ,name (segment rt ra si)
835 (:declare (type (signed-byte 16)))
836 (:printer d-si ((op ,op)))
839 (:dependencies (reads ra) ,@other-reads
840 (writes rt) ,@other-writes)
842 (when (typep si 'fixup)
844 ((:ha :l) (note-fixup segment ,fixup si)))
846 (emit-d-form-inst segment ,op (reg-tn-encoding rt) (reg-tn-encoding ra) si)))))
848 (define-d-rs-ui-instruction (name op &key (cost 1) other-dependencies)
849 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
850 `(define-instruction ,name (segment ra rs ui)
851 (:declare (type (unsigned-byte 16) ui))
852 (:printer d-rs-ui ((op ,op)))
855 (:dependencies (reads rs) ,@other-reads
856 (writes ra) ,@other-writes)
858 (emit-d-form-inst segment ,op (reg-tn-encoding rs) (reg-tn-encoding ra) ui)))))
860 (define-d-instruction (name op &key (cost 2) other-dependencies pinned)
861 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
862 `(define-instruction ,name (segment rt ra si)
863 (:declare (type (signed-byte 16) si))
864 (:printer d ((op ,op)))
867 ,@(when pinned '(:pinned))
868 (:dependencies (reads ra) ,@other-reads
869 (writes rt) ,@other-writes)
871 (emit-d-form-inst segment ,op (reg-tn-encoding rt) (reg-tn-encoding ra) si)))))
873 (define-d-frt-instruction (name op &key (cost 3) other-dependencies)
874 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
875 `(define-instruction ,name (segment frt ra si)
876 (:declare (type (signed-byte 16) si))
877 (:printer d-frt ((op ,op)))
880 (:dependencies (reads ra) ,@other-reads
881 (writes frt) ,@other-writes)
883 (emit-d-form-inst segment ,op (fp-reg-tn-encoding frt) (reg-tn-encoding ra) si)))))
885 (define-d-rs-instruction (name op &key (cost 1) other-dependencies pinned)
886 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
887 `(define-instruction ,name (segment rs ra si)
888 (:declare (type (signed-byte 16) si))
889 (:printer d-rs ((op ,op)))
892 ,@(when pinned '(:pinned))
893 (:dependencies (reads rs) (reads ra) ,@other-reads
894 (writes :memory :partially t) ,@other-writes)
896 (emit-d-form-inst segment ,op (reg-tn-encoding rs) (reg-tn-encoding ra) si)))))
898 (define-d-frs-instruction (name op &key (cost 1) other-dependencies)
899 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
900 `(define-instruction ,name (segment frs ra si)
901 (:declare (type (signed-byte 16) si))
902 (:printer d-frs ((op ,op)))
905 (:dependencies (reads frs) (reads ra) ,@other-reads
906 (writes :memory :partially t) ,@other-writes)
908 (emit-d-form-inst segment ,op (fp-reg-tn-encoding frs) (reg-tn-encoding ra) si)))))
910 (define-a-instruction (name op xo rc &key (cost 1) other-dependencies)
911 `(define-instruction ,name (segment frt fra frb frc)
912 (:printer a ((op ,op) (xo ,xo) (rc ,rc)))
915 (:dependencies (writes frt) (reads fra) (reads frb) (reads frc) ,@other-dependencies)
917 (emit-a-form-inst segment
919 (fp-reg-tn-encoding frt)
920 (fp-reg-tn-encoding fra)
921 (fp-reg-tn-encoding frb)
922 (fp-reg-tn-encoding frb)
926 (define-2-a-instructions (name op xo &key (cost 1) other-dependencies)
928 (define-a-instruction ,name ,op ,xo 0 :cost ,cost :other-dependencies ,other-dependencies)
929 (define-a-instruction ,(symbolicate name ".")
930 ,op ,xo 1 :cost ,cost :other-dependencies ,other-dependencies)))
932 (define-a-tab-instruction (name op xo rc &key (cost 1) other-dependencies)
933 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
934 `(define-instruction ,name (segment frt fra frb)
935 (:printer a-tab ((op ,op) (xo ,xo) (rc ,rc)))
938 (:dependencies (reads fra) (reads frb) ,@other-reads
939 (writes frt) ,@other-writes)
941 (emit-a-form-inst segment
943 (fp-reg-tn-encoding frt)
944 (fp-reg-tn-encoding fra)
945 (fp-reg-tn-encoding frb)
950 (define-2-a-tab-instructions (name op xo &key (cost 1) other-dependencies)
952 (define-a-tab-instruction ,name ,op ,xo 0 :cost ,cost :other-dependencies ,other-dependencies)
953 (define-a-tab-instruction ,(symbolicate name ".")
954 ,op ,xo 1 :cost ,cost :other-dependencies ,other-dependencies)))
956 (define-a-tac-instruction (name op xo rc &key (cost 1) other-dependencies)
957 (multiple-value-bind (other-reads other-writes) (classify-dependencies other-dependencies)
958 `(define-instruction ,name (segment frt fra frc)
959 (:printer a-tac ((op ,op) (xo ,xo) (rc ,rc)))
962 (:dependencies (reads fra) (reads frb) ,@other-reads
963 (writes frt) ,@other-writes)
965 (emit-a-form-inst segment
967 (fp-reg-tn-encoding frt)
968 (fp-reg-tn-encoding fra)
970 (fp-reg-tn-encoding frc)
974 (define-2-a-tac-instructions (name op xo &key (cost 1) other-dependencies)
976 (define-a-tac-instruction ,name ,op ,xo 0 :cost ,cost :other-dependencies ,other-dependencies)
977 (define-a-tac-instruction ,(symbolicate name ".")
978 ,op ,xo 1 :cost ,cost :other-dependencies ,other-dependencies)))
980 (define-crbit-instruction (name op xo)
981 `(define-instruction ,name (segment dbit abit bbit)
982 (:printer xl ((op ,op ) (xo ,xo)))
985 (:dependencies (reads :ccr) (writes :ccr))
986 (:emitter (emit-x-form-inst segment 19
987 (valid-bi-encoding dbit)
988 (valid-bi-encoding abit)
989 (valid-bi-encoding bbit)
993 ;;; The instructions, in numerical order
995 (define-instruction unimp (segment data)
996 (:declare (type (signed-byte 16) data))
997 (:printer xinstr ((op-to-a #.(logior (ash 3 10) (ash 6 5) 0)))
998 :default :control #'unimp-control)
1001 (:emitter (emit-d-form-inst segment 3 6 0 data)))
1003 (define-instruction twi (segment tcond ra si)
1004 (:printer d-to ((op 3)))
1007 (:emitter (emit-d-form-inst segment 3 (valid-tcond-encoding tcond) (reg-tn-encoding ra) si)))
1009 (define-d-si-instruction mulli 7 :cost 5)
1010 (define-d-si-instruction subfic 8)
1012 (define-instruction cmplwi (segment crf ra &optional (ui nil ui-p))
1013 (:printer d-crf-ui ((op 10) (l 0)) '(:name :tab bf "," ra "," ui))
1014 (:dependencies (if ui-p (reads ra) (reads crf)) (writes :ccr))
1018 (setq ui ra ra crf crf :cr0))
1019 (emit-d-form-inst segment
1021 (valid-cr-field-encoding crf)
1022 (reg-tn-encoding ra)
1025 (define-instruction cmpwi (segment crf ra &optional (si nil si-p))
1026 (:printer d-crf-si ((op 11) (l 0)) '(:name :tab bf "," ra "," si))
1027 (:dependencies (if si-p (reads ra) (reads crf)) (writes :ccr))
1031 (setq si ra ra crf crf :cr0))
1032 (emit-d-form-inst segment
1034 (valid-cr-field-encoding crf)
1035 (reg-tn-encoding ra)
1038 (define-d-si-instruction addic 12 :other-dependencies ((writes :xer)))
1039 (define-d-si-instruction addic. 13 :other-dependencies ((writes :xer) (writes :ccr)))
1041 (define-d-si-instruction addi 14 :fixup :l)
1042 (define-d-si-instruction addis 15 :fixup :ha)
1044 ;; There's no real support here for branch options that decrement
1045 ;; and test the CTR :
1046 ;; (a) the instruction scheduler doesn't know that anything's happening
1048 ;; (b) Lisp may have to assume that the CTR always has a lisp
1049 ;; object/locative in it.
1051 (define-instruction bc (segment bo bi target)
1052 (:declare (type label target))
1053 (:printer b ((op 16) (aa 0) (lk 0)))
1055 (:dependencies (reads :ccr))
1057 (emit-conditional-branch segment bo bi target)))
1059 (define-instruction bcl (segment bo bi target)
1060 (:declare (type label target))
1061 (:printer b ((op 16) (aa 0) (lk 1)))
1063 (:dependencies (reads :ccr))
1065 (emit-conditional-branch segment bo bi target nil t)))
1067 (define-instruction bca (segment bo bi target)
1068 (:declare (type label target))
1069 (:printer b ((op 16) (aa 1) (lk 0)))
1071 (:dependencies (reads :ccr))
1073 (emit-conditional-branch segment bo bi target t)))
1075 (define-instruction bcla (segment bo bi target)
1076 (:declare (type label target))
1077 (:printer b ((op 16) (aa 1) (lk 1)))
1079 (:dependencies (reads :ccr))
1081 (emit-conditional-branch segment bo bi target t t)))
1083 ;;; There may (or may not) be a good reason to use this in preference to "b[la] target".
1084 ;;; I can't think of a -bad- reason ...
1086 (define-instruction bu (segment target)
1087 (:declare (type label target))
1088 (:printer b ((op 16) (bo #.(valid-bo-encoding :bo-u)) (bi 0) (aa 0) (lk 0))
1092 (emit-conditional-branch segment #.(valid-bo-encoding :bo-u) 0 target nil nil)))
1095 (define-instruction bt (segment bi target)
1096 (:printer b ((op 16) (bo #.(valid-bo-encoding :bo-t)) (aa 0) (lk 0))
1097 '(:name :tab bi "," bd))
1100 (emit-conditional-branch segment #.(valid-bo-encoding :bo-t) bi target nil nil)))
1102 (define-instruction bf (segment bi target)
1103 (:printer b ((op 16) (bo #.(valid-bo-encoding :bo-f)) (aa 0) (lk 0))
1104 '(:name :tab bi "," bd))
1107 (emit-conditional-branch segment #.(valid-bo-encoding :bo-f) bi target nil nil)))
1109 (define-instruction b? (segment cr-field-name cr-name &optional (target nil target-p))
1113 (setq target cr-name cr-name cr-field-name cr-field-name :cr0))
1114 (let* ((+cond (position cr-name cr-bit-names))
1115 (-cond (position cr-name cr-bit-inverse-names))
1119 (error "Unknown branch condition ~s" cr-name))))
1120 (cr-form (list cr-field-name (if +cond cr-name (svref cr-bit-names -cond)))))
1121 (emit-conditional-branch segment b0 cr-form target))))
1123 (define-instruction sc (segment)
1124 (:printer sc ((op 17)))
1127 (:emitter (emit-sc-form-inst segment 17 2)))
1129 (define-instruction b (segment target)
1130 (:printer i ((op 18) (aa 0) (lk 0)))
1133 (emit-i-form-branch segment target nil)))
1135 (define-instruction ba (segment target)
1136 (:printer i-abs ((op 18) (aa 1) (lk 0)))
1139 (when (typep target 'fixup)
1140 (note-fixup segment :ba target)
1142 (emit-i-form-inst segment 18 (ash target -2) 1 0)))
1145 (define-instruction bl (segment target)
1146 (:printer i ((op 18) (aa 0) (lk 1)))
1149 (emit-i-form-branch segment target t)))
1151 (define-instruction bla (segment target)
1152 (:printer i-abs ((op 18) (aa 1) (lk 1)))
1155 (when (typep target 'fixup)
1156 (note-fixup segment :ba target)
1158 (emit-i-form-inst segment 18 (ash target -2) 1 1)))
1160 (define-instruction blr (segment)
1161 (:printer xl-bo-bi ((op 19) (xo 16) (bo #.(valid-bo-encoding :bo-u))(bi 0) (lk 0)) '(:name))
1163 (:dependencies (reads :ccr) (reads :ctr))
1165 (emit-x-form-inst segment 19 (valid-bo-encoding :bo-u) 0 0 16 0)))
1167 (define-instruction bclr (segment bo bi)
1168 (:printer xl-bo-bi ((op 19) (xo 16)))
1170 (:dependencies (reads :ccr) (reads :lr))
1172 (emit-x-form-inst segment 19 (valid-bo-encoding bo) (valid-bi-encoding bi) 0 16 0)))
1174 (define-instruction bclrl (segment bo bi)
1175 (:printer xl-bo-bi ((op 19) (xo 16) (lk 1)))
1177 (:dependencies (reads :ccr) (reads :lr))
1179 (emit-x-form-inst segment 19 (valid-bo-encoding bo)
1180 (valid-bi-encoding bi) 0 16 1)))
1182 (define-crbit-instruction crnor 19 33)
1183 (define-crbit-instruction crandc 19 129)
1184 (define-instruction isync (segment)
1185 (:printer xl-xo ((op 19) (xo 150)))
1188 (:emitter (emit-x-form-inst segment 19 0 0 0 150 0)))
1190 (define-crbit-instruction crxor 19 193)
1191 (define-crbit-instruction crnand 19 225)
1192 (define-crbit-instruction crand 19 257)
1193 (define-crbit-instruction creqv 19 289)
1194 (define-crbit-instruction crorc 19 417)
1195 (define-crbit-instruction cror 19 449)
1197 (define-instruction bcctr (segment bo bi)
1198 (:printer xl-bo-bi ((op 19) (xo 528)))
1200 (:dependencies (reads :ccr) (reads :ctr))
1202 (emit-x-form-inst segment 19 (valid-bo-encoding bo) (valid-bi-encoding bi) 0 528 0)))
1204 (define-instruction bcctrl (segment bo bi)
1205 (:printer xl-bo-bi ((op 19) (xo 528) (lk 1)))
1207 (:dependencies (reads :ccr) (reads :ctr) (writes :lr))
1209 (emit-x-form-inst segment 19 (valid-bo-encoding bo) (valid-bi-encoding bi) 0 528 1)))
1211 (define-instruction bctr (segment)
1212 (:printer xl-bo-bi ((op 19) (xo 528) (bo #.(valid-bo-encoding :bo-u)) (bi 0) (lk 0)) '(:name))
1214 (:dependencies (reads :ccr) (reads :ctr))
1216 (emit-x-form-inst segment 19 #.(valid-bo-encoding :bo-u) 0 0 528 0)))
1218 (define-instruction bctrl (segment)
1219 (:printer xl-bo-bi ((op 19) (xo 528) (bo #.(valid-bo-encoding :bo-u)) (bi 0) (lk 1)) '(:name))
1221 (:dependencies (reads :ccr) (reads :ctr))
1223 (emit-x-form-inst segment 19 #.(valid-bo-encoding :bo-u) 0 0 528 1)))
1225 (define-instruction rlwimi (segment ra rs sh mb me)
1226 (:printer m-sh ((op 20) (rc 0)))
1227 (:dependencies (reads rs) (writes ra))
1230 (emit-a-form-inst segment 20 (reg-tn-encoding rs) (reg-tn-encoding ra) sh mb me 0)))
1232 (define-instruction rlwimi. (segment ra rs sh mb me)
1233 (:printer m-sh ((op 20) (rc 1)))
1234 (:dependencies (reads rs) (writes ra) (writes :ccr))
1237 (emit-a-form-inst segment 20 (reg-tn-encoding rs) (reg-tn-encoding ra) sh mb me 1)))
1239 (define-instruction rlwinm (segment ra rs sh mb me)
1240 (:printer m-sh ((op 21) (rc 0)))
1242 (:dependencies (reads rs) (writes ra))
1244 (emit-a-form-inst segment 21 (reg-tn-encoding rs) (reg-tn-encoding ra) sh mb me 0)))
1246 (define-instruction rlwinm. (segment ra rs sh mb me)
1247 (:printer m-sh ((op 21) (rc 1)))
1249 (:dependencies (reads rs) (writes ra) (writes :ccr))
1251 (emit-a-form-inst segment 21 (reg-tn-encoding rs) (reg-tn-encoding ra) sh mb me 1)))
1253 (define-instruction rlwnm (segment ra rs rb mb me)
1254 (:printer m ((op 23) (rc 0) (rb nil :type 'reg)))
1256 (:dependencies (reads rs) (writes ra) (reads rb))
1258 (emit-a-form-inst segment 23 (reg-tn-encoding rs) (reg-tn-encoding ra) (reg-tn-encoding rb) mb me 0)))
1260 (define-instruction rlwnm. (segment ra rs rb mb me)
1261 (:printer m ((op 23) (rc 1) (rb nil :type 'reg)))
1263 (:dependencies (reads rs) (reads rb) (writes ra) (writes :ccr))
1265 (emit-a-form-inst segment 23 (reg-tn-encoding rs) (reg-tn-encoding ra) (reg-tn-encoding rb) mb me 1)))
1268 (define-d-rs-ui-instruction ori 24)
1270 (define-instruction nop (segment)
1271 (:printer d-rs-ui ((op 24) (rs 0) (ra 0) (ui 0)) '(:name))
1275 (emit-d-form-inst segment 24 0 0 0)))
1277 (define-d-rs-ui-instruction oris 25)
1278 (define-d-rs-ui-instruction xori 26)
1279 (define-d-rs-ui-instruction xoris 27)
1280 (define-d-rs-ui-instruction andi. 28 :other-dependencies ((writes :ccr)))
1281 (define-d-rs-ui-instruction andis. 29 :other-dependencies ((writes :ccr)))
1283 (define-instruction cmpw (segment crf ra &optional (rb nil rb-p))
1284 (:printer x-14 ((op 31) (xo 0) (l 0)) '(:name :tab bf "," ra "," rb))
1286 (:dependencies (reads ra) (if rb-p (reads rb) (reads crf)) (reads :xer) (writes :ccr))
1289 (setq rb ra ra crf crf :cr0))
1290 (emit-x-form-inst segment
1292 (valid-cr-field-encoding crf)
1293 (reg-tn-encoding ra)
1294 (reg-tn-encoding rb)
1298 (define-instruction tw (segment tcond ra rb)
1299 (:printer x-19 ((op 31) (xo 4)))
1302 (:emitter (emit-x-form-inst segment 31 (valid-tcond-encoding tcond) (reg-tn-encoding ra) (reg-tn-encoding rb) 4 0)))
1304 (define-4-xo-instructions subfc 31 8 :always-writes-xer t)
1305 (define-4-xo-instructions addc 31 10 :always-writes-xer t)
1306 (define-2-xo-oe-instructions mulhwu 31 11 :cost 5)
1308 (define-instruction mfcr (segment rd)
1309 (:printer x-4 ((op 31) (xo 19)))
1311 (:dependencies (reads :ccr) (writes rd))
1312 (:emitter (emit-x-form-inst segment 31 (reg-tn-encoding rd) 0 0 19 0)))
1314 (define-x-instruction lwarx 31 20)
1315 (define-x-instruction lwzx 31 23)
1316 (define-2-x-5-instructions slw 31 24)
1317 (define-2-x-10-instructions cntlzw 31 26)
1318 (define-2-x-5-instructions and 31 28)
1320 (define-instruction cmplw (segment crf ra &optional (rb nil rb-p))
1321 (:printer x-14 ((op 31) (xo 32) (l 0)) '(:name :tab bf "," ra "," rb))
1323 (:dependencies (reads ra) (if rb-p (reads rb) (reads crf)) (reads :xer) (writes :ccr))
1326 (setq rb ra ra crf crf :cr0))
1327 (emit-x-form-inst segment
1329 (valid-cr-field-encoding crf)
1330 (reg-tn-encoding ra)
1331 (reg-tn-encoding rb)
1336 (define-4-xo-instructions subf 31 40)
1338 (define-x-instruction lwzux 31 55 :other-dependencies ((writes rt)))
1339 (define-2-x-5-instructions andc 31 60)
1340 (define-2-xo-oe-instructions mulhw 31 75 :cost 5)
1342 (define-x-instruction lbzx 31 87)
1343 (define-4-xo-a-instructions neg 31 104)
1344 (define-x-instruction lbzux 31 119 :other-dependencies ((writes rt)))
1345 (define-2-x-5-instructions nor 31 124)
1346 (define-4-xo-instructions subfe 31 136 :always-reads-xer t :always-writes-xer t)
1348 (define-instruction-macro sube (rt ra rb)
1349 `(inst subfe ,rt ,rb ,ra))
1351 (define-instruction-macro sube. (rt ra rb)
1352 `(inst subfe. ,rt ,rb ,ra))
1354 (define-instruction-macro subeo (rt ra rb)
1355 `(inst subfeo ,rt ,rb ,ra))
1357 (define-instruction-macro subeo. (rt ra rb)
1358 `(inst subfeo ,rt ,rb ,ra))
1360 (define-4-xo-instructions adde 31 138 :always-reads-xer t :always-writes-xer t)
1362 (define-instruction mtcrf (segment mask rt)
1363 (:printer xfx-fxm ((op 31) (xo 144)))
1365 (:dependencies (reads rt) (writes :ccr))
1366 (:emitter (emit-xfx-form-inst segment 31 (reg-tn-encoding rt) (ash mask 1) 144 0)))
1368 (define-x-5-st-instruction stwcx. 31 150 t :other-dependencies ((writes :ccr)))
1369 (define-x-5-st-instruction stwx 31 151 nil)
1370 (define-x-5-st-instruction stwux 31 183 nil :other-dependencies ((writes ra)))
1371 (define-4-xo-a-instructions subfze 31 200 :always-reads-xer t :always-writes-xer t)
1372 (define-4-xo-a-instructions addze 31 202 :always-reads-xer t :always-writes-xer t)
1373 (define-x-5-st-instruction stbx 31 215 nil)
1374 (define-4-xo-a-instructions subfme 31 232 :always-reads-xer t :always-writes-xer t)
1375 (define-4-xo-a-instructions addme 31 234 :always-reads-xer t :always-writes-xer t)
1376 (define-4-xo-instructions mullw 31 235 :cost 5)
1377 (define-x-5-st-instruction stbux 31 247 nil :other-dependencies ((writes ra)))
1378 (define-4-xo-instructions add 31 266)
1379 (define-x-instruction lhzx 31 279)
1380 (define-2-x-5-instructions eqv 31 284)
1381 (define-x-instruction lhzux 31 311 :other-dependencies ((writes ra)))
1382 (define-2-x-5-instructions xor 31 316)
1384 (define-instruction mfmq (segment rt)
1385 (:printer xfx ((op 31) (xo 339) (spr 0)) '(:name :tab rt))
1387 (:dependencies (reads :xer) (writes rt))
1388 (:emitter (emit-xfx-form-inst segment 31 (reg-tn-encoding rt) (ash 0 5) 339 0)))
1390 (define-instruction mfxer (segment rt)
1391 (:printer xfx ((op 31) (xo 339) (spr 1)) '(:name :tab rt))
1393 (:dependencies (reads :xer) (writes rt))
1394 (:emitter (emit-xfx-form-inst segment 31 (reg-tn-encoding rt) (ash 1 5) 339 0)))
1396 (define-instruction mflr (segment rt)
1397 (:printer xfx ((op 31) (xo 339) (spr 8)) '(:name :tab rt))
1399 (:dependencies (reads :lr) (writes rt))
1400 (:emitter (emit-xfx-form-inst segment 31 (reg-tn-encoding rt) (ash 8 5) 339 0)))
1402 (define-instruction mfctr (segment rt)
1403 (:printer xfx ((op 31) (xo 339) (spr 9)) '(:name :tab rt))
1405 (:dependencies (reads rt) (reads :ctr))
1406 (:emitter (emit-xfx-form-inst segment 31 (reg-tn-encoding rt) (ash 9 5) 339 0)))
1409 (define-x-instruction lhax 31 343)
1410 (define-x-instruction lhaux 31 375 :other-dependencies ((writes ra)))
1411 (define-x-5-st-instruction sthx 31 407 nil)
1412 (define-2-x-5-instructions orc 31 412)
1413 (define-x-5-st-instruction sthux 31 439 nil :other-dependencies ((writes ra)))
1415 (define-instruction or (segment ra rs rb)
1416 (:printer x-5 ((op 31) (xo 444) (rc 0)) '((:cond
1417 ((rs :same-as rb) 'mr)
1421 (:unless (:same-as rs) "," rb)))
1424 (:dependencies (reads rb) (reads rs) (writes ra))
1426 (emit-x-form-inst segment
1428 (reg-tn-encoding rs)
1429 (reg-tn-encoding ra)
1430 (reg-tn-encoding rb)
1434 (define-instruction or. (segment ra rs rb)
1435 (:printer x-5 ((op 31) (xo 444) (rc 1)) '((:cond
1436 ((rs :same-as rb) 'mr.)
1440 (:unless (:same-as rs) "," rb)))
1443 (:dependencies (reads rb) (reads rs) (writes ra))
1445 (emit-x-form-inst segment
1447 (reg-tn-encoding rs)
1448 (reg-tn-encoding ra)
1449 (reg-tn-encoding rb)
1453 (define-instruction-macro mr (ra rs)
1454 `(inst or ,ra ,rs ,rs))
1456 (define-instruction-macro mr. (ra rs)
1457 `(inst or. ,ra ,rs ,rs))
1459 (define-4-xo-instructions divwu 31 459 :cost 36)
1461 ; This is a 601-specific instruction class.
1462 (define-4-xo-instructions div 31 331 :cost 36)
1464 ; This is a 601-specific instruction.
1465 (define-instruction mtmq (segment rt)
1466 (:printer xfx ((op 31) (xo 467) (spr (ash 0 5))) '(:name :tab rt))
1468 (:dependencies (reads rt) (writes :xer))
1469 (:emitter (emit-xfx-form-inst segment 31 (reg-tn-encoding rt) (ash 0 5) 467 0)))
1471 (define-instruction mtxer (segment rt)
1472 (:printer xfx ((op 31) (xo 467) (spr (ash 1 5))) '(:name :tab rt))
1474 (:dependencies (reads rt) (writes :xer))
1475 (:emitter (emit-xfx-form-inst segment 31 (reg-tn-encoding rt) (ash 1 5) 467 0)))
1477 (define-instruction mtlr (segment rt)
1478 (:printer xfx ((op 31) (xo 467) (spr (ash 8 5))) '(:name :tab rt))
1480 (:dependencies (reads rt) (writes :lr))
1481 (:emitter (emit-xfx-form-inst segment 31 (reg-tn-encoding rt) (ash 8 5) 467 0)))
1483 (define-instruction mtctr (segment rt)
1484 (:printer xfx ((op 31) (xo 467) (spr (ash 9 5))) '(:name :tab rt))
1486 (:dependencies (reads rt) (writes :ctr))
1487 (:emitter (emit-xfx-form-inst segment 31 (reg-tn-encoding rt) (ash 9 5) 467 0)))
1490 (define-2-x-5-instructions nand 31 476)
1491 (define-4-xo-instructions divw 31 491 :cost 36)
1492 (define-instruction mcrxr (segment crf)
1493 (:printer x-18 ((op 31) (xo 512)))
1495 (:dependencies (reads :xer) (writes :ccr) (writes :xer))
1496 (:emitter (emit-x-form-inst segment 31 (valid-cr-field-encoding crf) 0 0 512 0)))
1498 (define-instruction lswx (segment rs ra rb)
1499 (:printer x ((op 31) (xo 533) (rc 0)))
1503 (:emitter (emit-x-form-inst sb!assem:segment 31 (reg-tn-encoding rs) (reg-tn-encoding ra) (reg-tn-encoding rb) 533 0)))
1504 (define-x-instruction lwbrx 31 534)
1505 (define-x-20-instruction lfsx 31 535)
1506 (define-2-x-5-instructions srw 31 536)
1507 (define-x-20-instruction lfsux 31 567 :other-dependencies ((writes ra)))
1509 (define-instruction lswi (segment rt ra rb)
1510 (:printer x-1 ((op 31) (xo 597) (rc 0)))
1514 (:emitter (emit-x-form-inst sb!assem:segment 31 (reg-tn-encoding rt) (reg-tn-encoding ra) rb 597 0)))
1516 (define-instruction sync (segment)
1517 (:printer x-27 ((op 31) (xo 598)))
1520 (:emitter (emit-x-form-inst segment 31 0 0 0 598 0)))
1521 (define-x-20-instruction lfdx 31 599)
1522 (define-x-20-instruction lfdux 31 631 :other-dependencies ((writes ra)))
1523 (define-instruction stswx (segment rs ra rb)
1524 (:printer x-5 ((op 31) (xo 661)))
1528 (:emitter (emit-x-form-inst sb!assem:segment 31
1529 (reg-tn-encoding rs)
1530 (reg-tn-encoding ra)
1531 (reg-tn-encoding rb)
1534 (define-x-5-st-instruction stwbrx 31 662 nil)
1535 (define-x-23-st-instruction stfsx 31 663)
1536 (define-x-23-st-instruction stfsux 31 695 :other-dependencies ((writes ra)))
1537 (define-instruction stswi (segment rs ra nb)
1538 (:printer x-8 ((op 31) (xo 725)))
1542 (emit-x-form-inst segment 31
1543 (reg-tn-encoding rs)
1544 (reg-tn-encoding ra)
1549 (define-x-23-st-instruction stfdx 31 727)
1550 (define-x-23-st-instruction stfdux 31 759 :other-dependencies ((writes ra)))
1551 (define-x-instruction lhbrx 31 790)
1552 (define-2-x-5-instructions sraw 31 792)
1554 (define-instruction srawi (segment ra rs rb)
1555 (:printer x-9 ((op 31) (xo 824) (rc 0)))
1558 (:dependencies (reads rs) (writes ra))
1560 (emit-x-form-inst segment 31
1561 (reg-tn-encoding rs)
1562 (reg-tn-encoding ra)
1567 (define-instruction srawi. (segment ra rs rb)
1568 (:printer x-9 ((op 31) (xo 824) (rc 1)))
1571 (:dependencies (reads rs) (writes ra))
1573 (emit-x-form-inst segment 31
1574 (reg-tn-encoding rs)
1575 (reg-tn-encoding ra)
1580 (define-instruction eieio (segment)
1581 (:printer x-27 ((op 31) (xo 854)))
1584 (:emitter (emit-x-form-inst segment 31 0 0 0 854 0)))
1586 (define-x-5-st-instruction sthbrx 31 918 nil)
1588 (define-2-x-10-instructions extsb 31 954)
1589 (define-2-x-10-instructions extsh 31 922)
1592 (define-instruction lwz (segment rt ra si)
1593 (:declare (type (or fixup (signed-byte 16)) si))
1594 (:printer d ((op 32)))
1597 (:dependencies (reads ra) (writes rt))
1599 (when (typep si 'fixup)
1600 (note-fixup segment :l si)
1602 (emit-d-form-inst segment 32 (reg-tn-encoding rt) (reg-tn-encoding ra) si)))
1604 (define-d-instruction lwzu 33 :other-dependencies ((writes ra)))
1605 (define-d-instruction lbz 34)
1606 (define-d-instruction lbzu 35 :other-dependencies ((writes ra)))
1607 (define-d-rs-instruction stw 36)
1608 (define-d-rs-instruction stwu 37 :other-dependencies ((writes ra)))
1609 (define-d-rs-instruction stb 38)
1610 (define-d-rs-instruction stbu 39 :other-dependencies ((writes ra)))
1611 (define-d-instruction lhz 40)
1612 (define-d-instruction lhzu 41 :other-dependencies ((writes ra)))
1613 (define-d-instruction lha 42)
1614 (define-d-instruction lhau 43 :other-dependencies ((writes ra)))
1615 (define-d-rs-instruction sth 44)
1616 (define-d-rs-instruction sthu 45 :other-dependencies ((writes ra)))
1617 (define-d-instruction lmw 46 :pinned t)
1618 (define-d-rs-instruction stmw 47 :pinned t)
1619 (define-d-frt-instruction lfs 48)
1620 (define-d-frt-instruction lfsu 49 :other-dependencies ((writes ra)))
1621 (define-d-frt-instruction lfd 50)
1622 (define-d-frt-instruction lfdu 51 :other-dependencies ((writes ra)))
1623 (define-d-frs-instruction stfs 52)
1624 (define-d-frs-instruction stfsu 53 :other-dependencies ((writes ra)))
1625 (define-d-frs-instruction stfd 54)
1626 (define-d-frs-instruction stfdu 55 :other-dependencies ((writes ra)))
1628 (define-2-a-tab-instructions fdivs 59 18 :cost 17)
1629 (define-2-a-tab-instructions fsubs 59 20)
1630 (define-2-a-tab-instructions fadds 59 21)
1631 (define-2-a-tac-instructions fmuls 59 25)
1632 (define-2-a-instructions fmsubs 59 28 :cost 4)
1633 (define-2-a-instructions fmadds 59 29 :cost 4)
1634 (define-2-a-instructions fnmsubs 59 30 :cost 4)
1635 (define-2-a-instructions fnmadds 59 31 :cost 4)
1637 (define-instruction fcmpu (segment crfd fra frb)
1638 (:printer x-15 ((op 63) (xo 0)))
1639 (:dependencies (reads fra) (reads frb) (reads :fpscr)
1640 (writes :fpscr) (writes :ccr))
1643 (:emitter (emit-x-form-inst segment
1645 (valid-cr-field-encoding crfd)
1646 (fp-reg-tn-encoding fra)
1647 (fp-reg-tn-encoding frb)
1652 (define-2-x-21-instructions frsp 63 12)
1653 (define-2-x-21-instructions fctiw 63 14)
1654 (define-2-x-21-instructions fctiwz 63 15)
1656 (define-2-a-tab-instructions fdiv 63 18 :cost 31)
1657 (define-2-a-tab-instructions fsub 63 20)
1658 (define-2-a-tab-instructions fadd 63 21)
1659 (define-2-a-tac-instructions fmul 63 25 :cost 5)
1660 (define-2-a-instructions fmsub 63 28 :cost 5)
1661 (define-2-a-instructions fmadd 63 29 :cost 5)
1662 (define-2-a-instructions fnmsub 63 30 :cost 5)
1663 (define-2-a-instructions fnmadd 63 31 :cost 5)
1665 (define-instruction fcmpo (segment crfd fra frb)
1666 (:printer x-15 ((op 63) (xo 32)))
1667 (:dependencies (reads fra) (reads frb) (reads :fpscr)
1668 (writes :fpscr) (writes :ccr))
1671 (:emitter (emit-x-form-inst segment
1673 (valid-cr-field-encoding crfd)
1674 (fp-reg-tn-encoding fra)
1675 (fp-reg-tn-encoding frb)
1679 (define-2-x-21-instructions fneg 63 40)
1681 (define-2-x-21-instructions fmr 63 72)
1682 (define-2-x-21-instructions fnabs 63 136)
1683 (define-2-x-21-instructions fabs 63 264)
1685 (define-instruction mffs (segment frd)
1686 (:printer x-22 ((op 63) (xo 583) (rc 0)))
1688 (:dependencies (reads :fpscr) (writes frd))
1689 (:emitter (emit-x-form-inst segment
1691 (fp-reg-tn-encoding frd)
1697 (define-instruction mffs. (segment frd)
1698 (:printer x-22 ((op 63) (xo 583) (rc 1)))
1700 (:dependencies (reads :fpscr) (writes frd))
1701 (:emitter (emit-x-form-inst segment
1703 (fp-reg-tn-encoding frd)
1709 (define-instruction mtfsf (segment mask rb)
1710 (:printer xfl ((op 63) (xo 711) (rc 0)))
1711 (:dependencies (reads rb) (writes :fpscr))
1713 (:emitter (emit-xfl-form-inst segment 63 (ash mask 1) (fp-reg-tn-encoding rb) 711 0)))
1715 (define-instruction mtfsf. (segment mask rb)
1716 (:printer xfl ((op 63) (xo 711) (rc 1)))
1718 (:dependencies (reads rb) (writes :ccr) (writes :fpscr))
1719 (:emitter (emit-xfl-form-inst segment 63 (ash mask 1) (fp-reg-tn-encoding rb) 711 1)))
1724 ;;; Here in the future, macros are our friends.
1726 (define-instruction-macro subis (rt ra simm)
1727 `(inst addis ,rt ,ra (- ,simm)))
1729 (define-instruction-macro sub (rt rb ra)
1730 `(inst subf ,rt ,ra ,rb))
1731 (define-instruction-macro sub. (rt rb ra)
1732 `(inst subf. ,rt ,ra ,rb))
1733 (define-instruction-macro subo (rt rb ra)
1734 `(inst subfo ,rt ,ra ,rb))
1735 (define-instruction-macro subo. (rt rb ra)
1736 `(inst subfo. ,rt ,ra ,rb))
1739 (define-instruction-macro subic (rt ra simm)
1740 `(inst addic ,rt ,ra (- ,simm)))
1743 (define-instruction-macro subic. (rt ra simm)
1744 `(inst addic. ,rt ,ra (- ,simm)))
1748 (define-instruction-macro subc (rt rb ra)
1749 `(inst subfc ,rt ,ra ,rb))
1750 (define-instruction-macro subc. (rt rb ra)
1751 `(inst subfc. ,rt ,ra ,rb))
1752 (define-instruction-macro subco (rt rb ra)
1753 `(inst subfco ,rt ,ra ,rb))
1754 (define-instruction-macro subco. (rt rb ra)
1755 `(inst subfco. ,rt ,ra ,rb))
1757 (define-instruction-macro subi (rt ra simm)
1758 `(inst addi ,rt ,ra (- ,simm)))
1760 (define-instruction-macro li (rt val)
1761 `(inst addi ,rt zero-tn ,val))
1763 (define-instruction-macro lis (rt val)
1764 `(inst addis ,rt zero-tn ,val))
1767 (define-instruction-macro not (ra rs)
1768 `(inst nor ,ra ,rs ,rs))
1770 (define-instruction-macro not. (ra rs)
1771 `(inst nor. ,ra ,rs ,rs))
1774 (!def-vm-support-routine emit-nop (segment)
1775 (emit-word segment #x60000000))
1777 (define-instruction-macro extlwi (ra rs n b)
1778 `(inst rlwinm ,ra ,rs ,b 0 (1- ,n)))
1780 (define-instruction-macro extlwi. (ra rs n b)
1781 `(inst rlwinm. ,ra ,rs ,b 0 (1- ,n)))
1783 (define-instruction-macro srwi (ra rs n)
1784 `(inst rlwinm ,ra ,rs (- 32 ,n) ,n 31))
1786 (define-instruction-macro srwi. (ra rs n)
1787 `(inst rlwinm. ,ra ,rs (- 32 ,n) ,n 31))
1789 (define-instruction-macro clrrwi (ra rs n)
1790 `(inst rlwinm ,ra ,rs 0 0 (- 31 ,n)))
1792 (define-instruction-macro clrrwi. (ra rs n)
1793 `(inst rlwinm. ,ra ,rs 0 0 (- 31 ,n)))
1795 (define-instruction-macro inslw (ra rs n b)
1796 `(inst rlwimi ,ra ,rs (- 32 ,b) ,b (+ ,b (1- ,n))))
1798 (define-instruction-macro inslw. (ra rs n b)
1799 `(inst rlwimi. ,ra ,rs (- 32 ,b) ,b (+ ,b (1- ,n))))
1801 (define-instruction-macro rotlw (ra rs rb)
1802 `(inst rlwnm ,ra ,rs ,rb 0 31))
1804 (define-instruction-macro rotlw. (ra rs rb)
1805 `(inst rlwnm. ,ra ,rs ,rb 0 31))
1807 (define-instruction-macro rotlwi (ra rs n)
1808 `(inst rlwinm ,ra ,rs ,n 0 31))
1810 (define-instruction-macro rotrwi (ra rs n)
1811 `(inst rlwinm ,ra ,rs (- 32 ,n) 0 31))
1813 (define-instruction-macro slwi (ra rs n)
1814 `(inst rlwinm ,ra ,rs ,n 0 (- 31 ,n)))
1816 (define-instruction-macro slwi. (ra rs n)
1817 `(inst rlwinm. ,ra ,rs ,n 0 (- 31 ,n))))
1824 ((define-conditional-branches (name bo-name)
1825 (let* ((bo-enc (valid-bo-encoding bo-name)))
1827 (define-instruction-macro ,(symbolicate name "A") (bi target)
1828 ``(inst bca ,,,bo-enc ,,bi ,,target))
1829 (define-instruction-macro ,(symbolicate name "L") (bi target)
1830 ``(inst bcl ,,,bo-enc ,,bi ,,target))
1831 (define-instruction-macro ,(symbolicate name "LA") (bi target)
1832 ``(inst bcla ,,,bo-enc ,,bi ,,target))
1833 (define-instruction-macro ,(symbolicate name "CTR") (bi target)
1834 ``(inst bcctr ,,,bo-enc ,,bi ,,target))
1835 (define-instruction-macro ,(symbolicate name "CTRL") (bi target)
1836 ``(inst bcctrl ,,,bo-enc ,,bi ,,target))
1837 (define-instruction-macro ,(symbolicate name "LR") (bi target)
1838 ``(inst bclr ,,,bo-enc ,,bi ,,target))
1839 (define-instruction-macro ,(symbolicate name "LRL") (bi target)
1840 ``(inst bclrl ,,,bo-enc ,,bi ,,target))))))
1841 (define-conditional-branches bt :bo-t)
1842 (define-conditional-branches bf :bo-f))
1846 ((define-positive-conditional-branches (name cr-bit-name)
1848 (define-instruction-macro ,name (crf &optional (target nil target-p))
1850 (setq target crf crf :cr0))
1851 `(inst bt `(,,crf ,,,cr-bit-name) ,target))
1853 (define-instruction-macro ,(symbolicate name "A") (target &optional (cr-field :cr0))
1854 ``(inst bta (,,cr-field ,,,cr-bit-name) ,,target))
1855 (define-instruction-macro ,(symbolicate name "L") (target &optional (cr-field :cr0))
1856 ``(inst btl (,,cr-field ,,,cr-bit-name) ,,target))
1857 (define-instruction-macro ,(symbolicate name "LA") (target &optional (cr-field :cr0))
1858 ``(inst btla (,,cr-field ,,,cr-bit-name) ,,target))
1859 (define-instruction-macro ,(symbolicate name "CTR") (target &optional (cr-field :cr0))
1860 ``(inst btctr (,,cr-field ,,,cr-bit-name) ,,target))
1861 (define-instruction-macro ,(symbolicate name "CTRL") (target &optional (cr-field :cr0))
1862 ``(inst btctrl (,,cr-field ,,,cr-bit-name) ,,target))
1863 (define-instruction-macro ,(symbolicate name "LR") (target &optional (cr-field :cr0))
1864 ``(inst btlr (,,cr-field ,,,cr-bit-name) ,,target))
1865 (define-instruction-macro ,(symbolicate name "LRL") (target &optional (cr-field :cr0))
1866 ``(inst btlrl (,,cr-field ,,,cr-bit-name) ,,target))
1869 (define-positive-conditional-branches beq :eq)
1870 (define-positive-conditional-branches blt :lt)
1871 (define-positive-conditional-branches bgt :gt)
1872 (define-positive-conditional-branches bso :so)
1873 (define-positive-conditional-branches bun :so))
1877 ((define-negative-conditional-branches (name cr-bit-name)
1879 (define-instruction-macro ,name (crf &optional (target nil target-p))
1881 (setq target crf crf :cr0))
1882 `(inst bf `(,,crf ,,,cr-bit-name) ,target))
1884 (define-instruction-macro ,(symbolicate name "A") (target &optional (cr-field :cr0))
1885 ``(inst bfa (,,cr-field ,,,cr-bit-name) ,,target))
1886 (define-instruction-macro ,(symbolicate name "L") (target &optional (cr-field :cr0))
1887 ``(inst bfl (,,cr-field ,,,cr-bit-name) ,,target))
1888 (define-instruction-macro ,(symbolicate name "LA") (target &optional (cr-field :cr0))
1889 ``(inst bfla (,,cr-field ,,,cr-bit-name) ,,target))
1890 (define-instruction-macro ,(symbolicate name "CTR") (target &optional (cr-field :cr0))
1891 ``(inst bfctr (,,cr-field ,,,cr-bit-name) ,,target))
1892 (define-instruction-macro ,(symbolicate name "CTRL") (target &optional (cr-field :cr0))
1893 ``(inst bfctrl (,,cr-field ,,,cr-bit-name) ,,target))
1894 (define-instruction-macro ,(symbolicate name "LR") (target &optional (cr-field :cr0))
1895 ``(inst bflr (,,cr-field ,,,cr-bit-name) ,,target))
1896 (define-instruction-macro ,(symbolicate name "LRL") (target &optional (cr-field :cr0))
1897 ``(inst bflrl (,,cr-field ,,,cr-bit-name) ,,target))
1900 (define-negative-conditional-branches bne :eq)
1901 (define-negative-conditional-branches bnl :lt)
1902 (define-negative-conditional-branches bge :lt)
1903 (define-negative-conditional-branches bng :gt)
1904 (define-negative-conditional-branches ble :gt)
1905 (define-negative-conditional-branches bns :so)
1906 (define-negative-conditional-branches bnu :so))
1910 (define-instruction-macro j (func-tn offset)
1912 (inst addi lip-tn ,func-tn ,offset)
1918 (define-instruction-macro bua (target)
1919 `(inst bca :bo-u 0 ,target))
1921 (define-instruction-macro bul (target)
1922 `(inst bcl :bo-u 0 ,target))
1924 (define-instruction-macro bula (target)
1925 `(inst bcla :bo-u 0 ,target))
1928 (define-instruction-macro blrl ()
1929 `(inst bclrl :bo-u 0))
1939 ;;; Some more macros
1941 (defun %lr (reg value)
1944 (inst li reg value))
1946 (inst ori reg zero-tn value))
1947 ((or (signed-byte 32) (unsigned-byte 32))
1948 (let* ((high-half (ldb (byte 16 16) value))
1949 (low-half (ldb (byte 16 0) value)))
1950 (declare (type (unsigned-byte 16) high-half low-half))
1951 (cond ((if (logbitp 15 low-half) (= high-half #xffff) (zerop high-half))
1952 (inst li reg low-half))
1954 (inst lis reg high-half)
1955 (unless (zerop low-half)
1956 (inst ori reg reg low-half))))))
1958 (inst lis reg value)
1959 (inst addi reg reg value))))
1961 (define-instruction-macro lr (reg value)
1966 ;;;; Instructions for dumping data and header objects.
1968 (define-instruction word (segment word)
1969 (:declare (type (or (unsigned-byte 32) (signed-byte 32)) word))
1973 (emit-word segment word)))
1975 (define-instruction short (segment short)
1976 (:declare (type (or (unsigned-byte 16) (signed-byte 16)) short))
1980 (emit-short segment short)))
1982 (define-instruction byte (segment byte)
1983 (:declare (type (or (unsigned-byte 8) (signed-byte 8)) byte))
1987 (emit-byte segment byte)))
1989 (define-bitfield-emitter emit-header-object 32
1990 (byte 24 8) (byte 8 0))
1992 (defun emit-header-data (segment type)
1995 #'(lambda (segment posn)
1998 (ash (+ posn (component-header-length))
1999 (- n-widetag-bits word-shift)))))))
2001 (define-instruction simple-fun-header-word (segment)
2005 (emit-header-data segment simple-fun-header-widetag)))
2007 (define-instruction lra-header-word (segment)
2011 (emit-header-data segment return-pc-header-widetag)))
2014 ;;;; Instructions for converting between code objects, functions, and lras.
2015 (defun emit-compute-inst (segment vop dst src label temp calc)
2017 ;; We emit either 12 or 4 bytes, so we maintain 8 byte alignments.
2019 #'(lambda (segment posn delta-if-after)
2020 (let ((delta (funcall calc label posn delta-if-after)))
2021 (when (<= (- (ash 1 15)) delta (1- (ash 1 15)))
2022 (emit-back-patch segment 4
2023 #'(lambda (segment posn)
2024 (assemble (segment vop)
2026 (funcall calc label posn 0)))))
2028 #'(lambda (segment posn)
2029 (let ((delta (funcall calc label posn 0)))
2030 (assemble (segment vop)
2031 (inst lis temp (ldb (byte 16 16) delta))
2032 (inst ori temp temp (ldb (byte 16 0) delta))
2033 (inst add dst src temp))))))
2035 ;; this function is misnamed. should be compute-code-from-lip,
2036 ;; if the use in xep-allocate-frame is typical
2037 ;; (someone says code = fn - header - label-offset + other-pointer-tag)
2038 (define-instruction compute-code-from-fn (segment dst src label temp)
2039 (:declare (type tn dst src temp) (type label label))
2040 (:attributes variable-length)
2041 (:dependencies (reads src) (writes dst) (writes temp))
2045 (emit-compute-inst segment vop dst src label temp
2046 #'(lambda (label posn delta-if-after)
2047 (- other-pointer-lowtag
2048 ;;function-pointer-type
2049 (label-position label posn delta-if-after)
2050 (component-header-length))))))
2052 ;; code = lra - other-pointer-tag - header - label-offset + other-pointer-tag
2053 (define-instruction compute-code-from-lra (segment dst src label temp)
2054 (:declare (type tn dst src temp) (type label label))
2055 (:attributes variable-length)
2056 (:dependencies (reads src) (writes dst) (writes temp))
2060 (emit-compute-inst segment vop dst src label temp
2061 #'(lambda (label posn delta-if-after)
2062 (- (+ (label-position label posn delta-if-after)
2063 (component-header-length)))))))
2065 ;; lra = code + other-pointer-tag + header + label-offset - other-pointer-tag
2066 (define-instruction compute-lra-from-code (segment dst src label temp)
2067 (:declare (type tn dst src temp) (type label label))
2068 (:attributes variable-length)
2069 (:dependencies (reads src) (writes dst) (writes temp))
2073 (emit-compute-inst segment vop dst src label temp
2074 #'(lambda (label posn delta-if-after)
2075 (+ (label-position label posn delta-if-after)
2076 (component-header-length))))))