4 ;;;; Interfaces to IR2 conversion:
6 ;;; Return a wired TN describing the N'th full call argument passing
8 (!def-vm-support-routine standard-arg-location (n)
9 (declare (type unsigned-byte n))
10 (if (< n register-arg-count)
11 (make-wired-tn *backend-t-primitive-type*
13 (elt *register-arg-offsets* n))
14 (make-wired-tn *backend-t-primitive-type*
15 control-stack-arg-scn n)))
18 ;;; Make a passing location TN for a local call return PC. If standard is
19 ;;; true, then use the standard (full call) location, otherwise use any legal
20 ;;; location. Even in the non-standard case, this may be restricted by a
21 ;;; desire to use a subroutine call instruction.
22 (!def-vm-support-routine make-return-pc-passing-location (standard)
24 (make-wired-tn *backend-t-primitive-type* register-arg-scn lra-offset)
25 (make-restricted-tn *backend-t-primitive-type* register-arg-scn)))
27 ;;; This is similar to MAKE-RETURN-PC-PASSING-LOCATION, but makes a
28 ;;; location to pass OLD-FP in. This is (obviously) wired in the
29 ;;; standard convention, but is totally unrestricted in non-standard
30 ;;; conventions, since we can always fetch it off of the stack using
32 (!def-vm-support-routine make-old-fp-passing-location (standard)
34 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset)
35 (make-normal-tn *fixnum-primitive-type*)))
37 ;;; Make the TNs used to hold OLD-FP and RETURN-PC within the current
38 ;;; function. We treat these specially so that the debugger can find
39 ;;; them at a known location.
40 (!def-vm-support-routine make-old-fp-save-location (env)
42 (physenv-debug-live-tn (make-normal-tn *fixnum-primitive-type*) env)
43 (make-wired-tn *fixnum-primitive-type*
46 (!def-vm-support-routine make-return-pc-save-location (env)
48 (physenv-debug-live-tn (make-normal-tn *backend-t-primitive-type*) env)
49 (make-wired-tn *backend-t-primitive-type*
53 ;;; Make a TN for the standard argument count passing location. We only
54 ;;; need to make the standard location, since a count is never passed when we
55 ;;; are using non-standard conventions.
56 (!def-vm-support-routine make-arg-count-location ()
57 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))
60 ;;; Make a TN to hold the number-stack frame pointer. This is allocated
61 ;;; once per component, and is component-live.
62 (!def-vm-support-routine make-nfp-tn ()
64 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nfp-offset)))
66 (!def-vm-support-routine make-stack-pointer-tn ()
67 (make-normal-tn *fixnum-primitive-type*))
69 (!def-vm-support-routine make-number-stack-pointer-tn ()
70 (make-normal-tn *fixnum-primitive-type*))
72 ;;; Return a list of TNs that can be used to represent an unknown-values
73 ;;; continuation within a function.
74 (!def-vm-support-routine make-unknown-values-locations ()
75 (list (make-stack-pointer-tn)
76 (make-normal-tn *fixnum-primitive-type*)))
79 ;;; This function is called by the ENTRY-ANALYZE phase, allowing
80 ;;; VM-dependent initialization of the IR2-COMPONENT structure. We push
81 ;;; placeholder entries in the Constants to leave room for additional
82 ;;; noise in the code object header.
83 (!def-vm-support-routine select-component-format (component)
84 (declare (type component component))
85 (dotimes (i code-constants-offset)
86 (vector-push-extend nil
87 (ir2-component-constants (component-info component))))
93 ;;; Return the number of bytes needed for the current non-descriptor stack.
94 ;;; We have to allocate multiples of 64 bytes.
95 (defun bytes-needed-for-non-descriptor-stack-frame ()
96 (logandc2 (+ (* (sb-allocated-size 'non-descriptor-stack) n-word-bytes) 63)
99 ;;; Used for setting up the Old-FP in local call.
101 (define-vop (current-fp)
102 (:results (val :scs (any-reg)))
106 ;;; Used for computing the caller's NFP for use in known-values return. Only
107 ;;; works assuming there is no variable size stuff on the nstack.
109 (define-vop (compute-old-nfp)
110 (:results (val :scs (any-reg)))
113 (let ((nfp (current-nfp-tn vop)))
115 (inst addi (- (bytes-needed-for-non-descriptor-stack-frame))
118 (define-vop (xep-allocate-frame)
119 (:info start-lab copy-more-arg-follows)
120 (:ignore copy-more-arg-follows)
122 (:temporary (:scs (non-descriptor-reg)) temp)
124 ;; Make sure the function is aligned, and drop a label pointing to this
126 (align n-lowtag-bits)
127 (trace-table-entry trace-table-fun-prologue)
128 (emit-label start-lab)
129 ;; Allocate function header.
130 (inst fun-header-word)
131 (dotimes (i (1- simple-fun-code-offset))
133 ;; The start of the actual code.
134 ;; Fix CODE, cause the function object was passed in.
135 (let ((entry-point (gen-label)))
136 (emit-label entry-point)
137 (inst compute-code-from-fn lip-tn entry-point temp code-tn))
138 ;; Build our stack frames.
139 (inst addi (* n-word-bytes (sb-allocated-size 'control-stack))
141 (let ((nfp (current-nfp-tn vop)))
144 (inst addi (bytes-needed-for-non-descriptor-stack-frame)
146 (trace-table-entry trace-table-normal)))
148 (define-vop (allocate-frame)
149 (:results (res :scs (any-reg))
150 (nfp :scs (any-reg)))
154 (inst addi (* n-word-bytes (sb-allocated-size 'control-stack))
156 (when (ir2-physenv-number-stack-p callee)
158 (inst addi (bytes-needed-for-non-descriptor-stack-frame)
161 ;;; Allocate a partial frame for passing stack arguments in a full call. Nargs
162 ;;; is the number of arguments passed. If no stack arguments are passed, then
163 ;;; we don't have to do anything.
165 (define-vop (allocate-full-call-frame)
167 (:results (res :scs (any-reg)))
169 (when (> nargs register-arg-count)
171 (inst addi (* nargs n-word-bytes) csp-tn csp-tn))))
174 ;;; Emit code needed at the return-point from an unknown-values call for a
175 ;;; fixed number of values. VALUES is the head of the TN-REF list for the
176 ;;; locations that the values are to be received into. NVALS is the number of
177 ;;; values that are to be received (should equal the length of VALUES).
179 ;;; MOVE-TEMP is a DESCRIPTOR-REG TN used as a temporary.
181 ;;; This code exploits the fact that in the unknown-values convention, a
182 ;;; single value return returns at the return PC + 8, whereas a return of other
183 ;;; than one value returns directly at the return PC.
185 ;;; If 0 or 1 values are expected, then we just emit an instruction to reset
186 ;;; the SP (which will only be executed when other than 1 value is returned.)
188 ;;; In the general case, we have to do three things:
189 ;;; -- Default unsupplied register values. This need only be done when a
190 ;;; single value is returned, since register values are defaulted by the
191 ;;; called in the non-single case.
192 ;;; -- Default unsupplied stack values. This needs to be done whenever there
193 ;;; are stack values.
194 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
195 ;;; regardless of the number of values desired.
197 ;;; The general-case code looks like this:
199 b regs-defaulted ; Skip if MVs
202 move a1 null-tn ; Default register values
204 loadi nargs 1 ; Force defaulting of stack values
205 move old-fp csp ; Set up args for SP resetting
208 subu temp nargs register-arg-count
210 bltz temp default-value-7 ; jump to default code
212 loadw move-temp old-fp-tn 6 ; Move value to correct location.
213 store-stack-tn val4-tn move-temp
215 bltz temp default-value-8
217 loadw move-temp old-fp-tn 7
218 store-stack-tn val5-tn move-temp
223 move sp old-fp ; Reset SP.
228 store-stack-tn val4-tn null-tn ; Nil out 7'th value. (first on stack)
231 store-stack-tn val5-tn null-tn ; Nil out 8'th value.
239 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
240 (declare (type (or tn-ref null) values)
241 (type unsigned-byte nvals) (type tn move-temp temp))
245 ;; Note that this is a single-value return point. This is actually
246 ;; the multiple-value entry point for a single desired value, but
247 ;; the code location has to be here, or the debugger backtrace
249 (note-this-location vop :single-value-return)
250 (move ocfp-tn csp-tn)
251 (inst compute-code-from-lra code-tn lra-label temp code-tn)))
252 ((<= nvals register-arg-count)
254 ;; Note that this is an unknown-values return point.
255 (note-this-location vop :unknown-return)
256 ;; Branch off to the MV case.
257 (inst b regs-defaulted :nullify t)
259 ;; Default any unsupplied values.
260 (do ((val (tn-ref-across values) (tn-ref-across val)))
262 (inst move null-tn (tn-ref-tn val)
263 (if (tn-ref-across val)
269 ;; Clear the stack. Note: the last move in the single value reg
270 ;; defaulting nullifies this, so this only happens in the mv case.
271 (move ocfp-tn csp-tn)
274 (inst compute-code-from-lra code-tn lra-label temp code-tn)))
276 (collect ((defaults))
277 (assemble (nil nil :labels (default-stack-vals))
278 ;; Note that this is an unknown-values return point.
279 (note-this-location vop :unknown-return)
280 ;; Branch off to the MV case.
281 (inst b regs-defaulted :nullify t)
283 ;; Default any unsupplied register values.
285 (val (tn-ref-across values) (tn-ref-across val)))
286 ((= i register-arg-count))
287 (inst move null-tn (tn-ref-tn val)))
288 (inst b default-stack-vals)
289 (move ocfp-tn csp-tn)
293 (do ((i register-arg-count (1+ i))
294 (val (do ((i 0 (1+ i))
295 (val values (tn-ref-across val)))
296 ((= i register-arg-count) val))
297 (tn-ref-across val)))
300 (let ((default-lab (gen-label))
301 (tn (tn-ref-tn val)))
302 (defaults (cons default-lab tn))
303 (inst bci :>= nil (fixnumize i) nargs-tn default-lab)
304 (loadw move-temp ocfp-tn i)
305 (store-stack-tn tn move-temp)))
308 (move ocfp-tn csp-tn)
309 (inst compute-code-from-lra code-tn lra-label temp code-tn)
311 (let ((defaults (defaults)))
313 (assemble (*elsewhere*)
314 (trace-table-entry trace-table-call-site)
316 (do ((remaining defaults (cdr remaining)))
318 (let ((def (car remaining)))
319 (emit-label (car def))
320 (when (null (cdr remaining))
321 (inst b defaulting-done))
322 (store-stack-tn (cdr def) null-tn)))
323 (trace-table-entry trace-table-normal)))))))
327 ;;;; Unknown values receiving:
329 ;;; Emit code needed at the return point for an unknown-values call for an
330 ;;; arbitrary number of values.
332 ;;; We do the single and non-single cases with no shared code: there doesn't
333 ;;; seem to be any potential overlap, and receiving a single value is more
334 ;;; important efficiency-wise.
336 ;;; When there is a single value, we just push it on the stack, returning
337 ;;; the old SP and 1.
339 ;;; When there is a variable number of values, we move all of the argument
340 ;;; registers onto the stack, and return Args and Nargs.
342 ;;; Args and Nargs are TNs wired to the named locations. We must
343 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
344 ;;; results Start and Count (also, it's nice to be able to target them).
346 (defun receive-unknown-values (args nargs start count lra-label temp)
347 (declare (type tn args nargs start count temp))
348 (assemble (nil nil :labels (variable-values))
349 (inst b variable-values :nullify t)
351 (inst compute-code-from-lra code-tn lra-label temp code-tn)
352 (inst move csp-tn start)
353 (inst stwm (first register-arg-tns) n-word-bytes csp-tn)
354 (inst li (fixnumize 1) count)
358 (assemble (*elsewhere*)
359 (trace-table-entry trace-table-call-site)
361 (inst compute-code-from-lra code-tn lra-label temp code-tn)
362 (do ((arg register-arg-tns (rest arg))
365 (storew (first arg) args i))
368 (inst b done :nullify t)
369 (trace-table-entry trace-table-normal)))
372 ;;; VOP that can be inherited by unknown values receivers. The main thing this
373 ;;; handles is allocation of the result temporaries.
375 (define-vop (unknown-values-receiver)
376 (:results (start :scs (any-reg))
377 (count :scs (any-reg)))
378 (:temporary (:sc descriptor-reg :offset ocfp-offset
379 :from :eval :to (:result 0))
381 (:temporary (:sc any-reg :offset nargs-offset
382 :from :eval :to (:result 1))
384 (:temporary (:scs (non-descriptor-reg)) temp))
388 ;;;; Local call with unknown values convention return:
390 ;;; Non-TR local call for a fixed number of values passed according to the
391 ;;; unknown values convention.
393 ;;; Args are the argument passing locations, which are specified only to
394 ;;; terminate their lifetimes in the caller.
396 ;;; Values are the return value locations (wired to the standard passing
399 ;;; Save is the save info, which we can ignore since saving has been done.
400 ;;; Return-PC is the TN that the return PC should be passed in.
401 ;;; Target is a continuation pointing to the start of the called function.
402 ;;; Nvals is the number of values received.
404 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
405 ;;; registers may be tied up by the more operand. Instead, we use
406 ;;; MAYBE-LOAD-STACK-TN.
408 (define-vop (call-local)
412 (:results (values :more t))
414 (:move-args :local-call)
415 (:info arg-locs callee target nvals)
417 (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
418 (:temporary (:scs (non-descriptor-reg)) temp)
419 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
420 (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
421 (:ignore arg-locs args ocfp)
423 (trace-table-entry trace-table-call-site)
424 (let ((label (gen-label))
425 (cur-nfp (current-nfp-tn vop)))
427 (store-stack-tn nfp-save cur-nfp))
428 (let ((callee-nfp (callee-nfp-tn callee)))
430 (maybe-load-stack-tn callee-nfp nfp)))
431 (maybe-load-stack-tn cfp-tn cfp)
432 (inst compute-lra-from-code code-tn label temp
433 (callee-return-pc-tn callee))
434 (note-this-location vop :call-site)
435 (inst b target :nullify t)
436 (emit-return-pc label)
437 (default-unknown-values vop values nvals move-temp temp label)
439 (load-stack-tn cur-nfp nfp-save)))
440 (trace-table-entry trace-table-normal)))
442 ;;; Non-TR local call for a variable number of return values passed according
443 ;;; to the unknown values convention. The results are the start of the values
444 ;;; glob and the number of values received.
446 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
447 ;;; registers may be tied up by the more operand. Instead, we use
448 ;;; MAYBE-LOAD-STACK-TN.
450 (define-vop (multiple-call-local unknown-values-receiver)
455 (:move-args :local-call)
456 (:info save callee target)
459 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
461 (trace-table-entry trace-table-call-site)
462 (let ((label (gen-label))
463 (cur-nfp (current-nfp-tn vop)))
465 (store-stack-tn nfp-save cur-nfp))
466 (let ((callee-nfp (callee-nfp-tn callee)))
468 (maybe-load-stack-tn callee-nfp nfp)))
469 (maybe-load-stack-tn cfp-tn cfp)
470 (inst compute-lra-from-code code-tn label temp
471 (callee-return-pc-tn callee))
472 (note-this-location vop :call-site)
473 (inst b target :nullify t)
474 (emit-return-pc label)
475 (note-this-location vop :unknown-return)
476 (receive-unknown-values values-start nvals start count label temp)
478 (load-stack-tn cur-nfp nfp-save)))
479 (trace-table-entry trace-table-normal)))
482 ;;;; Local call with known values return:
484 ;;; Non-TR local call with known return locations. Known-value return works
485 ;;; just like argument passing in local call.
487 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
488 ;;; registers may be tied up by the more operand. Instead, we use
489 ;;; MAYBE-LOAD-STACK-TN.
491 (define-vop (known-call-local)
495 (:results (res :more t))
496 (:move-args :local-call)
498 (:info save callee target)
499 (:ignore args res save)
501 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
502 (:temporary (:scs (non-descriptor-reg)) temp)
504 (trace-table-entry trace-table-call-site)
505 (let ((label (gen-label))
506 (cur-nfp (current-nfp-tn vop)))
508 (store-stack-tn nfp-save cur-nfp))
509 (let ((callee-nfp (callee-nfp-tn callee)))
511 (maybe-load-stack-tn callee-nfp nfp)))
512 (maybe-load-stack-tn cfp-tn cfp)
513 (inst compute-lra-from-code code-tn label temp
514 (callee-return-pc-tn callee))
515 (note-this-location vop :call-site)
516 (inst b target :nullify t)
517 (emit-return-pc label)
518 (note-this-location vop :known-return)
520 (load-stack-tn cur-nfp nfp-save)))
521 (trace-table-entry trace-table-normal)))
523 ;;; Return from known values call. We receive the return locations as
524 ;;; arguments to terminate their lifetimes in the returning function. We
525 ;;; restore FP and CSP and jump to the Return-PC.
527 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
528 ;;; registers may be tied up by the more operand. Instead, we use
529 ;;; MAYBE-LOAD-STACK-TN.
531 (define-vop (known-return)
532 (:args (old-fp :target old-fp-temp)
533 (return-pc :target return-pc-temp)
535 (:temporary (:sc any-reg :from (:argument 0)) old-fp-temp)
536 (:temporary (:sc descriptor-reg :from (:argument 1)) return-pc-temp)
537 (:temporary (:scs (interior-reg)) lip)
538 (:move-args :known-return)
540 (:ignore val-locs vals)
543 (trace-table-entry trace-table-fun-epilogue)
544 (maybe-load-stack-tn old-fp-temp old-fp)
545 (maybe-load-stack-tn return-pc-temp return-pc)
547 (let ((cur-nfp (current-nfp-tn vop)))
549 (move cur-nfp nsp-tn)))
550 (inst addi (- n-word-bytes other-pointer-lowtag) return-pc-temp lip)
552 (move old-fp-temp cfp-tn)
553 (trace-table-entry trace-table-normal)))
558 ;;; There is something of a cross-product effect with full calls. Different
559 ;;; versions are used depending on whether we know the number of arguments or
560 ;;; the name of the called function, and whether we want fixed values, unknown
561 ;;; values, or a tail call.
563 ;;; In full call, the arguments are passed creating a partial frame on the
564 ;;; stack top and storing stack arguments into that frame. On entry to the
565 ;;; callee, this partial frame is pointed to by FP. If there are no stack
566 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
567 ;;; to SP just before the call.
569 ;;; This macro helps in the definition of full call VOPs by avoiding code
570 ;;; replication in defining the cross-product VOPs.
572 ;;; Name is the name of the VOP to define.
574 ;;; Named is true if the first argument is a symbol whose global function
575 ;;; definition is to be called.
577 ;;; Return is either :Fixed, :Unknown or :Tail:
578 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
579 ;;; the standard passing locations (passed as result operands).
580 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
581 ;;; result values are specified by the Start and Count as in the
582 ;;; unknown-values continuation representation.
583 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
584 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
586 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
587 ;;; fixed argument. If Variable is false, then the passing locations are
588 ;;; passed as a more arg. Variable is true if there are a variable number of
589 ;;; arguments passed on the stack. Variable cannot be specified with :Tail
590 ;;; return. TR variable argument call is implemented separately.
592 ;;; In tail call with fixed arguments, the passing locations are passed as a
593 ;;; more arg, but there is no new-FP, since the arguments have been set up in
594 ;;; the current frame.
596 (macrolet ((define-full-call (name named return variable)
597 (assert (not (and variable (eq return :tail))))
599 ,@(when (eq return :unknown)
600 '(unknown-values-receiver)))
602 ,@(unless (eq return :tail)
603 '((new-fp :scs (any-reg) :to :eval)))
606 '(fdefn :target fdefn-pass)
607 '(arg-fun :target lexenv))
609 ,@(when (eq return :tail)
610 '((ocfp :target ocfp-pass)
611 (lra :target lra-pass)))
613 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
615 ,@(when (eq return :fixed)
616 '((:results (values :more t))))
618 (:save-p ,(if (eq return :tail) :compute-only t))
620 ,@(unless (or (eq return :tail) variable)
621 '((:move-args :full-call)))
624 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
625 ,@(unless variable '(nargs))
626 ,@(when (eq return :fixed) '(nvals)))
629 ,@(unless (or variable (eq return :tail)) '(arg-locs))
630 ,@(unless variable '(args)))
632 (:temporary (:sc descriptor-reg
634 ,@(when (eq return :tail)
635 '(:from (:argument 1)))
636 ,@(unless (eq return :fixed)
640 (:temporary (:sc descriptor-reg
642 ,@(when (eq return :tail)
643 '(:from (:argument 2)))
648 `((:temporary (:sc descriptor-reg :offset fdefn-offset
649 :from (:argument ,(if (eq return :tail) 0 1))
653 `((:temporary (:sc descriptor-reg :offset lexenv-offset
654 :from (:argument ,(if (eq return :tail) 0 1))
657 (:temporary (:scs (descriptor-reg)
658 :from (:argument ,(if (eq return :tail) 2 1))
662 (:temporary (:sc any-reg :offset nargs-offset :to :eval)
666 (mapcar #'(lambda (name offset)
667 `(:temporary (:sc descriptor-reg
671 register-arg-names *register-arg-offsets*))
672 ,@(when (eq return :fixed)
673 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
675 ,@(unless (eq return :tail)
676 '((:temporary (:scs (non-descriptor-reg)) temp)
677 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
679 (:temporary (:scs (interior-reg) :type interior) lip)
681 (:generator ,(+ (if named 5 0)
683 (if (eq return :tail) 0 10)
685 (if (eq return :unknown) 25 0))
686 (trace-table-entry trace-table-call-site)
687 (let* ((cur-nfp (current-nfp-tn vop))
688 ,@(unless (eq return :tail)
689 '((lra-label (gen-label))))
692 ,@(if (eq return :tail)
693 '((unless (location= ocfp ocfp-pass)
695 (unless (location= lra lra-pass)
708 ((nil) (do-next-filler))
711 `((inst sub csp-tn new-fp nargs-pass)
713 (mapcar #'(lambda (name)
716 register-arg-names)))
717 '((inst li (fixnumize nargs) nargs-pass))))
718 ,@(if (eq return :tail)
722 (inst move ocfp ocfp-pass))
724 (loadw ocfp-pass cfp-tn (tn-offset ocfp)))))
728 (inst move lra lra-pass))
730 (loadw lra-pass cfp-tn (tn-offset lra)))))
732 (inst move cur-nfp nsp-tn)))
734 (store-stack-tn nfp-save cur-nfp))
736 (inst compute-lra-from-code
737 code-tn lra-label temp lra-pass))
739 (inst move cfp-tn ocfp-pass))
742 '(move new-fp cfp-tn)
743 '(if (> nargs register-arg-count)
745 (move csp-tn cfp-tn))))))))))
749 (descriptor-reg (move fdefn fdefn-pass))
751 (loadw fdefn-pass cfp-tn (tn-offset fdefn))
754 (loadw fdefn-pass code-tn (tn-offset fdefn)
755 other-pointer-lowtag)
757 (loadw lip fdefn-pass fdefn-raw-addr-slot
758 other-pointer-lowtag)
761 (descriptor-reg (move arg-fun lexenv))
763 (loadw lexenv cfp-tn (tn-offset arg-fun))
766 (loadw lexenv code-tn (tn-offset arg-fun)
767 other-pointer-lowtag)
769 (loadw function lexenv closure-fun-slot
772 (inst addi (- (ash simple-fun-code-offset word-shift)
785 (note-this-location vop :call-site)
786 (inst bv lip :nullify (null filler))
791 '((emit-return-pc lra-label)
792 (default-unknown-values vop values nvals
793 move-temp temp lra-label)
795 (load-stack-tn cur-nfp nfp-save))))
797 '((emit-return-pc lra-label)
798 (note-this-location vop :unknown-return)
799 (receive-unknown-values values-start nvals start count
802 (load-stack-tn cur-nfp nfp-save))))
804 (trace-table-entry trace-table-normal)))))
806 (define-full-call call nil :fixed nil)
807 (define-full-call call-named t :fixed nil)
808 (define-full-call multiple-call nil :unknown nil)
809 (define-full-call multiple-call-named t :unknown nil)
810 (define-full-call tail-call nil :tail nil)
811 (define-full-call tail-call-named t :tail nil)
813 (define-full-call call-variable nil :fixed t)
814 (define-full-call multiple-call-variable nil :unknown t))
817 ;;; Defined separately, since needs special code that BLT's the arguments
820 (define-vop (tail-call-variable)
821 (:args (args-arg :scs (any-reg) :target args)
822 (function-arg :scs (descriptor-reg) :target lexenv)
823 (old-fp-arg :scs (any-reg) :target old-fp)
824 (lra-arg :scs (descriptor-reg) :target lra))
826 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
827 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
828 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) old-fp)
829 (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
830 (:temporary (:scs (any-reg) :from (:argument 3)) tmp)
836 ;; Move these into the passing locations if they are not already there.
838 (move function-arg lexenv)
839 (move old-fp-arg old-fp)
842 ;; Clear the number stack if anything is there.
843 (let ((cur-nfp (current-nfp-tn vop)))
845 (inst move cur-nfp nsp-tn)))
847 ;; And jump to the assembly-routine that does the bliting.
848 (let ((fixup (make-fixup 'tail-call-variable :assembly-routine)))
849 (inst ldil fixup tmp)
850 (inst be fixup lisp-heap-space tmp :nullify t))))
853 ;;;; Unknown values return:
855 ;;; Return a single value using the unknown-values convention.
857 (define-vop (return-single)
858 (:args (old-fp :scs (any-reg))
859 (return-pc :scs (descriptor-reg))
864 ;; Clear the number stack.
865 (trace-table-entry trace-table-fun-epilogue)
866 (let ((cur-nfp (current-nfp-tn vop)))
868 (inst move cur-nfp nsp-tn)))
869 ;; Clear the control stack, and restore the frame pointer.
873 (lisp-return return-pc :offset 1)
874 (trace-table-entry trace-table-normal)))
876 ;;; Do unknown-values return of a fixed number of values. The Values are
877 ;;; required to be set up in the standard passing locations. Nvals is the
878 ;;; number of values returned.
880 ;;; If returning a single value, then deallocate the current frame, restore
881 ;;; FP and jump to the single-value entry at Return-PC + 8.
883 ;;; If returning other than one value, then load the number of values returned,
884 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
885 ;;; When there are stack values, we must initialize the argument pointer to
886 ;;; point to the beginning of the values block (which is the beginning of the
891 (old-fp :scs (any-reg))
892 (return-pc :scs (descriptor-reg) :to (:eval 1))
896 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
897 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
898 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
899 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
900 (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
901 (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
902 (:temporary (:sc any-reg :offset nargs-offset) nargs)
903 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
906 ;; Clear the number stack.
907 (trace-table-entry trace-table-fun-epilogue)
908 (let ((cur-nfp (current-nfp-tn vop)))
910 (inst move cur-nfp nsp-tn)))
911 ;; Establish the values pointer and values count.
912 (move cfp-tn val-ptr)
913 (inst li (fixnumize nvals) nargs)
914 ;; restore the frame pointer and clear as much of the control
915 ;; stack as possible.
917 (inst addi (* nvals n-word-bytes) val-ptr csp-tn)
918 ;; pre-default any argument register that need it.
919 (when (< nvals register-arg-count)
920 (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
923 (lisp-return return-pc)
924 (trace-table-entry trace-table-normal)))
926 ;;; Do unknown-values return of an arbitrary number of values (passed on the
927 ;;; stack.) We check for the common case of a single return value, and do that
928 ;;; inline using the normal single value return convention. Otherwise, we
929 ;;; branch off to code that calls an assembly-routine.
931 (define-vop (return-multiple)
933 (old-fp-arg :scs (any-reg) :to (:eval 1))
934 (lra-arg :scs (descriptor-reg) :to (:eval 1))
935 (vals-arg :scs (any-reg) :target vals)
936 (nvals-arg :scs (any-reg) :target nvals))
938 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) old-fp)
939 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
940 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
941 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
942 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
943 (:temporary (:scs (any-reg) :from (:eval 0)) tmp)
949 (trace-table-entry trace-table-fun-epilogue)
950 ;; Clear the number stack.
951 (let ((cur-nfp (current-nfp-tn vop)))
953 (inst move cur-nfp nsp-tn)))
955 (unless (policy node (> space speed))
956 ;; Check for the single case.
957 (inst comib :<> (fixnumize 1) nvals-arg not-single)
960 ;; Return with one value.
962 (move old-fp-arg cfp-tn)
963 (lisp-return lra-arg :offset 1))
965 ;; Nope, not the single case.
967 (move old-fp-arg old-fp)
970 (move nvals-arg nvals)
971 (let ((fixup (make-fixup 'return-multiple :assembly-routine)))
972 (inst ldil fixup tmp)
973 (inst be fixup lisp-heap-space tmp :nullify t))
974 (trace-table-entry trace-table-normal)))
980 ;;; We don't need to do anything special for regular functions.
982 (define-vop (setup-environment)
986 ;; Don't bother doing anything.
989 ;;; Get the lexical environment from it's passing location.
991 (define-vop (setup-closure-environment)
992 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
995 (:results (closure :scs (descriptor-reg)))
1000 (move lexenv closure)))
1002 ;;; Copy a more arg from the argument area to the end of the current frame.
1003 ;;; Fixed is the number of non-more arguments.
1005 (define-vop (copy-more-arg)
1006 (:temporary (:sc any-reg :offset nl0-offset) result)
1007 (:temporary (:sc any-reg :offset nl1-offset) count)
1008 (:temporary (:sc any-reg :offset nl2-offset) src)
1009 (:temporary (:sc any-reg :offset nl3-offset) dst)
1010 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1013 ;; Figure out how many things we are going to copy.
1014 (unless (zerop fixed)
1015 (inst addi (- (fixnumize fixed)) nargs-tn count))
1017 ;; Blow out of here if is nothing to copy.
1018 (inst comb :<= (if (zerop fixed) nargs-tn count) zero-tn done :nullify t)
1020 (when (< fixed register-arg-count)
1021 ;; Save a pointer to the results so we can fill in register args.
1022 ;; We don't need this if there are more fixed args than reg args.
1023 (move csp-tn result))
1025 ;; Allocate the space on the stack.
1026 (inst add csp-tn (if (zerop fixed) nargs-tn count) csp-tn)
1028 (when (< fixed register-arg-count)
1029 ;; We must stop when we run out of stack args, not when we run out of
1031 (inst addi (fixnumize (- register-arg-count)) nargs-tn count)
1032 ;; Everything of interest in registers.
1033 (inst comb :<= count zero-tn do-regs))
1034 ;; Initialize dst to be end of stack.
1037 ;; Initialize src to be end of args.
1038 (inst add cfp-tn nargs-tn src)
1041 ;; *--dst = *--src, --count
1042 (inst ldwm (- n-word-bytes) src temp)
1043 (inst addib :> (fixnumize -1) count loop)
1044 (inst stwm temp (- n-word-bytes) dst)
1047 (when (< fixed register-arg-count)
1048 ;; Now we have to deposit any more args that showed up in registers.
1049 ;; We know there is at least one more arg, otherwise we would have
1050 ;; branched to done up at the top.
1051 (inst addi (fixnumize (- fixed)) nargs-tn count)
1052 (do ((i fixed (1+ i)))
1053 ((>= i register-arg-count))
1054 ;; Is this the last one?
1055 (inst addib :<= (fixnumize -1) count done)
1056 ;; Store it relative to the pointer saved at the start.
1057 (storew (nth i register-arg-tns) result (- i fixed))))
1060 ;;; More args are stored consequtively on the stack, starting immediately at
1061 ;;; the context pointer. The context pointer is not typed, so the lowtag is 0.
1063 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1066 ;;; Turn more arg (context, count) into a list.
1068 (define-vop (listify-rest-args)
1069 (:args (context-arg :target context :scs (descriptor-reg))
1070 (count-arg :target count :scs (any-reg)))
1071 (:arg-types * tagged-num)
1072 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1073 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1074 (:temporary (:scs (descriptor-reg) :from :eval) temp)
1075 (:temporary (:scs (non-descriptor-reg) :from :eval) dst)
1076 (:results (result :scs (descriptor-reg)))
1077 (:translate %listify-rest-args)
1080 (move context-arg context)
1081 (move count-arg count)
1082 ;; Check to see if there are any arguments.
1083 (inst comb := count zero-tn done)
1084 (move null-tn result)
1086 ;; We need to do this atomically.
1089 ;; Allocate a cons (2 words) for each item.
1090 (inst move alloc-tn result)
1091 (inst dep list-pointer-lowtag 31 3 result)
1093 (inst sll count 1 temp)
1094 (inst add alloc-tn temp alloc-tn)
1097 ;; Grab one value and stash it in the car of this cons.
1098 (inst ldwm n-word-bytes context temp)
1099 (storew temp dst 0 list-pointer-lowtag)
1101 ;; Dec count, and if != zero, go back for more.
1102 (inst addi (* 2 n-word-bytes) dst dst)
1103 (inst addib :> (fixnumize -1) count loop :nullify t)
1104 (storew dst dst -1 list-pointer-lowtag)
1106 ;; NIL out the last cons.
1107 (storew null-tn dst -1 list-pointer-lowtag)
1108 ;; Clear out dst, because it points past the last cons.
1109 (move null-tn dst)))
1112 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1113 ;;; Supplied is the total number of arguments supplied (originally passed in
1114 ;;; NARGS.) Fixed is the number of non-rest arguments.
1116 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1117 ;;; time the environment is in a pretty brain-damaged state, preventing this
1118 ;;; info from being returned as values. What we do is compute
1119 ;;; supplied - fixed, and return a pointer that many words below the current
1123 ;;; WTF? FIXME -- CSR
1124 ;;;(setf (info function source-transform 'c::%more-arg-context) nil)
1126 (define-vop (more-arg-context)
1127 (:policy :fast-safe)
1128 (:translate sb!c::%more-arg-context)
1129 (:args (supplied :scs (any-reg)))
1130 (:arg-types tagged-num (:constant fixnum))
1132 (:results (context :scs (descriptor-reg))
1133 (count :scs (any-reg)))
1134 (:result-types t tagged-num)
1135 (:note "more-arg-context")
1137 (inst addi (fixnumize (- fixed)) supplied count)
1138 (inst sub csp-tn count context)))
1141 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1143 (define-vop (verify-arg-count)
1144 (:policy :fast-safe)
1145 (:translate sb!c::%verify-arg-count)
1146 (:args (nargs :scs (any-reg)))
1147 (:arg-types positive-fixnum (:constant t))
1150 (:save-p :compute-only)
1153 (generate-error-code vop invalid-arg-count-error nargs)))
1154 (cond ((zerop count)
1155 (inst bc :<> nil nargs zero-tn err-lab))
1157 (inst bci :<> nil (fixnumize count) nargs err-lab))))))
1159 ;;; Signal an argument count error.
1161 (macrolet ((frob (name error translate &rest args)
1162 `(define-vop (,name)
1164 `((:policy :fast-safe)
1165 (:translate ,translate)))
1166 (:args ,@(mapcar #'(lambda (arg)
1167 `(,arg :scs (any-reg descriptor-reg)))
1170 (:save-p :compute-only)
1172 (error-call vop ,error ,@args)))))
1173 (frob arg-count-error invalid-arg-count-error
1174 sb!c::%arg-count-error nargs)
1175 (frob type-check-error object-not-type-error sb!c::%type-check-error
1177 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1179 (frob odd-key-args-error odd-key-args-error
1180 sb!c::%odd-key-args-error)
1181 (frob unknown-key-arg-error unknown-key-arg-error
1182 sb!c::%unknown-key-arg-error key)
1183 (frob nil-fun-returned-error nil-fun-returned-error nil fun))