1 ;;;; function call for the x86 VM
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 (defconstant arg-count-sc
(make-sc-offset any-reg-sc-number rcx-offset
))
15 (defconstant closure-sc
(make-sc-offset any-reg-sc-number rax-offset
))
17 ;;; Make a passing location TN for a local call return PC.
19 ;;; Always wire the return PC location to the stack in its standard
21 (defun make-return-pc-passing-location (standard)
22 (declare (ignore standard
))
23 (make-wired-tn (primitive-type-or-lose 'system-area-pointer
)
24 sap-stack-sc-number return-pc-save-offset
))
26 (defconstant return-pc-passing-offset
27 (make-sc-offset sap-stack-sc-number return-pc-save-offset
))
29 ;;; This is similar to MAKE-RETURN-PC-PASSING-LOCATION, but makes a
30 ;;; location to pass OLD-FP in.
32 ;;; This is wired in both the standard and the local-call conventions,
33 ;;; because we want to be able to assume it's always there. Besides,
34 ;;; the x86 doesn't have enough registers to really make it profitable
35 ;;; to pass it in a register.
36 (defun make-old-fp-passing-location (standard)
37 (declare (ignore standard
))
38 (make-wired-tn *fixnum-primitive-type
* control-stack-sc-number
41 (defconstant old-fp-passing-offset
42 (make-sc-offset control-stack-sc-number ocfp-save-offset
))
44 ;;; Make the TNs used to hold OLD-FP and RETURN-PC within the current
45 ;;; function. We treat these specially so that the debugger can find
46 ;;; them at a known location.
48 ;;; Without using a save-tn - which does not make much sense if it is
49 ;;; wired to the stack?
50 (defun make-old-fp-save-location (physenv)
51 (physenv-debug-live-tn (make-wired-tn *fixnum-primitive-type
*
52 control-stack-sc-number
55 (defun make-return-pc-save-location (physenv)
56 (physenv-debug-live-tn
57 (make-wired-tn (primitive-type-or-lose 'system-area-pointer
)
58 sap-stack-sc-number return-pc-save-offset
)
61 ;;; Make a TN for the standard argument count passing location. We only
62 ;;; need to make the standard location, since a count is never passed when we
63 ;;; are using non-standard conventions.
64 (defun make-arg-count-location ()
65 (make-wired-tn *fixnum-primitive-type
* any-reg-sc-number rcx-offset
))
69 ;;; This is used for setting up the Old-FP in local call.
70 (define-vop (current-fp)
71 (:results
(val :scs
(any-reg control-stack
)))
75 ;;; We don't have a separate NFP, so we don't need to do anything here.
76 (define-vop (compute-old-nfp)
82 ;;; Accessing a slot from an earlier stack frame is definite hackery.
83 (define-vop (ancestor-frame-ref)
84 (:args
(frame-pointer :scs
(descriptor-reg))
85 (variable-home-tn :load-if nil
))
86 (:results
(value :scs
(descriptor-reg any-reg
)))
89 (aver (sc-is variable-home-tn control-stack
))
90 (loadw value frame-pointer
91 (frame-word-offset (tn-offset variable-home-tn
)))))
92 (define-vop (ancestor-frame-set)
93 (:args
(frame-pointer :scs
(descriptor-reg))
94 (value :scs
(descriptor-reg any-reg
)))
95 (:results
(variable-home-tn :load-if nil
))
98 (aver (sc-is variable-home-tn control-stack
))
99 (storew value frame-pointer
100 (frame-word-offset (tn-offset variable-home-tn
)))))
102 (macrolet ((define-frame-op
103 (suffix sc stack-sc instruction
107 :disp
(frame-byte-offset
108 (tn-offset variable-home-tn
)))))
109 (let ((reffer (symbolicate 'ancestor-frame-ref
'/ suffix
))
110 (setter (symbolicate 'ancestor-frame-set
'/ suffix
)))
112 (define-vop (,reffer ancestor-frame-ref
)
113 (:results
(value :scs
(,sc
)))
115 (aver (sc-is variable-home-tn
,stack-sc
))
116 (inst ,instruction value
118 (define-vop (,setter ancestor-frame-set
)
119 (:args
(frame-pointer :scs
(descriptor-reg))
122 (aver (sc-is variable-home-tn
,stack-sc
))
123 (inst ,instruction
,ea value
)))))))
124 (define-frame-op double-float double-reg double-stack movsd
)
125 (define-frame-op single-float single-reg single-stack movss
)
126 (define-frame-op complex-double-float complex-double-reg complex-double-stack
127 movupd
(ea-for-cdf-data-stack variable-home-tn frame-pointer
))
128 (define-frame-op complex-single-float complex-single-reg complex-single-stack
129 movq
(ea-for-csf-data-stack variable-home-tn frame-pointer
))
130 (define-frame-op signed-byte-64 signed-reg signed-stack mov
)
131 (define-frame-op unsigned-byte-64 unsigned-reg unsigned-stack mov
)
132 (define-frame-op system-area-pointer sap-reg sap-stack mov
))
134 (defun primitive-type-indirect-cell-type (ptype)
135 (declare (type primitive-type ptype
))
136 (macrolet ((foo (&body data
)
137 `(case (primitive-type-name ptype
)
138 ,@(loop for
(name stack-sc ref set
) in data
142 (list (primitive-type-or-lose ',name
)
143 (sc-or-lose ',stack-sc
)
144 (lambda (node block fp value res
)
145 (sb!c
::vop
,ref node block
147 (lambda (node block fp new-val value
)
148 (sb!c
::vop
,set node block
149 fp new-val value
)))))))))
150 (foo (double-float double-stack
151 ancestor-frame-ref
/double-float
152 ancestor-frame-set
/double-float
)
153 (single-float single-stack
154 ancestor-frame-ref
/single-float
155 ancestor-frame-set
/single-float
)
156 (complex-double-float complex-double-stack
157 ancestor-frame-ref
/complex-double-float
158 ancestor-frame-set
/complex-double-float
)
159 (complex-single-float complex-single-stack
160 ancestor-frame-ref
/complex-single-float
161 ancestor-frame-set
/complex-single-float
)
162 (signed-byte-64 signed-stack
163 ancestor-frame-ref
/signed-byte-64
164 ancestor-frame-set
/signed-byte-64
)
165 (unsigned-byte-64 unsigned-stack
166 ancestor-frame-ref
/unsigned-byte-64
167 ancestor-frame-set
/unsigned-byte-64
)
168 (unsigned-byte-63 unsigned-stack
169 ancestor-frame-ref
/unsigned-byte-64
170 ancestor-frame-set
/unsigned-byte-64
)
171 (system-area-pointer sap-stack
172 ancestor-frame-ref
/system-area-pointer
173 ancestor-frame-set
/system-area-pointer
))))
175 (define-vop (xep-allocate-frame)
178 (emit-alignment n-lowtag-bits
)
179 (emit-label start-lab
)
180 ;; Skip space for the function header.
181 (inst simple-fun-header-word
)
182 (dotimes (i (* n-word-bytes
(1- simple-fun-code-offset
)))
185 ;; The start of the actual code.
186 ;; Save the return-pc.
187 (popw rbp-tn
(frame-word-offset return-pc-save-offset
))))
189 (define-vop (xep-setup-sp)
192 (make-ea :qword
:base rbp-tn
193 :disp
(- (* n-word-bytes
194 (- (max 3 (sb-allocated-size 'stack
))
197 ;;; This is emitted directly before either a known-call-local, call-local,
198 ;;; or a multiple-call-local. All it does is allocate stack space for the
199 ;;; callee (who has the same size stack as us).
200 (define-vop (allocate-frame)
201 (:results
(res :scs
(any-reg))
206 (inst lea res
(make-ea :qword
:base rsp-tn
207 :disp
(- (* sp-
>fp-offset n-word-bytes
))))
208 (inst sub rsp-tn
(* n-word-bytes
(sb-allocated-size 'stack
)))))
210 ;;; Allocate a partial frame for passing stack arguments in a full
211 ;;; call. NARGS is the number of arguments passed. We allocate at
212 ;;; least 3 slots, because the XEP noise is going to want to use them
213 ;;; before it can extend the stack.
214 (define-vop (allocate-full-call-frame)
216 (:results
(res :scs
(any-reg)))
218 (inst lea res
(make-ea :qword
:base rsp-tn
219 :disp
(- (* sp-
>fp-offset n-word-bytes
))))
220 (inst sub rsp-tn
(* (max nargs
3) n-word-bytes
))))
222 ;;; Emit code needed at the return-point from an unknown-values call
223 ;;; for a fixed number of values. Values is the head of the TN-REF
224 ;;; list for the locations that the values are to be received into.
225 ;;; Nvals is the number of values that are to be received (should
226 ;;; equal the length of Values).
228 ;;; If 0 or 1 values are expected, then we just emit an instruction to
229 ;;; reset the SP (which will only be executed when other than 1 value
232 ;;; In the general case we have to do three things:
233 ;;; -- Default unsupplied register values. This need only be done
234 ;;; when a single value is returned, since register values are
235 ;;; defaulted by the called in the non-single case.
236 ;;; -- Default unsupplied stack values. This needs to be done whenever
237 ;;; there are stack values.
238 ;;; -- Reset SP. This must be done whenever other than 1 value is
239 ;;; returned, regardless of the number of values desired.
240 (defun default-unknown-values (vop values nvals node
)
241 (declare (type (or tn-ref null
) values
)
242 (type unsigned-byte nvals
))
243 (let ((type (sb!c
::basic-combination-derived-type node
)))
246 (note-this-location vop
:single-value-return
)
248 ((<= (sb!kernel
:values-type-max-value-count type
)
250 (when (and (named-type-p type
)
251 (eq nil
(named-type-name type
)))
252 ;; The function never returns, it may happen that the code
253 ;; ends right here leavig the :SINGLE-VALUE-RETURN note
254 ;; dangling. Let's emit a NOP.
256 ((not (sb!kernel
:values-type-may-be-single-value-p type
))
257 (inst mov rsp-tn rbx-tn
))
259 (inst cmov
:c rsp-tn rbx-tn
))))
260 ((<= nvals register-arg-count
)
261 (note-this-location vop
:unknown-return
)
262 (when (sb!kernel
:values-type-may-be-single-value-p type
)
263 (let ((regs-defaulted (gen-label)))
264 (inst jmp
:c regs-defaulted
)
265 ;; Default the unsupplied registers.
266 (let* ((2nd-tn-ref (tn-ref-across values
))
267 (2nd-tn (tn-ref-tn 2nd-tn-ref
)))
268 (inst mov
2nd-tn nil-value
)
271 for tn-ref
= (tn-ref-across 2nd-tn-ref
)
272 then
(tn-ref-across tn-ref
)
273 for count from
2 below register-arg-count
274 do
(inst mov
(tn-ref-tn tn-ref
) 2nd-tn
))))
275 (inst mov rbx-tn rsp-tn
)
276 (emit-label regs-defaulted
)))
277 (when (< register-arg-count
278 (sb!kernel
:values-type-max-value-count type
))
279 (inst mov rsp-tn rbx-tn
)))
281 ;; The number of bytes depends on the relative jump instructions.
282 ;; Best case is 31+(n-3)*14, worst case is 35+(n-3)*18. For
283 ;; NVALS=6 that is 73/89 bytes, and for NVALS=7 that is 87/107
284 ;; bytes which is likely better than using the blt below.
285 (let ((regs-defaulted (gen-label))
286 (defaulting-done (gen-label))
287 (default-stack-slots (gen-label)))
288 (note-this-location vop
:unknown-return
)
289 (inst mov rax-tn nil-value
)
290 ;; Branch off to the MV case.
291 (inst jmp
:c regs-defaulted
)
292 ;; Do the single value case.
293 ;; Default the register args
295 (val (tn-ref-across values
) (tn-ref-across val
)))
296 ((= i
(min nvals register-arg-count
)))
297 (inst mov
(tn-ref-tn val
) rax-tn
))
298 ;; Fake other registers so it looks like we returned with all the
299 ;; registers filled in.
301 (inst jmp default-stack-slots
)
302 (emit-label regs-defaulted
)
303 (collect ((defaults))
304 (do ((i register-arg-count
(1+ i
))
305 (val (do ((i 0 (1+ i
))
306 (val values
(tn-ref-across val
)))
307 ((= i register-arg-count
) val
))
308 (tn-ref-across val
)))
310 (let ((default-lab (gen-label))
312 (first-stack-arg-p (= i register-arg-count
)))
313 (defaults (cons default-lab
314 (cons tn first-stack-arg-p
)))
315 (inst cmp rcx-tn
(fixnumize i
))
316 (inst jmp
:be default-lab
)
317 (when first-stack-arg-p
318 ;; There are stack args so the frame of the callee is
319 ;; still there, save RDX in its first slot temporalily.
320 (storew rdx-tn rbx-tn
(frame-word-offset sp-
>fp-offset
)))
321 (loadw rdx-tn rbx-tn
(frame-word-offset (+ sp-
>fp-offset i
)))
322 (inst mov tn rdx-tn
)))
323 (emit-label defaulting-done
)
324 (loadw rdx-tn rbx-tn
(frame-word-offset sp-
>fp-offset
))
326 (let ((defaults (defaults)))
328 (assemble (*elsewhere
*)
329 (emit-label default-stack-slots
)
330 (dolist (default defaults
)
331 (emit-label (car default
))
333 ;; We are setting the first stack argument to NIL.
334 ;; The callee's stack frame is dead, save RDX by
335 ;; pushing it to the stack, it will end up at same
336 ;; place as in the (STOREW RDX-TN RBX-TN -1) case
339 (inst mov
(second default
) rax-tn
))
340 (inst jmp defaulting-done
)))))))
342 (let ((regs-defaulted (gen-label))
343 (restore-edi (gen-label))
344 (no-stack-args (gen-label))
345 (default-stack-vals (gen-label))
346 (count-okay (gen-label)))
347 (note-this-location vop
:unknown-return
)
348 ;; Branch off to the MV case.
349 (inst jmp
:c regs-defaulted
)
350 ;; Default the register args, and set up the stack as if we
351 ;; entered the MV return point.
352 (inst mov rbx-tn rsp-tn
)
353 (inst mov rdi-tn nil-value
)
354 (inst mov rsi-tn rdi-tn
)
355 ;; Compute a pointer to where to put the [defaulted] stack values.
356 (emit-label no-stack-args
)
360 (make-ea :qword
:base rbp-tn
361 :disp
(frame-byte-offset register-arg-count
)))
362 ;; Load RAX with NIL so we can quickly store it, and set up
363 ;; stuff for the loop.
364 (inst mov rax-tn nil-value
)
366 (inst mov rcx-tn
(- nvals register-arg-count
))
367 ;; Jump into the default loop.
368 (inst jmp default-stack-vals
)
369 ;; The regs are defaulted. We need to copy any stack arguments,
370 ;; and then default the remaining stack arguments.
371 (emit-label regs-defaulted
)
372 ;; Compute the number of stack arguments, and if it's zero or
373 ;; less, don't copy any stack arguments.
374 (inst sub rcx-tn
(fixnumize register-arg-count
))
375 (inst jmp
:le no-stack-args
)
377 (storew rdi-tn rbx-tn
(frame-word-offset (+ sp-
>fp-offset
1)))
378 ;; Throw away any unwanted args.
379 (inst cmp rcx-tn
(fixnumize (- nvals register-arg-count
)))
380 (inst jmp
:be count-okay
)
381 (inst mov rcx-tn
(fixnumize (- nvals register-arg-count
)))
382 (emit-label count-okay
)
383 ;; Save the number of stack values.
384 (inst mov rax-tn rcx-tn
)
385 ;; Compute a pointer to where the stack args go.
387 (make-ea :qword
:base rbp-tn
388 :disp
(frame-byte-offset register-arg-count
)))
389 ;; Save ESI, and compute a pointer to where the args come from.
390 (storew rsi-tn rbx-tn
(frame-word-offset (+ sp-
>fp-offset
2)))
392 (make-ea :qword
:base rbx-tn
393 :disp
(frame-byte-offset
394 (+ sp-
>fp-offset register-arg-count
))))
396 (inst shr rcx-tn n-fixnum-tag-bits
) ; make word count
401 (loadw rsi-tn rbx-tn
(frame-word-offset (+ sp-
>fp-offset
2)))
402 ;; Now we have to default the remaining args. Find out how many.
403 (inst sub rax-tn
(fixnumize (- nvals register-arg-count
)))
405 ;; If none, then just blow out of here.
406 (inst jmp
:le restore-edi
)
407 (inst mov rcx-tn rax-tn
)
408 (inst shr rcx-tn n-fixnum-tag-bits
) ; word count
409 ;; Load RAX with NIL for fast storing.
410 (inst mov rax-tn nil-value
)
412 (emit-label default-stack-vals
)
415 ;; Restore EDI, and reset the stack.
416 (emit-label restore-edi
)
417 (loadw rdi-tn rbx-tn
(frame-word-offset (+ sp-
>fp-offset
1)))
418 (inst mov rsp-tn rbx-tn
)
422 ;;;; unknown values receiving
424 ;;; Emit code needed at the return point for an unknown-values call
425 ;;; for an arbitrary number of values.
427 ;;; We do the single and non-single cases with no shared code: there
428 ;;; doesn't seem to be any potential overlap, and receiving a single
429 ;;; value is more important efficiency-wise.
431 ;;; When there is a single value, we just push it on the stack,
432 ;;; returning the old SP and 1.
434 ;;; When there is a variable number of values, we move all of the
435 ;;; argument registers onto the stack, and return ARGS and NARGS.
437 ;;; ARGS and NARGS are TNs wired to the named locations. We must
438 ;;; explicitly allocate these TNs, since their lifetimes overlap with
439 ;;; the results start and count. (Also, it's nice to be able to target
441 (defun receive-unknown-values (args nargs start count node
)
442 (declare (type tn args nargs start count
))
443 (let ((type (sb!c
::basic-combination-derived-type node
))
444 (variable-values (gen-label))
445 (stack-values (gen-label))
447 (when (sb!kernel
:values-type-may-be-single-value-p type
)
448 (inst jmp
:c variable-values
)
449 (cond ((location= start
(first *register-arg-tns
*))
450 (inst push
(first *register-arg-tns
*))
451 (inst lea start
(make-ea :qword
:base rsp-tn
:disp n-word-bytes
)))
452 (t (inst mov start rsp-tn
)
453 (inst push
(first *register-arg-tns
*))))
454 (inst mov count
(fixnumize 1))
456 (emit-label variable-values
))
457 ;; The stack frame is burnt and RETurned from if there are no
458 ;; stack values. In this case quickly reallocate sufficient space.
459 (when (<= (sb!kernel
:values-type-min-value-count type
)
461 (inst cmp nargs
(fixnumize register-arg-count
))
462 (inst jmp
:g stack-values
)
463 #!+#.
(cl:if
(cl:= sb
!vm
:word-shift sb
!vm
:n-fixnum-tag-bits
) '(and) '(or))
464 (inst sub rsp-tn nargs
)
465 #!-
#.
(cl:if
(cl:= sb
!vm
:word-shift sb
!vm
:n-fixnum-tag-bits
) '(and) '(or))
467 ;; FIXME: This can't be efficient, but LEA (my first choice)
468 ;; doesn't do subtraction.
469 (inst shl nargs
(- word-shift n-fixnum-tag-bits
))
470 (inst sub rsp-tn nargs
)
471 (inst shr nargs
(- word-shift n-fixnum-tag-bits
)))
472 (emit-label stack-values
))
473 ;; dtc: this writes the registers onto the stack even if they are
474 ;; not needed, only the number specified in rcx are used and have
475 ;; stack allocated to them. No harm is done.
477 for arg in
*register-arg-tns
*
479 for j below
(sb!kernel
:values-type-max-value-count type
)
480 do
(storew arg args i
))
487 ;;; VOP that can be inherited by unknown values receivers. The main thing this
488 ;;; handles is allocation of the result temporaries.
489 (define-vop (unknown-values-receiver)
490 (:temporary
(:sc descriptor-reg
:offset rbx-offset
491 :from
:eval
:to
(:result
0))
493 (:temporary
(:sc any-reg
:offset rcx-offset
494 :from
:eval
:to
(:result
1))
496 (:results
(start :scs
(any-reg control-stack
))
497 (count :scs
(any-reg control-stack
))))
499 ;;;; local call with unknown values convention return
501 (defun check-ocfp-and-return-pc (old-fp return-pc
)
503 (format t
"*known-return: old-fp ~S, tn-kind ~S; ~S ~S~%"
504 old-fp
(tn-kind old-fp
) (sb!c
::tn-save-tn old-fp
)
505 (tn-kind (sb!c
::tn-save-tn old-fp
)))
507 (format t
"*known-return: return-pc ~S, tn-kind ~S; ~S ~S~%"
508 return-pc
(tn-kind return-pc
)
509 (sb!c
::tn-save-tn return-pc
)
510 (tn-kind (sb!c
::tn-save-tn return-pc
)))
511 (unless (and (sc-is old-fp control-stack
)
512 (= (tn-offset old-fp
) ocfp-save-offset
))
513 (error "ocfp not on stack in standard save location?"))
514 (unless (and (sc-is return-pc sap-stack
)
515 (= (tn-offset return-pc
) return-pc-save-offset
))
516 (error "return-pc not on stack in standard save location?")))
518 ;;; The local call convention doesn't fit that well with x86-style
519 ;;; calls. Emit a header for local calls to pop the return address
520 ;;; in the right place.
521 (defun emit-block-header (start-label trampoline-label fall-thru-p alignp
)
522 (when (and fall-thru-p trampoline-label
)
523 (inst jmp start-label
))
524 (when trampoline-label
525 (emit-label trampoline-label
)
526 (popw rbp-tn
(frame-word-offset return-pc-save-offset
)))
528 (emit-alignment n-lowtag-bits
:long-nop
))
529 (emit-label start-label
))
531 ;;; Non-TR local call for a fixed number of values passed according to
532 ;;; the unknown values convention.
534 ;;; FP is the frame pointer in install before doing the call.
536 ;;; NFP would be the number-stack frame pointer if we had a separate
539 ;;; Args are the argument passing locations, which are specified only
540 ;;; to terminate their lifetimes in the caller.
542 ;;; VALUES are the return value locations (wired to the standard
543 ;;; passing locations). NVALS is the number of values received.
545 ;;; Save is the save info, which we can ignore since saving has been
548 ;;; TARGET is a continuation pointing to the start of the called
550 (define-vop (call-local)
554 (:results
(values :more t
))
556 (:move-args
:local-call
)
557 (:info arg-locs callee target nvals
)
559 (:ignore nfp arg-locs args callee
)
563 (note-this-location vop
:call-site
)
565 (default-unknown-values vop values nvals node
)))
567 ;;; Non-TR local call for a variable number of return values passed according
568 ;;; to the unknown values convention. The results are the start of the values
569 ;;; glob and the number of values received.
570 (define-vop (multiple-call-local unknown-values-receiver
)
575 (:move-args
:local-call
)
576 (:info save callee target
)
577 (:ignore args save nfp callee
)
582 (note-this-location vop
:call-site
)
584 (note-this-location vop
:unknown-return
)
585 (receive-unknown-values values-start nvals start count node
)))
587 ;;;; local call with known values return
589 ;;; Non-TR local call with known return locations. Known-value return
590 ;;; works just like argument passing in local call.
592 ;;; Note: we can't use normal load-tn allocation for the fixed args,
593 ;;; since all registers may be tied up by the more operand. Instead,
594 ;;; we use MAYBE-LOAD-STACK-TN.
595 (define-vop (known-call-local)
599 (:results
(res :more t
))
600 (:move-args
:local-call
)
602 (:info save callee target
)
603 (:ignore args res save nfp callee
)
607 (note-this-location vop
:call-site
)
609 (note-this-location vop
:known-return
)))
611 ;;; From Douglas Crosher
612 ;;; Return from known values call. We receive the return locations as
613 ;;; arguments to terminate their lifetimes in the returning function. We
614 ;;; restore FP and CSP and jump to the Return-PC.
615 (define-vop (known-return)
619 (:move-args
:known-return
)
621 (:ignore val-locs vals
)
624 (check-ocfp-and-return-pc old-fp return-pc
)
625 ;; Zot all of the stack except for the old-fp and return-pc.
626 (inst mov rsp-tn rbp-tn
)
632 ;;; There is something of a cross-product effect with full calls.
633 ;;; Different versions are used depending on whether we know the
634 ;;; number of arguments or the name of the called function, and
635 ;;; whether we want fixed values, unknown values, or a tail call.
637 ;;; In full call, the arguments are passed creating a partial frame on
638 ;;; the stack top and storing stack arguments into that frame. On
639 ;;; entry to the callee, this partial frame is pointed to by FP.
641 ;;; This macro helps in the definition of full call VOPs by avoiding
642 ;;; code replication in defining the cross-product VOPs.
644 ;;; NAME is the name of the VOP to define.
646 ;;; NAMED is true if the first argument is an fdefinition object whose
647 ;;; definition is to be called.
649 ;;; RETURN is either :FIXED, :UNKNOWN or :TAIL:
650 ;;; -- If :FIXED, then the call is for a fixed number of values, returned in
651 ;;; the standard passing locations (passed as result operands).
652 ;;; -- If :UNKNOWN, then the result values are pushed on the stack, and the
653 ;;; result values are specified by the Start and Count as in the
654 ;;; unknown-values continuation representation.
655 ;;; -- If :TAIL, then do a tail-recursive call. No values are returned.
656 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
658 ;;; In non-tail calls, the pointer to the stack arguments is passed as
659 ;;; the last fixed argument. If Variable is false, then the passing
660 ;;; locations are passed as a more arg. Variable is true if there are
661 ;;; a variable number of arguments passed on the stack. Variable
662 ;;; cannot be specified with :TAIL return. TR variable argument call
663 ;;; is implemented separately.
665 ;;; In tail call with fixed arguments, the passing locations are
666 ;;; passed as a more arg, but there is no new-FP, since the arguments
667 ;;; have been set up in the current frame.
668 (macrolet ((define-full-call (name named return variable
)
669 (aver (not (and variable
(eq return
:tail
))))
671 ,@(when (eq return
:unknown
)
672 '(unknown-values-receiver)))
674 ,@(unless (eq return
:tail
)
675 '((new-fp :scs
(any-reg) :to
(:argument
1))))
677 (fun :scs
(descriptor-reg control-stack
)
678 :target rax
:to
(:argument
0))
680 ,@(when (eq return
:tail
)
684 ,@(unless variable
'((args :more t
:scs
(descriptor-reg)))))
686 ,@(when (eq return
:fixed
)
687 '((:results
(values :more t
))))
689 (:save-p
,(if (eq return
:tail
) :compute-only t
))
691 ,@(unless (or (eq return
:tail
) variable
)
692 '((:move-args
:full-call
)))
696 ,@(unless (or variable
(eq return
:tail
)) '(arg-locs))
697 ,@(unless variable
'(nargs))
698 ,@(when (eq return
:fixed
) '(nvals))
702 ,@(unless (or variable
(eq return
:tail
)) '(arg-locs))
703 ,@(unless variable
'(args)))
705 ;; We pass either the fdefn object (for named call) or
706 ;; the actual function object (for unnamed call) in
707 ;; RAX. With named call, closure-tramp will replace it
708 ;; with the real function and invoke the real function
709 ;; for closures. Non-closures do not need this value,
710 ;; so don't care what shows up in it.
718 ;; We pass the number of arguments in RCX.
719 (:temporary
(:sc unsigned-reg
:offset rcx-offset
:to
:eval
) rcx
)
721 ;; With variable call, we have to load the
722 ;; register-args out of the (new) stack frame before
723 ;; doing the call. Therefore, we have to tell the
724 ;; lifetime stuff that we need to use them.
726 (mapcar (lambda (name offset
)
727 `(:temporary
(:sc descriptor-reg
732 *register-arg-names
* *register-arg-offsets
*))
734 ,@(when (eq return
:tail
)
735 '((:temporary
(:sc unsigned-reg
739 ,@(unless (eq return
:tail
)
742 (:generator
,(+ (if named
5 0)
744 (if (eq return
:tail
) 0 10)
746 (if (eq return
:unknown
) 25 0))
747 ;; This has to be done before the frame pointer is
748 ;; changed! RAX stores the 'lexical environment' needed
754 ;; For variable call, compute the number of
755 ;; arguments and move some of the arguments to
758 ;; Compute the number of arguments.
759 (noise '(inst mov rcx new-fp
))
760 (noise '(inst sub rcx rsp-tn
))
761 #.
(unless (= word-shift n-fixnum-tag-bits
)
762 '(noise '(inst shr rcx
763 (- word-shift n-fixnum-tag-bits
))))
764 ;; Move the necessary args to registers,
765 ;; this moves them all even if they are
768 for name in
*register-arg-names
*
769 for index downfrom -
1
770 do
(noise `(loadw ,name new-fp
,index
)))
774 (inst mov rcx
(fixnumize nargs
)))))
775 ,@(cond ((eq return
:tail
)
776 '(;; Python has figured out what frame we should
777 ;; return to so might as well use that clue.
778 ;; This seems really important to the
779 ;; implementation of things like
780 ;; (without-interrupts ...)
782 ;; dtc; Could be doing a tail call from a
783 ;; known-local-call etc in which the old-fp
784 ;; or ret-pc are in regs or in non-standard
785 ;; places. If the passing location were
786 ;; wired to the stack in standard locations
787 ;; then these moves will be un-necessary;
788 ;; this is probably best for the x86.
791 (unless (= ocfp-save-offset
793 ;; FIXME: FORMAT T for stale
794 ;; diagnostic output (several of
795 ;; them around here), ick
796 (error "** tail-call old-fp not S0~%")
797 (move old-fp-tmp old-fp
)
800 (frame-word-offset ocfp-save-offset
))))
801 ((any-reg descriptor-reg
)
802 (error "** tail-call old-fp in reg not S0~%")
805 (frame-word-offset ocfp-save-offset
))))
807 ;; For tail call, we have to push the
808 ;; return-pc so that it looks like we CALLed
809 ;; despite the fact that we are going to JMP.
810 (inst push return-pc
)
813 ;; For non-tail call, we have to save our
814 ;; frame pointer and install the new frame
815 ;; pointer. We can't load stack tns after this
817 `(;; Python doesn't seem to allocate a frame
818 ;; here which doesn't leave room for the
821 ;; The variable args are on the stack and
822 ;; become the frame, but there may be <3
823 ;; args and 3 stack slots are assumed
824 ;; allocate on the call. So need to ensure
825 ;; there are at least 3 slots. This hack
828 '(inst sub rsp-tn
(* 3 n-word-bytes
)))
830 ;; Bias the new-fp for use as an fp
832 '(inst sub new-fp
(* sp-
>fp-offset n-word-bytes
)))
835 (storew rbp-tn new-fp
836 (frame-word-offset ocfp-save-offset
))
838 (move rbp-tn new-fp
) ; NB - now on new stack frame.
841 (when step-instrumenting
842 (emit-single-step-test)
844 (inst break single-step-around-trap
))
847 (note-this-location vop
:call-site
)
849 (inst ,(if (eq return
:tail
) 'jmp
'call
)
850 (make-ea :qword
:base rax
852 '(- (* fdefn-raw-addr-slot
854 other-pointer-lowtag
)
855 '(- (* closure-fun-slot n-word-bytes
)
856 fun-pointer-lowtag
))))
859 '((default-unknown-values vop values nvals node
)))
861 '((note-this-location vop
:unknown-return
)
862 (receive-unknown-values values-start nvals start count
866 (define-full-call call nil
:fixed nil
)
867 (define-full-call call-named t
:fixed nil
)
868 (define-full-call multiple-call nil
:unknown nil
)
869 (define-full-call multiple-call-named t
:unknown nil
)
870 (define-full-call tail-call nil
:tail nil
)
871 (define-full-call tail-call-named t
:tail nil
)
873 (define-full-call call-variable nil
:fixed t
)
874 (define-full-call multiple-call-variable nil
:unknown t
))
876 ;;; This is defined separately, since it needs special code that BLT's
877 ;;; the arguments down. All the real work is done in the assembly
878 ;;; routine. We just set things up so that it can find what it needs.
879 (define-vop (tail-call-variable)
880 (:args
(args :scs
(any-reg control-stack
) :target rsi
)
881 (function :scs
(descriptor-reg control-stack
) :target rax
)
884 (:temporary
(:sc unsigned-reg
:offset rsi-offset
:from
(:argument
0)) rsi
)
885 (:temporary
(:sc unsigned-reg
:offset rax-offset
:from
(:argument
1)) rax
)
886 (:temporary
(:sc unsigned-reg
) call-target
)
889 (check-ocfp-and-return-pc old-fp return-pc
)
890 ;; Move these into the passing locations if they are not already there.
893 ;; And jump to the assembly routine.
894 (invoke-asm-routine 'jmp
'tail-call-variable vop call-target
)))
896 ;;;; unknown values return
898 ;;; Return a single-value using the Unknown-Values convention.
900 ;;; pfw--get wired-tn conflicts sometimes if register sc specd for args
901 ;;; having problems targeting args to regs -- using temps instead.
903 ;;; First off, modifying the return-pc defeats the branch-prediction
904 ;;; optimizations on modern CPUs quite handily. Second, we can do all
905 ;;; this without needing a temp register. Fixed the latter, at least.
906 ;;; -- AB 2006/Feb/04
907 (define-vop (return-single)
913 (check-ocfp-and-return-pc old-fp return-pc
)
914 ;; Drop stack above old-fp
915 (inst mov rsp-tn rbp-tn
)
916 ;; Clear the multiple-value return flag
918 ;; Restore the old frame pointer
923 ;;; Do unknown-values return of a fixed (other than 1) number of
924 ;;; values. The VALUES are required to be set up in the standard
925 ;;; passing locations. NVALS is the number of values returned.
927 ;;; Basically, we just load RCX with the number of values returned and
928 ;;; RBX with a pointer to the values, set RSP to point to the end of
929 ;;; the values, and jump directly to return-pc.
932 (return-pc :to
(:eval
1))
936 ;; In the case of other than one value, we need these registers to
937 ;; tell the caller where they are and how many there are.
938 (:temporary
(:sc unsigned-reg
:offset rbx-offset
) rbx
)
939 (:temporary
(:sc unsigned-reg
:offset rcx-offset
) rcx
)
940 ;; We need to stretch the lifetime of return-pc past the argument
941 ;; registers so that we can default the argument registers without
942 ;; trashing return-pc.
943 (:temporary
(:sc unsigned-reg
:offset
(first *register-arg-offsets
*)
945 (:temporary
(:sc unsigned-reg
:offset
(second *register-arg-offsets
*)
947 (:temporary
(:sc unsigned-reg
:offset
(third *register-arg-offsets
*)
951 (check-ocfp-and-return-pc old-fp return-pc
)
953 ;; This is handled in RETURN-SINGLE.
954 (error "nvalues is 1"))
955 ;; Establish the values pointer and values count.
956 (inst lea rbx
(make-ea :qword
:base rbp-tn
957 :disp
(* sp-
>fp-offset n-word-bytes
)))
959 (zeroize rcx
) ; smaller
960 (inst mov rcx
(fixnumize nvals
)))
961 ;; Pre-default any argument register that need it.
962 (when (< nvals register-arg-count
)
963 (let* ((arg-tns (nthcdr nvals
(list a0 a1 a2
)))
964 (first (first arg-tns
)))
965 (inst mov first nil-value
)
966 (dolist (tn (cdr arg-tns
))
967 (inst mov tn first
))))
968 ;; Set the multiple value return flag.
970 ;; And away we go. Except that return-pc is still on the
971 ;; stack and we've changed the stack pointer. So we have to
972 ;; tell it to index off of RBX instead of RBP.
973 (cond ((<= nvals register-arg-count
)
974 (inst mov rsp-tn rbp-tn
)
978 ;; Some values are on the stack after RETURN-PC and OLD-FP,
979 ;; can't return normally and some slots of the frame will
980 ;; be used as temporaries by the receiver.
982 ;; Clear as much of the stack as possible, but not past the
983 ;; old frame address.
985 (make-ea :qword
:base rbp-tn
986 :disp
(frame-byte-offset (1- nvals
))))
988 (inst push
(make-ea :qword
:base rbx
989 :disp
(frame-byte-offset
991 (tn-offset return-pc
)))))
994 ;;; Do unknown-values return of an arbitrary number of values (passed
995 ;;; on the stack.) We check for the common case of a single return
996 ;;; value, and do that inline using the normal single value return
997 ;;; convention. Otherwise, we branch off to code that calls an
998 ;;; assembly-routine.
1000 ;;; The assembly routine takes the following args:
1001 ;;; RCX -- number of values to find there.
1002 ;;; RSI -- pointer to where to find the values.
1003 (define-vop (return-multiple)
1006 (vals :scs
(any-reg) :target rsi
)
1007 (nvals :scs
(any-reg) :target rcx
))
1008 (:temporary
(:sc unsigned-reg
:offset rsi-offset
:from
(:argument
2)) rsi
)
1009 (:temporary
(:sc unsigned-reg
:offset rcx-offset
:from
(:argument
3)) rcx
)
1010 (:temporary
(:sc unsigned-reg
) return-asm
)
1011 (:temporary
(:sc descriptor-reg
:offset
(first *register-arg-offsets
*)
1012 :from
(:eval
0)) a0
)
1016 (check-ocfp-and-return-pc old-fp return-pc
)
1017 (unless (policy node
(> space speed
))
1018 ;; Check for the single case.
1019 (let ((not-single (gen-label)))
1020 (inst cmp nvals
(fixnumize 1))
1021 (inst jmp
:ne not-single
)
1022 ;; Return with one value.
1024 ;; Clear the stack until ocfp.
1025 (inst mov rsp-tn rbp-tn
)
1026 ;; clear the multiple-value return flag
1031 ;; Nope, not the single case. Jump to the assembly routine.
1032 (emit-label not-single
)))
1035 (invoke-asm-routine 'jmp
'return-multiple vop return-asm
)))
1039 ;;; Get the lexical environment from its passing location.
1040 (define-vop (setup-closure-environment)
1041 (:results
(closure :scs
(descriptor-reg)))
1046 (move closure rax-tn
)))
1048 ;;; Copy a &MORE arg from the argument area to the end of the current
1049 ;;; frame. FIXED is the number of non-&MORE arguments.
1050 (define-vop (copy-more-arg)
1051 (:temporary
(:sc any-reg
:offset r8-offset
) copy-index
)
1052 (:temporary
(:sc any-reg
:offset r9-offset
) source
)
1053 (:temporary
(:sc descriptor-reg
:offset r10-offset
) temp
)
1054 (:info fixed min-verified
)
1056 ;; Avoid the copy if there are no more args.
1057 (cond ((zerop fixed
)
1058 (inst jrcxz JUST-ALLOC-FRAME
))
1059 ((and (eql min-verified fixed
)
1061 ;; verify-arg-count will do a CMP
1062 (inst jmp
:e JUST-ALLOC-FRAME
))
1064 (inst cmp rcx-tn
(fixnumize fixed
))
1065 (inst jmp
:be JUST-ALLOC-FRAME
)))
1067 ;; Create a negated copy of the number of arguments to allow us to
1068 ;; use EA calculations in order to do scaled subtraction.
1069 (inst mov temp rcx-tn
)
1072 ;; Allocate the space on the stack.
1073 ;; stack = rbp + sp->fp-offset - (max 3 frame-size) - (nargs - fixed)
1074 ;; if we'd move SP backward, swap the meaning of rsp and source;
1075 ;; otherwise, we'd be accessing values below SP, and that's no good
1076 ;; if a signal interrupts this code sequence. In that case, store
1077 ;; the final value in rsp after the stack-stack memmove loop.
1078 (inst lea
(if (<= fixed
(max 3 (sb-allocated-size 'stack
)))
1081 (make-ea :qword
:base rbp-tn
1082 :index temp
:scale
(ash 1 (- word-shift n-fixnum-tag-bits
))
1083 :disp
(* n-word-bytes
1084 (- (+ sp-
>fp-offset fixed
)
1085 (max 3 (sb-allocated-size 'stack
))))))
1087 ;; Now: nargs>=1 && nargs>fixed
1089 (cond ((< fixed register-arg-count
)
1090 ;; the code above only moves the final value of rsp in
1091 ;; rsp directly if that condition is satisfied. Currently,
1092 ;; r-a-c is 3, so the aver is OK. If the calling convention
1093 ;; ever changes, the logic above with LEA will have to be
1095 (aver (<= fixed
(max 3 (sb-allocated-size 'stack
))))
1096 ;; We must stop when we run out of stack args, not when we
1097 ;; run out of more args.
1098 ;; Number to copy = nargs-3
1099 ;; Save the original count of args.
1100 (inst mov rbx-tn rcx-tn
)
1101 (inst sub rbx-tn
(fixnumize register-arg-count
))
1102 ;; Everything of interest in registers.
1103 (inst jmp
:be DO-REGS
))
1105 ;; Number to copy = nargs-fixed
1106 (inst lea rbx-tn
(make-ea :qword
:base rcx-tn
1107 :disp
(- (fixnumize fixed
))))))
1109 ;; Initialize R8 to be the end of args.
1110 ;; Swap with SP if necessary to mirror the previous condition
1111 (inst lea
(if (<= fixed
(max 3 (sb-allocated-size 'stack
)))
1114 (make-ea :qword
:base rbp-tn
1115 :index temp
:scale
(ash 1 (- word-shift n-fixnum-tag-bits
))
1116 :disp
(* sp-
>fp-offset n-word-bytes
)))
1118 ;; src: rbp + temp + sp->fp
1119 ;; dst: rbp + temp + sp->fp + (fixed - (max 3 [stack-size]))
1120 (let ((delta (- fixed
(max 3 (sb-allocated-size 'stack
))))
1122 (fixnum->word
(ash 1 (- word-shift n-fixnum-tag-bits
))))
1123 (cond ((zerop delta
)) ; no-op move
1125 ;; dst is lower than src, copy forward
1126 (zeroize copy-index
)
1127 ;; We used to use REP MOVS here, but on modern x86 it performs
1128 ;; much worse than an explicit loop for small blocks.
1131 (inst mov temp
(make-ea :qword
:base source
:index copy-index
))
1132 (inst mov
(make-ea :qword
:base rsp-tn
:index copy-index
) temp
)
1133 (inst add copy-index n-word-bytes
)
1134 (inst sub rbx-tn
(fixnumize 1))
1135 (inst jmp
:nz loop
))
1137 ;; dst is higher than src; copy backward
1139 (inst sub rbx-tn
(fixnumize 1))
1140 (inst mov temp
(make-ea :qword
:base rsp-tn
1141 :index rbx-tn
:scale fixnum-
>word
))
1142 (inst mov
(make-ea :qword
:base source
1143 :index rbx-tn
:scale fixnum-
>word
)
1146 ;; done with the stack--stack copy. Reset RSP to its final
1148 (inst mov rsp-tn source
))))
1151 ;; Here: nargs>=1 && nargs>fixed
1152 (when (< fixed register-arg-count
)
1153 ;; Now we have to deposit any more args that showed up in
1157 ;; Store it relative to rbp
1158 (inst mov
(make-ea :qword
:base rbp-tn
1159 :disp
(* n-word-bytes
1163 (max 3 (sb-allocated-size
1165 (nth i
*register-arg-tns
*))
1168 (when (>= i register-arg-count
)
1171 ;; Don't deposit any more than there are.
1173 (inst test rcx-tn rcx-tn
)
1174 (inst cmp rcx-tn
(fixnumize i
)))
1175 (inst jmp
:eq DONE
)))
1181 (make-ea :qword
:base rbp-tn
1182 :disp
(* n-word-bytes
1184 (max 3 (sb-allocated-size 'stack
))))))
1188 (define-vop (more-kw-arg)
1189 (:translate sb
!c
::%more-kw-arg
)
1190 (:policy
:fast-safe
)
1191 (:args
(object :scs
(descriptor-reg) :to
(:result
1))
1192 (index :scs
(any-reg) :to
(:result
1) :target keyword
))
1193 (:arg-types
* tagged-num
)
1194 (:results
(value :scs
(descriptor-reg any-reg
))
1195 (keyword :scs
(descriptor-reg any-reg
)))
1198 (inst mov value
(make-ea :qword
:base object
:index index
1199 :scale
(ash 1 (- word-shift n-fixnum-tag-bits
))))
1200 (inst mov keyword
(make-ea :qword
:base object
:index index
1201 :scale
(ash 1 (- word-shift n-fixnum-tag-bits
))
1202 :disp n-word-bytes
))))
1204 (define-vop (more-arg/c
)
1205 (:translate sb
!c
::%more-arg
)
1206 (:policy
:fast-safe
)
1207 (:args
(object :scs
(descriptor-reg) :to
(:result
1)))
1209 (:arg-types
* (:constant
(signed-byte 32)))
1210 (:results
(value :scs
(descriptor-reg any-reg
)))
1213 (inst mov value
(make-ea :qword
:base object
1214 :disp
(- (* index n-word-bytes
))))))
1216 (define-vop (more-arg)
1217 (:translate sb
!c
::%more-arg
)
1218 (:policy
:fast-safe
)
1219 (:args
(object :scs
(descriptor-reg) :to
(:result
1))
1220 (index :scs
(any-reg) :to
(:result
1) :target value
))
1221 (:arg-types
* tagged-num
)
1222 (:results
(value :scs
(descriptor-reg any-reg
)))
1227 (inst mov value
(make-ea :qword
:base object
:index value
1228 :scale
(ash 1 (- word-shift n-fixnum-tag-bits
))))))
1230 ;;; Turn more arg (context, count) into a list.
1231 (define-vop (listify-rest-args)
1232 (:translate %listify-rest-args
)
1234 (:args
(context :scs
(descriptor-reg) :target src
)
1235 (count :scs
(any-reg) :target rcx
))
1236 (:arg-types
* tagged-num
)
1237 (:temporary
(:sc unsigned-reg
:offset rsi-offset
:from
(:argument
0)) src
)
1238 (:temporary
(:sc unsigned-reg
:offset rcx-offset
:from
(:argument
1)) rcx
)
1239 (:temporary
(:sc unsigned-reg
:offset rax-offset
) rax
)
1240 (:temporary
(:sc unsigned-reg
) dst
)
1241 (:results
(result :scs
(descriptor-reg)))
1244 (let ((enter (gen-label))
1247 (stack-allocate-p (node-stack-allocate-p node
)))
1250 ;; Check to see whether there are no args, and just return NIL if so.
1251 (inst mov result nil-value
)
1253 (inst lea dst
(make-ea :qword
:index rcx
:scale
(ash 2 (- word-shift n-fixnum-tag-bits
))))
1254 (maybe-pseudo-atomic stack-allocate-p
1255 (allocation dst dst node stack-allocate-p list-pointer-lowtag
)
1256 ;; Set up the result.
1258 ;; Jump into the middle of the loop, 'cause that's where we want
1262 ;; Compute a pointer to the next cons.
1263 (inst add dst
(* cons-size n-word-bytes
))
1264 ;; Store a pointer to this cons in the CDR of the previous cons.
1265 (storew dst dst -
1 list-pointer-lowtag
)
1267 ;; Grab one value and stash it in the car of this cons.
1268 (inst mov rax
(make-ea :qword
:base src
))
1269 (inst sub src n-word-bytes
)
1270 (storew rax dst
0 list-pointer-lowtag
)
1271 ;; Go back for more.
1272 (inst sub rcx
(fixnumize 1))
1274 ;; NIL out the last cons.
1275 (storew nil-value dst
1 list-pointer-lowtag
))
1276 (emit-label done
))))
1278 ;;; Return the location and size of the &MORE arg glob created by
1279 ;;; COPY-MORE-ARG. SUPPLIED is the total number of arguments supplied
1280 ;;; (originally passed in RCX). FIXED is the number of non-rest
1283 ;;; We must duplicate some of the work done by COPY-MORE-ARG, since at
1284 ;;; that time the environment is in a pretty brain-damaged state,
1285 ;;; preventing this info from being returned as values. What we do is
1286 ;;; compute supplied - fixed, and return a pointer that many words
1287 ;;; below the current stack top.
1288 (define-vop (more-arg-context)
1289 (:policy
:fast-safe
)
1290 (:translate sb
!c
::%more-arg-context
)
1291 (:args
(supplied :scs
(any-reg) :target count
))
1292 (:arg-types positive-fixnum
(:constant fixnum
))
1294 (:results
(context :scs
(descriptor-reg))
1295 (count :scs
(any-reg)))
1296 (:result-types t tagged-num
)
1297 (:note
"more-arg-context")
1299 (move count supplied
)
1300 ;; SP at this point points at the last arg pushed.
1301 ;; Point to the first more-arg, not above it.
1302 (inst lea context
(make-ea :qword
:base rsp-tn
1304 :scale
(ash 1 (- word-shift n-fixnum-tag-bits
))
1305 :disp
(- (* (1+ fixed
) n-word-bytes
))))
1306 (unless (zerop fixed
)
1307 (inst sub count
(fixnumize fixed
)))))
1309 (define-vop (verify-arg-count)
1310 (:policy
:fast-safe
)
1311 (:args
(nargs :scs
(any-reg)))
1312 (:arg-types positive-fixnum
(:constant t
) (:constant t
))
1315 (:save-p
:compute-only
)
1317 ;; NOTE: copy-more-arg expects this to issue a CMP for min > 1
1319 (generate-error-code vop
'invalid-arg-count-error nargs
)))
1320 (flet ((check-min ()
1322 (inst test nargs nargs
)
1323 (inst jmp
:e err-lab
))
1325 (inst cmp nargs
(fixnumize min
))
1326 (inst jmp
:b err-lab
)))))
1329 (inst test nargs nargs
)
1330 (inst cmp nargs
(fixnumize max
)))
1331 (inst jmp
:ne err-lab
))
1334 (inst cmp nargs
(fixnumize max
))
1335 (inst jmp
:a err-lab
))
1339 ;; Signal an error about an untagged number.
1340 ;; These are pretty much boilerplate and could be generic except:
1341 ;; - the names of the SCs could differ between backends (or maybe not?)
1342 ;; - in the "/c" case, the older backends don't eval the errcode
1343 ;; And the 6 vops above ought to be generic too...
1344 ;; FIXME: there are still some occurrences of
1345 ;; note: doing signed word to integer coercion
1346 ;; in regard to SB-C::%TYPE-CHECK-ERROR. Figure out why.
1347 (define-vop (type-check-error/word
)
1348 (:policy
:fast-safe
)
1349 (:translate sb
!c
::%type-check-error
)
1350 (:args
(object :scs
(signed-reg unsigned-reg
))
1351 ;; Types are trees of symbols, so 'any-reg' is not
1353 (type :scs
(any-reg descriptor-reg constant
)))
1354 (:arg-types untagged-num
* (:constant t
))
1355 (:info
*location-context
*)
1357 (:save-p
:compute-only
)
1358 ;; cost is a smidgen less than type-check-error
1359 ;; otherwise this does not get selected.
1361 (error-call vop
'object-not-type-error object type
)))
1362 (define-vop (type-check-error/word
/c
)
1363 (:policy
:fast-safe
)
1364 (:translate sb
!c
::%type-check-error
/c
)
1365 (:args
(object :scs
(signed-reg unsigned-reg
)))
1366 (:arg-types untagged-num
(:constant symbol
) (:constant t
))
1367 (:info errcode
*location-context
*)
1369 (:save-p
:compute-only
)
1370 (:generator
899 ; smidgen less than type-check-error/c
1371 (error-call vop errcode object
)))
1375 (defun emit-single-step-test ()
1376 ;; We use different ways of representing whether stepping is on on
1377 ;; +SB-THREAD / -SB-THREAD: on +SB-THREAD, we use a slot in the
1378 ;; thread structure. On -SB-THREAD we use the value of a static
1379 ;; symbol. Things are done this way, since reading a thread-local
1380 ;; slot from a symbol would require an extra register on +SB-THREAD,
1381 ;; and reading a slot from a thread structure would require an extra
1382 ;; register on -SB-THREAD. While this isn't critical for x86-64,
1383 ;; it's more serious for x86.
1385 (inst cmp
(make-ea :qword
1386 :base thread-base-tn
1387 :disp
(* thread-stepping-slot n-word-bytes
))
1390 (inst cmp
(make-ea :qword
1391 :disp
(+ nil-value
(static-symbol-offset
1392 'sb
!impl
::*stepping
*)
1393 (* symbol-value-slot n-word-bytes
)
1394 (- other-pointer-lowtag
)))
1397 (define-vop (step-instrument-before-vop)
1398 (:policy
:fast-safe
)
1401 (emit-single-step-test)
1403 (inst break single-step-before-trap
)
1405 (note-this-location vop
:step-before-vop
)))