Unify error trap argument emission via EMIT-ERROR-BREAKs
[sbcl.git] / src / compiler / x86-64 / macros.lisp
bloba2a4a208a656b25234babb9de5e56b92cd2a6d5c
1 ;;;; a bunch of handy macros for x86-64
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
12 (in-package "SB!VM")
14 ;;;; instruction-like macros
16 ;;; This used to be a macro (and still is on the other platforms) but
17 ;;; the support for SC-dependent move instructions needed here makes
18 ;;; that expand into so large an expression that the resulting code
19 ;;; bloat is not justifiable.
20 (defun move (dst src)
21 #!+sb-doc
22 "Move SRC into DST unless they are location=."
23 (unless (location= dst src)
24 (sc-case dst
25 ((single-reg complex-single-reg)
26 (aver (xmm-register-p src))
27 (inst movaps dst src))
28 ((double-reg complex-double-reg)
29 (aver (xmm-register-p src))
30 (inst movapd dst src))
31 #!+sb-simd-pack
32 ((int-sse-reg sse-reg)
33 (aver (xmm-register-p src))
34 (inst movdqa dst src))
35 #!+sb-simd-pack
36 ((single-sse-reg double-sse-reg)
37 (aver (xmm-register-p src))
38 (inst movaps dst src))
40 (inst mov dst src)))))
42 (defmacro make-ea-for-object-slot (ptr slot lowtag)
43 `(make-ea :qword :base ,ptr :disp (- (* ,slot n-word-bytes) ,lowtag)))
44 (defmacro make-ea-for-object-slot-half (ptr slot lowtag)
45 `(make-ea :dword :base ,ptr :disp (- (* ,slot n-word-bytes) ,lowtag)))
46 (defmacro tls-index-of (sym)
47 `(make-ea :dword :base ,sym :disp (+ 4 (- other-pointer-lowtag))))
49 (defmacro loadw (value ptr &optional (slot 0) (lowtag 0))
50 `(inst mov ,value (make-ea-for-object-slot ,ptr ,slot ,lowtag)))
52 (defun storew (value ptr &optional (slot 0) (lowtag 0))
53 (cond ((and (integerp value)
54 (not (typep value '(signed-byte 32))))
55 (inst mov temp-reg-tn value)
56 (inst mov (make-ea-for-object-slot ptr slot lowtag) temp-reg-tn))
58 (inst mov (make-ea-for-object-slot ptr slot lowtag) value))))
60 (defmacro pushw (ptr &optional (slot 0) (lowtag 0))
61 `(inst push (make-ea-for-object-slot ,ptr ,slot ,lowtag)))
63 (defmacro popw (ptr &optional (slot 0) (lowtag 0))
64 `(inst pop (make-ea-for-object-slot ,ptr ,slot ,lowtag)))
66 (defun call-indirect (offset)
67 (typecase offset
68 ((signed-byte 32)
69 (inst call (make-ea :qword :disp offset)))
71 (inst mov temp-reg-tn offset)
72 (inst call (make-ea :qword :base temp-reg-tn)))))
74 ;;;; macros to generate useful values
76 (defmacro load-symbol (reg symbol)
77 `(inst mov ,reg (+ nil-value (static-symbol-offset ,symbol))))
79 (defmacro make-ea-for-symbol-value (symbol)
80 `(make-ea :qword
81 :disp (+ nil-value
82 (static-symbol-offset ',symbol)
83 (ash symbol-value-slot word-shift)
84 (- other-pointer-lowtag))))
86 (defmacro load-symbol-value (reg symbol)
87 `(inst mov ,reg (make-ea-for-symbol-value ,symbol)))
89 (defmacro store-symbol-value (reg symbol)
90 `(inst mov (make-ea-for-symbol-value ,symbol) ,reg))
92 ;; Return the effective address of the value slot of static SYMBOL.
93 (defun static-symbol-value-ea (symbol)
94 (make-ea :qword
95 :disp (+ nil-value
96 (static-symbol-offset symbol)
97 (ash symbol-value-slot word-shift)
98 (- other-pointer-lowtag))))
100 #!+sb-thread
101 (progn
102 ;; Return an EA for the TLS of SYMBOL, or die.
103 (defun symbol-known-tls-cell (symbol)
104 (let ((index (info :variable :wired-tls symbol)))
105 (aver (integerp index))
106 (make-ea :qword :base thread-base-tn :disp index)))
108 ;; LOAD/STORE-TL-SYMBOL-VALUE macros are ad-hoc (ugly) emulations
109 ;; of (INFO :VARIABLE :WIRED-TLS) = :ALWAYS-THREAD-LOCAL
110 (defmacro load-tl-symbol-value (reg symbol)
111 `(inst mov ,reg (symbol-known-tls-cell ',symbol)))
113 (defmacro store-tl-symbol-value (reg symbol)
114 `(inst mov (symbol-known-tls-cell ',symbol) ,reg)))
116 #!-sb-thread
117 (progn
118 (defmacro load-tl-symbol-value (reg symbol)
119 `(load-symbol-value ,reg ,symbol))
120 (defmacro store-tl-symbol-value (reg symbol)
121 `(store-symbol-value ,reg ,symbol)))
123 (defmacro load-binding-stack-pointer (reg)
124 #!+sb-thread `(inst mov ,reg (symbol-known-tls-cell '*binding-stack-pointer*))
125 #!-sb-thread `(load-symbol-value ,reg *binding-stack-pointer*))
127 (defmacro store-binding-stack-pointer (reg)
128 #!+sb-thread `(inst mov (symbol-known-tls-cell '*binding-stack-pointer*) ,reg)
129 #!-sb-thread `(store-symbol-value ,reg *binding-stack-pointer*))
131 (defmacro load-type (target source &optional (offset 0))
132 #!+sb-doc
133 "Loads the type bits of a pointer into target independent of
134 byte-ordering issues."
135 (once-only ((n-target target)
136 (n-source source)
137 (n-offset offset))
138 (ecase *backend-byte-order*
139 (:little-endian
140 `(inst movzx ,n-target
141 (make-ea :byte :base ,n-source :disp ,n-offset)))
142 (:big-endian
143 `(inst movzx ,n-target
144 (make-ea :byte :base ,n-source
145 :disp (+ ,n-offset (1- n-word-bytes))))))))
147 ;;;; allocation helpers
149 ;;; All allocation is done by calls to assembler routines that
150 ;;; eventually invoke the C alloc() function.
152 ;;; Emit code to allocate an object with a size in bytes given by
153 ;;; Size. The size may be an integer of a TN. If Inline is a VOP
154 ;;; node-var then it is used to make an appropriate speed vs size
155 ;;; decision.
157 (defun allocation-dynamic-extent (alloc-tn size lowtag)
158 (inst sub rsp-tn size)
159 ;; see comment in x86/macros.lisp implementation of this
160 ;; However that comment seems inapplicable here because:
161 ;; - PAD-DATA-BLOCK quite clearly enforces double-word alignment,
162 ;; contradicting "... unfortunately not enforced by ..."
163 ;; - It's not the job of WITH-FIXED-ALLOCATION to realign anything.
164 ;; - The real issue is that it's not obvious that the stack is
165 ;; 16-byte-aligned at *all* times. Maybe it is, maybe it isn't.
166 (inst and rsp-tn #.(lognot lowtag-mask))
167 (aver (not (location= alloc-tn rsp-tn)))
168 (inst lea alloc-tn (make-ea :byte :base rsp-tn :disp lowtag))
169 (values))
171 ;;; This macro should only be used inside a pseudo-atomic section,
172 ;;; which should also cover subsequent initialization of the
173 ;;; object.
174 (defun allocation-tramp (alloc-tn size lowtag
175 &optional (result-tn alloc-tn))
176 (cond ((typep size '(and integer (not (signed-byte 32))))
177 ;; MOV accepts large immediate operands, PUSH does not
178 (inst mov alloc-tn size)
179 (inst push alloc-tn))
181 (inst push size)))
182 (inst mov alloc-tn (make-fixup "alloc_tramp" :foreign))
183 (inst call alloc-tn)
184 (inst pop result-tn)
185 (when lowtag
186 (inst or (reg-in-size result-tn :byte) lowtag))
187 (values))
189 (defun allocation (alloc-tn size &optional ignored dynamic-extent lowtag)
190 (declare (ignore ignored))
191 (when dynamic-extent
192 (allocation-dynamic-extent alloc-tn size lowtag)
193 (return-from allocation (values)))
194 (let ((NOT-INLINE (gen-label))
195 (DONE (gen-label))
196 ;; Yuck.
197 (in-elsewhere (eq *elsewhere* sb!assem::**current-segment**))
198 ;; thread->alloc_region.free_pointer
199 (free-pointer
200 #!+sb-thread
201 (make-ea :qword
202 :base thread-base-tn :scale 1
203 :disp (* n-word-bytes thread-alloc-region-slot))
204 #!-sb-thread
205 (make-ea :qword
206 :scale 1 :disp
207 (make-fixup "boxed_region" :foreign)))
208 ;; thread->alloc_region.end_addr
209 (end-addr
210 #!+sb-thread
211 (make-ea :qword
212 :base thread-base-tn :scale 1
213 :disp (* n-word-bytes (1+ thread-alloc-region-slot)))
214 #!-sb-thread
215 (make-ea :qword
216 :scale 1 :disp
217 (make-fixup "boxed_region" :foreign 8))))
218 (cond ((or in-elsewhere
219 #!+gencgc
220 ;; large objects will never be made in a per-thread region
221 (and (integerp size)
222 (>= size large-object-size)))
223 (allocation-tramp alloc-tn size lowtag))
225 (inst mov temp-reg-tn free-pointer)
226 (cond ((tn-p size)
227 (if (location= alloc-tn size)
228 (inst add alloc-tn temp-reg-tn)
229 (inst lea alloc-tn
230 (make-ea :qword :base temp-reg-tn :index size))))
231 ((typep size '(signed-byte 31))
232 (inst lea alloc-tn
233 (make-ea :qword :base temp-reg-tn :disp size)))
234 (t ; a doozy - 'disp' in an EA is too small for this size
235 (inst mov alloc-tn temp-reg-tn)
236 (inst add alloc-tn (constantize size))))
237 (inst cmp alloc-tn end-addr)
238 (inst jmp :a NOT-INLINE)
239 (inst mov free-pointer alloc-tn)
240 (emit-label DONE)
241 (if lowtag
242 (inst lea alloc-tn (make-ea :byte :base temp-reg-tn :disp lowtag))
243 (inst mov alloc-tn temp-reg-tn))
244 (assemble (*elsewhere*)
245 (emit-label NOT-INLINE)
246 (cond ((numberp size)
247 (allocation-tramp alloc-tn size nil temp-reg-tn))
249 (inst sub alloc-tn free-pointer)
250 (allocation-tramp alloc-tn alloc-tn nil temp-reg-tn)))
251 (inst jmp DONE))))
252 (values)))
254 ;;; Allocate an other-pointer object of fixed SIZE with a single word
255 ;;; header having the specified WIDETAG value. The result is placed in
256 ;;; RESULT-TN.
257 (defmacro with-fixed-allocation ((result-tn widetag size &optional inline stack-allocate-p)
258 &body forms)
259 (unless forms
260 (bug "empty &body in WITH-FIXED-ALLOCATION"))
261 (once-only ((result-tn result-tn) (size size) (stack-allocate-p stack-allocate-p))
262 `(maybe-pseudo-atomic ,stack-allocate-p
263 (allocation ,result-tn (pad-data-block ,size) ,inline ,stack-allocate-p
264 other-pointer-lowtag)
265 (storew (logior (ash (1- ,size) n-widetag-bits) ,widetag)
266 ,result-tn 0 other-pointer-lowtag)
267 ,@forms)))
269 ;;;; error code
270 (defun emit-error-break (vop kind code values)
271 (assemble ()
272 #!-ud2-breakpoints
273 (inst int 3) ; i386 breakpoint instruction
274 ;; On Darwin, we need to use #x0b0f instead of int3 in order
275 ;; to generate a SIGILL instead of a SIGTRAP as darwin/x86
276 ;; doesn't seem to be reliably firing SIGTRAP
277 ;; handlers. Hopefully this will be fixed by Apple at a
278 ;; later date. Do the same on x86-64 as we do on x86 until this gets
279 ;; sorted out.
280 #!+ud2-breakpoints
281 (inst word #x0b0f)
282 ;; The return PC points here; note the location for the debugger.
283 (when vop
284 (note-this-location vop :internal-error))
285 (inst byte kind) ; eg trap_Xyyy
286 (case kind
287 (#.invalid-arg-count-trap) ; there is no "payload" in this trap kind
289 (inst byte code)
290 (with-adjustable-vector (vector) ; interr arguments
291 (dolist (tn values)
292 ;; classic CMU CL comment:
293 ;; zzzzz jrd here. tn-offset is zero for constant
294 ;; tns.
295 (write-var-integer
296 (make-sc-offset (sc-number (tn-sc tn)) (or (tn-offset tn) 0)) vector))
297 (dotimes (i (length vector))
298 (inst byte (aref vector i))))))))
300 (defun error-call (vop error-code &rest values)
301 #!+sb-doc
302 "Cause an error. ERROR-CODE is the error to cause."
303 (emit-error-break vop error-trap (error-number-or-lose error-code) values))
305 (defun generate-error-code (vop error-code &rest values)
306 #!+sb-doc
307 "Generate-Error-Code Error-code Value*
308 Emit code for an error with the specified Error-Code and context Values."
309 (assemble (*elsewhere*)
310 (let ((start-lab (gen-label)))
311 (emit-label start-lab)
312 (emit-error-break vop
313 (case error-code ; should be named ERROR-SYMBOL really
314 (invalid-arg-count-error invalid-arg-count-trap)
315 (t error-trap))
316 (error-number-or-lose error-code)
317 values)
318 start-lab)))
321 ;;;; PSEUDO-ATOMIC
323 ;;; This is used to wrap operations which leave untagged memory lying
324 ;;; around. It's an operation which the AOP weenies would describe as
325 ;;; having "cross-cutting concerns", meaning it appears all over the
326 ;;; place and there's no logical single place to attach documentation.
327 ;;; grep (mostly in src/runtime) is your friend
329 (defmacro maybe-pseudo-atomic (not-really-p &body body)
330 `(if ,not-really-p
331 (progn ,@body)
332 (pseudo-atomic ,@body)))
334 ;;; Unsafely clear pa flags so that the image can properly lose in a
335 ;;; pa section.
336 #!+sb-thread
337 (defmacro %clear-pseudo-atomic ()
338 '(inst mov (make-ea :qword :base thread-base-tn
339 :disp (* n-word-bytes thread-pseudo-atomic-bits-slot))
342 #!+sb-safepoint
343 (defun emit-safepoint ()
344 (inst test al-tn (make-ea :byte :disp gc-safepoint-page-addr)))
346 #!+sb-thread
347 (defmacro pseudo-atomic (&rest forms)
348 #!+sb-safepoint-strictly
349 `(progn ,@forms (emit-safepoint))
350 #!-sb-safepoint-strictly
351 (with-unique-names (label)
352 `(let ((,label (gen-label)))
353 (inst mov (make-ea :qword
354 :base thread-base-tn
355 :disp (* n-word-bytes thread-pseudo-atomic-bits-slot))
356 rbp-tn)
357 ,@forms
358 (inst xor (make-ea :qword
359 :base thread-base-tn
360 :disp (* n-word-bytes thread-pseudo-atomic-bits-slot))
361 rbp-tn)
362 (inst jmp :z ,label)
363 ;; if PAI was set, interrupts were disabled at the same time
364 ;; using the process signal mask.
365 (inst break pending-interrupt-trap)
366 (emit-label ,label)
367 #!+sb-safepoint
368 ;; In this case, when allocation thinks a GC should be done, it
369 ;; does not mark PA as interrupted, but schedules a safepoint
370 ;; trap instead. Let's take the opportunity to trigger that
371 ;; safepoint right now.
372 (emit-safepoint))))
375 #!-sb-thread
376 (defmacro pseudo-atomic (&rest forms)
377 (with-unique-names (label)
378 `(let ((,label (gen-label)))
379 ;; FIXME: The MAKE-EA noise should become a MACROLET macro or
380 ;; something. (perhaps SVLB, for static variable low byte)
381 (inst mov (make-ea :qword :disp (+ nil-value
382 (static-symbol-offset
383 '*pseudo-atomic-bits*)
384 (ash symbol-value-slot word-shift)
385 (- other-pointer-lowtag)))
386 rbp-tn)
387 ,@forms
388 (inst xor (make-ea :qword :disp (+ nil-value
389 (static-symbol-offset
390 '*pseudo-atomic-bits*)
391 (ash symbol-value-slot word-shift)
392 (- other-pointer-lowtag)))
393 rbp-tn)
394 (inst jmp :z ,label)
395 ;; if PAI was set, interrupts were disabled at the same time
396 ;; using the process signal mask.
397 (inst break pending-interrupt-trap)
398 (emit-label ,label))))
400 ;;;; indexed references
402 (defmacro define-full-compare-and-swap
403 (name type offset lowtag scs el-type &optional translate)
404 `(progn
405 (define-vop (,name)
406 ,@(when translate `((:translate ,translate)))
407 (:policy :fast-safe)
408 (:args (object :scs (descriptor-reg) :to :eval)
409 (index :scs (any-reg) :to :result)
410 (old-value :scs ,scs :target rax)
411 (new-value :scs ,scs))
412 (:arg-types ,type tagged-num ,el-type ,el-type)
413 (:temporary (:sc descriptor-reg :offset rax-offset
414 :from (:argument 2) :to :result :target value) rax)
415 (:results (value :scs ,scs))
416 (:result-types ,el-type)
417 (:generator 5
418 (move rax old-value)
419 (inst cmpxchg (make-ea :qword :base object :index index
420 :scale (ash 1 (- word-shift n-fixnum-tag-bits))
421 :disp (- (* ,offset n-word-bytes) ,lowtag))
422 new-value :lock)
423 (move value rax)))))
425 (defmacro define-full-reffer (name type offset lowtag scs el-type &optional translate)
426 `(progn
427 (define-vop (,name)
428 ,@(when translate
429 `((:translate ,translate)))
430 (:policy :fast-safe)
431 (:args (object :scs (descriptor-reg))
432 (index :scs (any-reg)))
433 (:arg-types ,type tagged-num)
434 (:results (value :scs ,scs))
435 (:result-types ,el-type)
436 (:generator 3 ; pw was 5
437 (inst mov value (make-ea :qword :base object :index index
438 :scale (ash 1 (- word-shift n-fixnum-tag-bits))
439 :disp (- (* ,offset n-word-bytes)
440 ,lowtag)))))
441 (define-vop (,(symbolicate name "-C"))
442 ,@(when translate
443 `((:translate ,translate)))
444 (:policy :fast-safe)
445 (:args (object :scs (descriptor-reg)))
446 (:info index)
447 (:arg-types ,type
448 (:constant (load/store-index ,n-word-bytes ,(eval lowtag)
449 ,(eval offset))))
450 (:results (value :scs ,scs))
451 (:result-types ,el-type)
452 (:generator 2 ; pw was 5
453 (inst mov value (make-ea :qword :base object
454 :disp (- (* (+ ,offset index) n-word-bytes)
455 ,lowtag)))))))
457 (defmacro define-full-reffer+offset (name type offset lowtag scs el-type &optional translate)
458 `(progn
459 (define-vop (,name)
460 ,@(when translate
461 `((:translate ,translate)))
462 (:policy :fast-safe)
463 (:args (object :scs (descriptor-reg))
464 (index :scs (any-reg)))
465 (:info offset)
466 (:arg-types ,type tagged-num
467 (:constant (constant-displacement other-pointer-lowtag
468 n-word-bytes vector-data-offset)))
469 (:results (value :scs ,scs))
470 (:result-types ,el-type)
471 (:generator 3 ; pw was 5
472 (inst mov value (make-ea :qword :base object :index index
473 :scale (ash 1 (- word-shift n-fixnum-tag-bits))
474 :disp (- (* (+ ,offset offset) n-word-bytes)
475 ,lowtag)))))
476 (define-vop (,(symbolicate name "-C"))
477 ,@(when translate
478 `((:translate ,translate)))
479 (:policy :fast-safe)
480 (:args (object :scs (descriptor-reg)))
481 (:info index offset)
482 (:arg-types ,type
483 (:constant (load/store-index ,n-word-bytes ,(eval lowtag)
484 ,(eval offset)))
485 (:constant (constant-displacement other-pointer-lowtag
486 n-word-bytes vector-data-offset)))
487 (:results (value :scs ,scs))
488 (:result-types ,el-type)
489 (:generator 2 ; pw was 5
490 (inst mov value (make-ea :qword :base object
491 :disp (- (* (+ ,offset index offset) n-word-bytes)
492 ,lowtag)))))))
494 (defmacro define-full-setter (name type offset lowtag scs el-type &optional translate)
495 `(progn
496 (define-vop (,name)
497 ,@(when translate
498 `((:translate ,translate)))
499 (:policy :fast-safe)
500 (:args (object :scs (descriptor-reg))
501 (index :scs (any-reg))
502 (value :scs ,scs :target result))
503 (:arg-types ,type tagged-num ,el-type)
504 (:results (result :scs ,scs))
505 (:result-types ,el-type)
506 (:generator 4 ; was 5
507 (inst mov (make-ea :qword :base object :index index
508 :scale (ash 1 (- word-shift n-fixnum-tag-bits))
509 :disp (- (* ,offset n-word-bytes) ,lowtag))
510 value)
511 (move result value)))
512 (define-vop (,(symbolicate name "-C"))
513 ,@(when translate
514 `((:translate ,translate)))
515 (:policy :fast-safe)
516 (:args (object :scs (descriptor-reg))
517 (value :scs ,scs :target result))
518 (:info index)
519 (:arg-types ,type
520 (:constant (load/store-index ,n-word-bytes ,(eval lowtag)
521 ,(eval offset)))
522 ,el-type)
523 (:results (result :scs ,scs))
524 (:result-types ,el-type)
525 (:generator 3 ; was 5
526 (inst mov (make-ea :qword :base object
527 :disp (- (* (+ ,offset index) n-word-bytes)
528 ,lowtag))
529 value)
530 (move result value)))))
532 (defmacro define-full-setter+offset (name type offset lowtag scs el-type &optional translate)
533 `(progn
534 (define-vop (,name)
535 ,@(when translate
536 `((:translate ,translate)))
537 (:policy :fast-safe)
538 (:args (object :scs (descriptor-reg))
539 (index :scs (any-reg))
540 (value :scs ,scs :target result))
541 (:info offset)
542 (:arg-types ,type tagged-num
543 (:constant (constant-displacement other-pointer-lowtag
544 n-word-bytes
545 vector-data-offset))
546 ,el-type)
547 (:results (result :scs ,scs))
548 (:result-types ,el-type)
549 (:generator 4 ; was 5
550 (inst mov (make-ea :qword :base object :index index
551 :scale (ash 1 (- word-shift n-fixnum-tag-bits))
552 :disp (- (* (+ ,offset offset) n-word-bytes) ,lowtag))
553 value)
554 (move result value)))
555 (define-vop (,(symbolicate name "-C"))
556 ,@(when translate
557 `((:translate ,translate)))
558 (:policy :fast-safe)
559 (:args (object :scs (descriptor-reg))
560 (value :scs ,scs :target result))
561 (:info index offset)
562 (:arg-types ,type
563 (:constant (load/store-index ,n-word-bytes ,(eval lowtag)
564 ,(eval offset)))
565 (:constant (constant-displacement other-pointer-lowtag
566 n-word-bytes
567 vector-data-offset))
568 ,el-type)
569 (:results (result :scs ,scs))
570 (:result-types ,el-type)
571 (:generator 3 ; was 5
572 (inst mov (make-ea :qword :base object
573 :disp (- (* (+ ,offset index offset) n-word-bytes)
574 ,lowtag))
575 value)
576 (move result value)))))
578 ;;; helper for alien stuff.
580 (sb!xc:defmacro with-pinned-objects ((&rest objects) &body body)
581 #!+sb-doc
582 "Arrange with the garbage collector that the pages occupied by
583 OBJECTS will not be moved in memory for the duration of BODY.
584 Useful for e.g. foreign calls where another thread may trigger
585 collection."
586 (if objects
587 (let ((pins (make-gensym-list (length objects)))
588 (wpo (sb!xc:gensym "WITH-PINNED-OBJECTS-THUNK")))
589 ;; BODY is stuffed in a function to preserve the lexical
590 ;; environment.
591 `(flet ((,wpo () (progn ,@body)))
592 ;; The cross-compiler prints either "unknown type: COMPILER-NOTE" at
593 ;; each use of W-P-O prior to 'ir1report' being compiled, or else
594 ;; "could not stack allocate". Kill it with fire :-(
595 (declare (muffle-conditions #+sb-xc compiler-note #-sb-xc t))
596 ;; PINS are dx-allocated in case the compiler for some
597 ;; unfathomable reason decides to allocate value-cells
598 ;; for them -- since we have DX value-cells on x86oid
599 ;; platforms this still forces them on the stack.
600 (dx-let ,(mapcar #'list pins objects)
601 (multiple-value-prog1 (,wpo)
602 ;; TOUCH-OBJECT has a VOP with an empty body: compiler
603 ;; thinks we're using the argument and doesn't flush
604 ;; the variable, but we don't have to pay any extra
605 ;; beyond that -- and MULTIPLE-VALUE-PROG1 keeps them
606 ;; live till the body has finished. *whew*
607 ,@(mapcar (lambda (pin)
608 `(touch-object ,pin))
609 pins)))))
610 `(progn ,@body)))
612 ;;; Emit the most compact form of the test immediate instruction,
613 ;;; using an 8 bit test when the immediate is only 8 bits and the
614 ;;; value is one of the four low registers (rax, rbx, rcx, rdx) or the
615 ;;; control stack.
616 (defun emit-optimized-test-inst (x y)
617 (typecase y
618 ((unsigned-byte 7)
619 ;; If we knew that the sign bit would not be tested, this could
620 ;; handle (unsigned-byte 8) constants. But since we don't know,
621 ;; we assume that it's not ok to change the test such that the S flag
622 ;; comes out possibly differently.
623 (let ((offset (tn-offset x)))
624 (cond ((and (sc-is x any-reg descriptor-reg signed-reg unsigned-reg)
625 (or (= offset rax-offset) (= offset rbx-offset)
626 (= offset rcx-offset) (= offset rdx-offset)))
627 (inst test (reg-in-size x :byte) y))
628 ((sc-is x control-stack)
629 (inst test (make-ea :byte :base rbp-tn
630 :disp (frame-byte-offset offset))
633 (inst test x y)))))
635 (inst test x y))))