0.9.16.38:
[sbcl.git] / src / compiler / mips / call.lisp
1 ;;;; the VM definition of function call for MIPS
2
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.
11
12 (in-package "SB!VM")
13 \f
14 ;;;; Interfaces to IR2 conversion:
15
16 ;;; Return a wired TN describing the N'th full call argument passing
17 ;;; location.
18 (!def-vm-support-routine standard-arg-location (n)
19   (declare (type unsigned-byte n))
20   (if (< n register-arg-count)
21       (make-wired-tn *backend-t-primitive-type*
22                      register-arg-scn
23                      (elt *register-arg-offsets* n))
24       (make-wired-tn *backend-t-primitive-type*
25                      control-stack-arg-scn n)))
26
27
28 ;;; Make a passing location TN for a local call return PC.  If standard is
29 ;;; true, then use the standard (full call) location, otherwise use any legal
30 ;;; location.  Even in the non-standard case, this may be restricted by a
31 ;;; desire to use a subroutine call instruction.
32 (!def-vm-support-routine make-return-pc-passing-location (standard)
33   (if standard
34       (make-wired-tn *backend-t-primitive-type* register-arg-scn lra-offset)
35       (make-restricted-tn *backend-t-primitive-type* register-arg-scn)))
36
37 ;;; This is similar to MAKE-RETURN-PC-PASSING-LOCATION, but makes a
38 ;;; location to pass OLD-FP in. This is (obviously) wired in the
39 ;;; standard convention, but is totally unrestricted in non-standard
40 ;;; conventions, since we can always fetch it off of the stack using
41 ;;; the arg pointer.
42 (!def-vm-support-routine make-old-fp-passing-location (standard)
43   (if standard
44       (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset)
45       (make-normal-tn *fixnum-primitive-type*)))
46
47 ;;; Make the TNs used to hold OLD-FP and RETURN-PC within the current
48 ;;; function. We treat these specially so that the debugger can find
49 ;;; them at a known location.
50 (!def-vm-support-routine make-old-fp-save-location (env)
51   (specify-save-tn
52    (physenv-debug-live-tn (make-normal-tn *fixnum-primitive-type*) env)
53    (make-wired-tn *fixnum-primitive-type*
54                   control-stack-arg-scn
55                   ocfp-save-offset)))
56
57 (!def-vm-support-routine make-return-pc-save-location (env)
58   (let ((ptype *backend-t-primitive-type*))
59     (specify-save-tn
60      (physenv-debug-live-tn (make-normal-tn ptype) env)
61      (make-wired-tn ptype control-stack-arg-scn lra-save-offset))))
62
63 ;;; Make a TN for the standard argument count passing location.  We only
64 ;;; need to make the standard location, since a count is never passed when we
65 ;;; are using non-standard conventions.
66 (!def-vm-support-routine make-arg-count-location ()
67   (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))
68
69
70 ;;; Make a TN to hold the number-stack frame pointer.  This is allocated
71 ;;; once per component, and is component-live.
72 (!def-vm-support-routine make-nfp-tn ()
73   (component-live-tn
74    (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nfp-offset)))
75
76 (!def-vm-support-routine make-stack-pointer-tn ()
77   (make-normal-tn *fixnum-primitive-type*))
78
79 (!def-vm-support-routine make-number-stack-pointer-tn ()
80   (make-normal-tn *fixnum-primitive-type*))
81
82 ;;; Return a list of TNs that can be used to represent an unknown-values
83 ;;; continuation within a function.
84 (!def-vm-support-routine make-unknown-values-locations ()
85   (list (make-stack-pointer-tn)
86         (make-normal-tn *fixnum-primitive-type*)))
87
88
89 ;;; This function is called by the ENTRY-ANALYZE phase, allowing
90 ;;; VM-dependent initialization of the IR2-COMPONENT structure.  We push
91 ;;; placeholder entries in the Constants to leave room for additional
92 ;;; noise in the code object header.
93 (!def-vm-support-routine select-component-format (component)
94   (declare (type component component))
95   (dotimes (i code-constants-offset)
96     (vector-push-extend nil
97                         (ir2-component-constants (component-info component))))
98   (values))
99
100 \f
101 ;;;; Frame hackery:
102
103 ;;; BYTES-NEEDED-FOR-NON-DESCRIPTOR-STACK-FRAME -- internal
104 ;;;
105 ;;; Return the number of bytes needed for the current non-descriptor stack
106 ;;; frame.  Non-descriptor stack frames must be multiples of 8 bytes on
107 ;;; the PMAX.
108 ;;;
109 (defun bytes-needed-for-non-descriptor-stack-frame ()
110   (* (logandc2 (1+ (sb-allocated-size 'non-descriptor-stack)) 1)
111      n-word-bytes))
112
113 ;;; Used for setting up the Old-FP in local call.
114 ;;;
115 (define-vop (current-fp)
116   (:results (val :scs (any-reg)))
117   (:generator 1
118     (move val cfp-tn)))
119
120 ;;; Used for computing the caller's NFP for use in known-values return.  Only
121 ;;; works assuming there is no variable size stuff on the nstack.
122 ;;;
123 (define-vop (compute-old-nfp)
124   (:results (val :scs (any-reg)))
125   (:vop-var vop)
126   (:generator 1
127     (let ((nfp (current-nfp-tn vop)))
128       (when nfp
129         (inst addu val nfp (bytes-needed-for-non-descriptor-stack-frame))))))
130
131
132 (define-vop (xep-allocate-frame)
133   (:info start-lab copy-more-arg-follows)
134   (:ignore copy-more-arg-follows)
135   (:vop-var vop)
136   (:temporary (:scs (non-descriptor-reg)) temp)
137   (:generator 1
138     ;; Make sure the function is aligned, and drop a label pointing to this
139     ;; function header.
140     (align n-lowtag-bits)
141     (trace-table-entry trace-table-fun-prologue)
142     (emit-label start-lab)
143     ;; Allocate function header.
144     (inst simple-fun-header-word)
145     (dotimes (i (1- simple-fun-code-offset))
146       (inst word 0))
147     ;; The start of the actual code.
148     ;; Compute CODE from the address of this entry point.
149     (let ((entry-point (gen-label)))
150       (emit-label entry-point)
151       (inst compute-code-from-lip code-tn lip-tn entry-point temp)
152       ;; ### We should also save it on the stack so that the garbage collector
153       ;; won't forget about us if we call anyone else.
154       )
155     ;; Build our stack frames.
156     (inst addu csp-tn cfp-tn
157           (* n-word-bytes (sb-allocated-size 'control-stack)))
158     (let ((nfp (current-nfp-tn vop)))
159       (when nfp
160         (inst addu nsp-tn nsp-tn
161               (- (bytes-needed-for-non-descriptor-stack-frame)))
162         (move nfp nsp-tn)))
163     (trace-table-entry trace-table-normal)))
164
165 (define-vop (allocate-frame)
166   (:results (res :scs (any-reg))
167             (nfp :scs (any-reg)))
168   (:info callee)
169   (:generator 2
170     (trace-table-entry trace-table-fun-prologue)
171     (move res csp-tn)
172     (inst addu csp-tn csp-tn
173           (* n-word-bytes (sb-allocated-size 'control-stack)))
174     (when (ir2-physenv-number-stack-p callee)
175       (inst addu nsp-tn nsp-tn
176             (- (bytes-needed-for-non-descriptor-stack-frame)))
177       (move nfp nsp-tn))
178     (trace-table-entry trace-table-normal)))
179
180 ;;; Allocate a partial frame for passing stack arguments in a full call.  Nargs
181 ;;; is the number of arguments passed.  If no stack arguments are passed, then
182 ;;; we don't have to do anything.
183 ;;;
184 (define-vop (allocate-full-call-frame)
185   (:info nargs)
186   (:results (res :scs (any-reg)))
187   (:generator 2
188     (when (> nargs register-arg-count)
189       (move res csp-tn)
190       (inst addu csp-tn csp-tn (* nargs n-word-bytes)))))
191
192
193
194 \f
195 ;;; Emit code needed at the return-point from an unknown-values call for a
196 ;;; fixed number of values.  Values is the head of the TN-Ref list for the
197 ;;; locations that the values are to be received into.  Nvals is the number of
198 ;;; values that are to be received (should equal the length of Values).
199 ;;;
200 ;;;    MOVE-TEMP is a DESCRIPTOR-REG TN used as a temporary.
201 ;;;
202 ;;;    This code exploits the fact that in the unknown-values convention, a
203 ;;; single value return returns at the return PC + 8, whereas a return of other
204 ;;; than one value returns directly at the return PC.
205 ;;;
206 ;;;    If 0 or 1 values are expected, then we just emit an instruction to reset
207 ;;; the SP (which will only be executed when other than 1 value is returned.)
208 ;;;
209 ;;; In the general case, we have to do three things:
210 ;;;  -- Default unsupplied register values.  This need only be done when a
211 ;;;     single value is returned, since register values are defaulted by the
212 ;;;     callee in the non-single case.
213 ;;;  -- Default unsupplied stack values.  This needs to be done whenever there
214 ;;;     are stack values.
215 ;;;  -- Reset SP.  This must be done whenever other than 1 value is returned,
216 ;;;     regardless of the number of values desired.
217 ;;;
218 ;;; The general-case code looks like this:
219 #|
220         b regs-defaulted                ; Skip if MVs
221         nop
222
223         move a1 null-tn                 ; Default register values
224         ...
225         loadi nargs 1                   ; Force defaulting of stack values
226         move ocfp csp                   ; Set up args for SP resetting
227
228 regs-defaulted
229         subu temp nargs register-arg-count
230
231         bltz temp default-value-7       ; jump to default code
232         addu temp temp -1
233         loadw move-temp ocfp-tn 6       ; Move value to correct location.
234         store-stack-tn val4-tn move-temp
235
236         bltz temp default-value-8
237         addu temp temp -1
238         loadw move-temp ocfp-tn 7
239         store-stack-tn val5-tn move-temp
240
241         ...
242
243 defaulting-done
244         move csp ocfp                    ; Reset SP.
245 <end of code>
246
247 <elsewhere>
248 default-value-7
249         store-stack-tn val4-tn null-tn  ; Nil out 7'th value. (first on stack)
250
251 default-value-8
252         store-stack-tn val5-tn null-tn  ; Nil out 8'th value.
253
254         ...
255
256         br defaulting-done
257         nop
258 |#
259 ;;;
260 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
261   (declare (type (or tn-ref null) values)
262            (type unsigned-byte nvals) (type tn move-temp temp))
263   (if (<= nvals 1)
264       (progn
265         ;; Note that this is a single-value return point.  This is actually
266         ;; the multiple-value entry point for a single desired value, but
267         ;; the code location has to be here, or the debugger backtrace
268         ;; gets confused.
269         (without-scheduling ()
270           (note-this-location vop :single-value-return)
271           (move csp-tn ocfp-tn t)
272           (inst nop))
273         (when lra-label
274           (inst compute-code-from-lra code-tn code-tn lra-label temp)))
275       (let ((regs-defaulted (gen-label))
276             (defaulting-done (gen-label))
277             (default-stack-vals (gen-label)))
278         (without-scheduling ()
279           ;; Note that this is an unknown-values return point.
280           (note-this-location vop :unknown-return)
281           ;; Branch off to the MV case.
282           (inst b regs-defaulted)
283           ;; If there are no stack results, clear the stack now.
284           (if (> nvals register-arg-count)
285               (inst addu temp nargs-tn (fixnumize (- register-arg-count)))
286               (move csp-tn ocfp-tn t)))
287
288         ;; Do the single value case.
289         (do ((i 1 (1+ i))
290              (val (tn-ref-across values) (tn-ref-across val)))
291             ((= i (min nvals register-arg-count)))
292           (move (tn-ref-tn val) null-tn))
293         (when (> nvals register-arg-count)
294           (inst b default-stack-vals)
295           (move ocfp-tn csp-tn t))
296
297         (emit-label regs-defaulted)
298
299         (when (> nvals register-arg-count)
300           ;; If there are stack results, we have to default them
301           ;; and clear the stack.
302           (collect ((defaults))
303             (do ((i register-arg-count (1+ i))
304                  (val (do ((i 0 (1+ i))
305                            (val values (tn-ref-across val)))
306                           ((= i register-arg-count) val))
307                       (tn-ref-across val)))
308                 ((null val))
309
310               (let ((default-lab (gen-label))
311                     (tn (tn-ref-tn val)))
312                 (defaults (cons default-lab tn))
313
314                 (inst blez temp default-lab)
315                 (inst lw move-temp ocfp-tn (* i n-word-bytes))
316                 (inst addu temp temp (fixnumize -1))
317                 (store-stack-tn tn move-temp)))
318
319             (emit-label defaulting-done)
320             (move csp-tn ocfp-tn)
321
322             (let ((defaults (defaults)))
323               (aver defaults)
324               (assemble (*elsewhere*)
325                 (emit-label default-stack-vals)
326                 (trace-table-entry trace-table-fun-prologue)
327                 (do ((remaining defaults (cdr remaining)))
328                     ((null remaining))
329                   (let ((def (car remaining)))
330                     (emit-label (car def))
331                     (when (null (cdr remaining))
332                       (inst b defaulting-done))
333                     (store-stack-tn (cdr def) null-tn)))
334                 (trace-table-entry trace-table-normal)))))
335
336         (when lra-label
337           (inst compute-code-from-lra code-tn code-tn lra-label temp))))
338   (values))
339
340 \f
341 ;;;; Unknown values receiving:
342
343 ;;;    Emit code needed at the return point for an unknown-values call for an
344 ;;; arbitrary number of values.
345 ;;;
346 ;;;    We do the single and non-single cases with no shared code: there doesn't
347 ;;; seem to be any potential overlap, and receiving a single value is more
348 ;;; important efficiency-wise.
349 ;;;
350 ;;;    When there is a single value, we just push it on the stack, returning
351 ;;; the old SP and 1.
352 ;;;
353 ;;;    When there is a variable number of values, we move all of the argument
354 ;;; registers onto the stack, and return Args and Nargs.
355 ;;;
356 ;;;    Args and Nargs are TNs wired to the named locations.  We must
357 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
358 ;;; results Start and Count (also, it's nice to be able to target them).
359 ;;;
360 (defun receive-unknown-values (args nargs start count lra-label temp)
361   (declare (type tn args nargs start count temp))
362   (let ((variable-values (gen-label))
363         (done (gen-label)))
364     (without-scheduling ()
365       (inst b variable-values)
366       (inst nop))
367
368     (when lra-label
369       (inst compute-code-from-lra code-tn code-tn lra-label temp))
370     (inst addu csp-tn csp-tn 4)
371     (storew (first *register-arg-tns*) csp-tn -1)
372     (inst addu start csp-tn -4)
373     (inst li count (fixnumize 1))
374
375     (emit-label done)
376
377     (assemble (*elsewhere*)
378       (trace-table-entry trace-table-fun-prologue)
379       (emit-label variable-values)
380       (when lra-label
381         (inst compute-code-from-lra code-tn code-tn lra-label temp))
382       (do ((arg *register-arg-tns* (rest arg))
383            (i 0 (1+ i)))
384           ((null arg))
385         (storew (first arg) args i))
386       (move start args)
387       (inst b done)
388       (move count nargs t)
389       (trace-table-entry trace-table-normal)))
390   (values))
391
392
393 ;;; VOP that can be inherited by unknown values receivers.  The main thing this
394 ;;; handles is allocation of the result temporaries.
395 ;;;
396 (define-vop (unknown-values-receiver)
397   (:results
398    (start :scs (any-reg))
399    (count :scs (any-reg)))
400   (:temporary (:sc descriptor-reg :offset ocfp-offset
401                    :from :eval :to (:result 0))
402               values-start)
403   (:temporary (:sc any-reg :offset nargs-offset
404                :from :eval :to (:result 1))
405               nvals)
406   (:temporary (:scs (non-descriptor-reg)) temp))
407
408
409 \f
410 ;;;; Local call with unknown values convention return:
411
412 ;;; Non-TR local call for a fixed number of values passed according to the
413 ;;; unknown values convention.
414 ;;;
415 ;;; Args are the argument passing locations, which are specified only to
416 ;;; terminate their lifetimes in the caller.
417 ;;;
418 ;;; Values are the return value locations (wired to the standard passing
419 ;;; locations).
420 ;;;
421 ;;; Save is the save info, which we can ignore since saving has been done.
422 ;;; Return-PC is the TN that the return PC should be passed in.
423 ;;; Target is a continuation pointing to the start of the called function.
424 ;;; Nvals is the number of values received.
425 ;;;
426 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
427 ;;; registers may be tied up by the more operand.  Instead, we use
428 ;;; MAYBE-LOAD-STACK-TN.
429 ;;;
430 (define-vop (call-local)
431   (:args (fp)
432          (nfp)
433          (args :more t))
434   (:results (values :more t))
435   (:save-p t)
436   (:move-args :local-call)
437   (:info arg-locs callee target nvals)
438   (:vop-var vop)
439   (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
440   (:temporary (:scs (non-descriptor-reg)) temp)
441   (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
442   (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
443   (:ignore arg-locs args ocfp)
444   (:generator 5
445     (let ((label (gen-label))
446           (cur-nfp (current-nfp-tn vop)))
447       (when cur-nfp
448         (store-stack-tn nfp-save cur-nfp))
449       (let ((callee-nfp (callee-nfp-tn callee)))
450         (when callee-nfp
451           (maybe-load-stack-tn callee-nfp nfp)))
452       (maybe-load-stack-tn cfp-tn fp)
453       (trace-table-entry trace-table-call-site)
454       (inst compute-lra-from-code
455             (callee-return-pc-tn callee) code-tn label temp)
456       (note-this-location vop :call-site)
457       (inst b target)
458       (inst nop)
459       (trace-table-entry trace-table-normal)
460       (emit-return-pc label)
461       (default-unknown-values vop values nvals move-temp temp label)
462       (when cur-nfp
463         (load-stack-tn cur-nfp nfp-save)))))
464
465
466 ;;; Non-TR local call for a variable number of return values passed according
467 ;;; to the unknown values convention.  The results are the start of the values
468 ;;; glob and the number of values received.
469 ;;;
470 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
471 ;;; registers may be tied up by the more operand.  Instead, we use
472 ;;; MAYBE-LOAD-STACK-TN.
473 ;;;
474 (define-vop (multiple-call-local unknown-values-receiver)
475   (:args (fp)
476          (nfp)
477          (args :more t))
478   (:save-p t)
479   (:move-args :local-call)
480   (:info save callee target)
481   (:ignore args save)
482   (:vop-var vop)
483   (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
484   (:temporary (:scs (non-descriptor-reg)) temp)
485   (:generator 20
486     (let ((label (gen-label))
487           (cur-nfp (current-nfp-tn vop)))
488       (when cur-nfp
489         (store-stack-tn nfp-save cur-nfp))
490       (let ((callee-nfp (callee-nfp-tn callee)))
491         (when callee-nfp
492           (maybe-load-stack-tn callee-nfp nfp)))
493       (maybe-load-stack-tn cfp-tn fp)
494       (trace-table-entry trace-table-call-site)
495       (inst compute-lra-from-code
496             (callee-return-pc-tn callee) code-tn label temp)
497       (note-this-location vop :call-site)
498       (inst b target)
499       (inst nop)
500       (trace-table-entry trace-table-normal)
501       (emit-return-pc label)
502       (note-this-location vop :unknown-return)
503       (receive-unknown-values values-start nvals start count label temp)
504       (when cur-nfp
505         (load-stack-tn cur-nfp nfp-save)))))
506
507 \f
508 ;;;; Local call with known values return:
509
510 ;;; Non-TR local call with known return locations.  Known-value return works
511 ;;; just like argument passing in local call.
512 ;;;
513 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
514 ;;; registers may be tied up by the more operand.  Instead, we use
515 ;;; MAYBE-LOAD-STACK-TN.
516 ;;;
517 (define-vop (known-call-local)
518   (:args (fp)
519          (nfp)
520          (args :more t))
521   (:results (res :more t))
522   (:move-args :local-call)
523   (:save-p t)
524   (:info save callee target)
525   (:ignore args res save)
526   (:vop-var vop)
527   (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
528   (:temporary (:scs (non-descriptor-reg)) temp)
529   (:generator 5
530     (let ((label (gen-label))
531           (cur-nfp (current-nfp-tn vop)))
532       (when cur-nfp
533         (store-stack-tn nfp-save cur-nfp))
534       (let ((callee-nfp (callee-nfp-tn callee)))
535         (when callee-nfp
536           (maybe-load-stack-tn callee-nfp nfp)))
537       (maybe-load-stack-tn cfp-tn fp)
538       (trace-table-entry trace-table-call-site)
539       (inst compute-lra-from-code
540             (callee-return-pc-tn callee) code-tn label temp)
541       (note-this-location vop :call-site)
542       (inst b target)
543       (inst nop)
544       (trace-table-entry trace-table-normal)
545       (emit-return-pc label)
546       (note-this-location vop :known-return)
547       (when cur-nfp
548         (load-stack-tn cur-nfp nfp-save)))))
549
550 ;;; Return from known values call.  We receive the return locations as
551 ;;; arguments to terminate their lifetimes in the returning function.  We
552 ;;; restore FP and CSP and jump to the Return-PC.
553 ;;;
554 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
555 ;;; registers may be tied up by the more operand.  Instead, we use
556 ;;; MAYBE-LOAD-STACK-TN.
557 ;;;
558 (define-vop (known-return)
559   (:args (ocfp :target ocfp-temp)
560          (return-pc :target return-pc-temp)
561          (vals :more t))
562   (:temporary (:sc any-reg :from (:argument 0)) ocfp-temp)
563   (:temporary (:sc descriptor-reg :from (:argument 1))
564               return-pc-temp)
565   (:temporary (:scs (interior-reg)) lip)
566   (:move-args :known-return)
567   (:info val-locs)
568   (:ignore val-locs vals)
569   (:vop-var vop)
570   (:generator 6
571     (trace-table-entry trace-table-fun-epilogue)
572     (maybe-load-stack-tn ocfp-temp ocfp)
573     (maybe-load-stack-tn return-pc-temp return-pc)
574     (move csp-tn cfp-tn)
575     (let ((cur-nfp (current-nfp-tn vop)))
576       (when cur-nfp
577         (inst addu nsp-tn cur-nfp
578               (bytes-needed-for-non-descriptor-stack-frame))))
579     (inst addu lip return-pc-temp (- n-word-bytes other-pointer-lowtag))
580     (inst j lip)
581     (move cfp-tn ocfp-temp t)
582     (trace-table-entry trace-table-normal)))
583
584 \f
585 ;;;; Full call:
586 ;;;
587 ;;;    There is something of a cross-product effect with full calls.  Different
588 ;;; versions are used depending on whether we know the number of arguments or
589 ;;; the name of the called function, and whether we want fixed values, unknown
590 ;;; values, or a tail call.
591 ;;;
592 ;;; In full call, the arguments are passed creating a partial frame on the
593 ;;; stack top and storing stack arguments into that frame.  On entry to the
594 ;;; callee, this partial frame is pointed to by FP.  If there are no stack
595 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
596 ;;; to SP just before the call.
597
598 ;;;    This macro helps in the definition of full call VOPs by avoiding code
599 ;;; replication in defining the cross-product VOPs.
600 ;;;
601 ;;; Name is the name of the VOP to define.
602 ;;;
603 ;;; Named is true if the first argument is a symbol whose global function
604 ;;; definition is to be called.
605 ;;;
606 ;;; Return is either :Fixed, :Unknown or :Tail:
607 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
608 ;;;    the standard passing locations (passed as result operands).
609 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
610 ;;;    result values are specified by the Start and Count as in the
611 ;;;    unknown-values continuation representation.
612 ;;; -- If :Tail, then do a tail-recursive call.  No values are returned.
613 ;;;    The Ocfp and Return-PC are passed as the second and third arguments.
614 ;;;
615 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
616 ;;; fixed argument.  If Variable is false, then the passing locations are
617 ;;; passed as a more arg.  Variable is true if there are a variable number of
618 ;;; arguments passed on the stack.  Variable cannot be specified with :Tail
619 ;;; return.  TR variable argument call is implemented separately.
620 ;;;
621 ;;; In tail call with fixed arguments, the passing locations are passed as a
622 ;;; more arg, but there is no new-FP, since the arguments have been set up in
623 ;;; the current frame.
624 ;;;
625 (defmacro define-full-call (name named return variable)
626   (aver (not (and variable (eq return :tail))))
627   `(define-vop (,name
628                 ,@(when (eq return :unknown)
629                     '(unknown-values-receiver)))
630      (:args
631       ,@(unless (eq return :tail)
632           '((new-fp :scs (any-reg) :to :eval)))
633
634       ,(if named
635            '(name :target name-pass)
636            '(arg-fun :target lexenv))
637
638       ,@(when (eq return :tail)
639           '((ocfp :target ocfp-pass)
640             (return-pc :target return-pc-pass)))
641
642       ,@(unless variable '((args :more t :scs (descriptor-reg)))))
643
644      ,@(when (eq return :fixed)
645          '((:results (values :more t))))
646
647      (:save-p ,(if (eq return :tail) :compute-only t))
648
649      ,@(unless (or (eq return :tail) variable)
650          '((:move-args :full-call)))
651
652      (:vop-var vop)
653      (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
654             ,@(unless variable '(nargs))
655             ,@(when (eq return :fixed) '(nvals))
656             step-instrumenting)
657
658      (:ignore ,@(unless (or variable (eq return :tail)) '(arg-locs))
659               ,@(unless variable '(args))
660               ;; Step instrumentation for full calls not implemented yet.
661               ;; See the PPC backend for an example.
662               step-instrumenting)
663
664      (:temporary (:sc descriptor-reg
665                   :offset ocfp-offset
666                   :from (:argument 1)
667                   ,@(unless (eq return :fixed)
668                       '(:to :eval)))
669                  ocfp-pass)
670
671      (:temporary (:sc descriptor-reg
672                   :offset lra-offset
673                   :from (:argument ,(if (eq return :tail) 2 1))
674                   :to :eval)
675                  return-pc-pass)
676
677      ,@(if named
678          `((:temporary (:sc descriptor-reg :offset fdefn-offset
679                         :from (:argument ,(if (eq return :tail) 0 1))
680                         :to :eval)
681                        name-pass))
682
683          `((:temporary (:sc descriptor-reg :offset lexenv-offset
684                         :from (:argument ,(if (eq return :tail) 0 1))
685                         :to :eval)
686                        lexenv)
687            (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
688                        function)))
689
690      (:temporary (:sc any-reg :offset nargs-offset :to :eval)
691                  nargs-pass)
692
693      ,@(when variable
694          (mapcar #'(lambda (name offset)
695                      `(:temporary (:sc descriptor-reg
696                                    :offset ,offset
697                                    :to :eval)
698                          ,name))
699                  register-arg-names *register-arg-offsets*))
700      ,@(when (eq return :fixed)
701          '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
702
703      ,@(unless (eq return :tail)
704          '((:temporary (:scs (non-descriptor-reg)) temp)
705            (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
706
707      (:temporary (:sc interior-reg :offset lip-offset) entry-point)
708
709      (:generator ,(+ (if named 5 0)
710                      (if variable 19 1)
711                      (if (eq return :tail) 0 10)
712                      15
713                      (if (eq return :unknown) 25 0))
714        (let* ((cur-nfp (current-nfp-tn vop))
715               ,@(unless (eq return :tail)
716                   '((lra-label (gen-label))))
717               (filler
718                (remove nil
719                        (list :load-nargs
720                              ,@(if (eq return :tail)
721                                    '((unless (location= ocfp ocfp-pass)
722                                        :load-ocfp)
723                                      (unless (location= return-pc
724                                                         return-pc-pass)
725                                        :load-return-pc)
726                                      (when cur-nfp
727                                        :frob-nfp))
728                                    '(:comp-lra
729                                      (when cur-nfp
730                                        :frob-nfp)
731                                      :save-fp
732                                      :load-fp))))))
733          (flet ((do-next-filler ()
734                   (let* ((next (pop filler))
735                          (what (if (consp next) (car next) next)))
736                     (ecase what
737                       (:load-nargs
738                        ,@(if variable
739                              `((inst subu nargs-pass csp-tn new-fp)
740                                ,@(let ((index -1))
741                                    (mapcar #'(lambda (name)
742                                                `(inst lw ,name new-fp
743                                                       ,(ash (incf index)
744                                                             word-shift)))
745                                            register-arg-names)))
746                              '((inst li nargs-pass (fixnumize nargs)))))
747                       ,@(if (eq return :tail)
748                             '((:load-ocfp
749                                (sc-case ocfp
750                                  (any-reg
751                                   (move ocfp-pass ocfp t))
752                                  (control-stack
753                                   (inst lw ocfp-pass cfp-tn
754                                         (ash (tn-offset ocfp)
755                                              word-shift)))))
756                               (:load-return-pc
757                                (sc-case return-pc
758                                  (descriptor-reg
759                                   (move return-pc-pass return-pc t))
760                                  (control-stack
761                                   (inst lw return-pc-pass cfp-tn
762                                         (ash (tn-offset return-pc)
763                                              word-shift)))))
764                               (:frob-nfp
765                                (inst addu nsp-tn cur-nfp
766                                      (bytes-needed-for-non-descriptor-stack-frame))))
767                             `((:comp-lra
768                                (inst compute-lra-from-code
769                                      return-pc-pass code-tn lra-label temp))
770                               (:frob-nfp
771                                (store-stack-tn nfp-save cur-nfp))
772                               (:save-fp
773                                (move ocfp-pass cfp-tn t))
774                               (:load-fp
775                                ,(if variable
776                                     '(move cfp-tn new-fp)
777                                     '(if (> nargs register-arg-count)
778                                          (move cfp-tn new-fp)
779                                          (move cfp-tn csp-tn)))
780                                (trace-table-entry trace-table-call-site))))
781                       ((nil)
782                        (inst nop))))))
783
784            ,@(if named
785                  `((sc-case name
786                      (descriptor-reg (move name-pass name))
787                      (control-stack
788                       (inst lw name-pass cfp-tn
789                             (ash (tn-offset name) word-shift))
790                       (do-next-filler))
791                      (constant
792                       (inst lw name-pass code-tn
793                             (- (ash (tn-offset name) word-shift)
794                                other-pointer-lowtag))
795                       (do-next-filler)))
796                    (inst lw entry-point name-pass
797                          (- (ash fdefn-raw-addr-slot word-shift)
798                             other-pointer-lowtag))
799                    (do-next-filler))
800                  `((sc-case arg-fun
801                      (descriptor-reg (move lexenv arg-fun))
802                      (control-stack
803                       (inst lw lexenv cfp-tn
804                             (ash (tn-offset arg-fun) word-shift))
805                       (do-next-filler))
806                      (constant
807                       (inst lw lexenv code-tn
808                             (- (ash (tn-offset arg-fun) word-shift)
809                                other-pointer-lowtag))
810                       (do-next-filler)))
811                    (inst lw function lexenv
812                          (- (ash closure-fun-slot word-shift)
813                             fun-pointer-lowtag))
814                    (do-next-filler)
815                    (inst addu entry-point function
816                          (- (ash simple-fun-code-offset word-shift)
817                             fun-pointer-lowtag))))
818            (loop
819              (if (cdr filler)
820                  (do-next-filler)
821                  (return)))
822
823            (do-next-filler)
824            (note-this-location vop :call-site)
825            (inst j entry-point)
826            (inst nop))
827
828          ,@(ecase return
829              (:fixed
830               '((trace-table-entry trace-table-normal)
831                 (emit-return-pc lra-label)
832                 (default-unknown-values vop values nvals
833                                         move-temp temp lra-label)
834                 (when cur-nfp
835                   (load-stack-tn cur-nfp nfp-save))))
836              (:unknown
837               '((trace-table-entry trace-table-normal)
838                 (emit-return-pc lra-label)
839                 (note-this-location vop :unknown-return)
840                 (receive-unknown-values values-start nvals start count
841                                         lra-label temp)
842                 (when cur-nfp
843                   (load-stack-tn cur-nfp nfp-save))))
844              (:tail))))))
845
846
847 (define-full-call call nil :fixed nil)
848 (define-full-call call-named t :fixed nil)
849 (define-full-call multiple-call nil :unknown nil)
850 (define-full-call multiple-call-named t :unknown nil)
851 (define-full-call tail-call nil :tail nil)
852 (define-full-call tail-call-named t :tail nil)
853
854 (define-full-call call-variable nil :fixed t)
855 (define-full-call multiple-call-variable nil :unknown t)
856
857
858 ;;; Defined separately, since needs special code that BLT's the arguments
859 ;;; down.
860 ;;;
861 (define-vop (tail-call-variable)
862   (:args
863    (args-arg :scs (any-reg) :target args)
864    (function-arg :scs (descriptor-reg) :target lexenv)
865    (ocfp-arg :scs (any-reg) :target ocfp)
866    (lra-arg :scs (descriptor-reg) :target lra))
867
868   (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
869   (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
870   (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) ocfp)
871   (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
872
873   (:vop-var vop)
874
875   (:generator 75
876
877     ;; Move these into the passing locations if they are not already there.
878     (move args args-arg)
879     (move lexenv function-arg)
880     (move ocfp ocfp-arg)
881     (move lra lra-arg)
882
883     ;; Clear the number stack if anything is there and jump to the
884     ;; assembly-routine that does the bliting.
885     (inst j (make-fixup 'tail-call-variable :assembly-routine))
886     (let ((cur-nfp (current-nfp-tn vop)))
887       (if cur-nfp
888         (inst addu nsp-tn cur-nfp
889               (bytes-needed-for-non-descriptor-stack-frame))
890         (inst nop)))))
891
892 \f
893 ;;;; Unknown values return:
894
895 ;;; Return a single value using the unknown-values convention.
896 ;;;
897 (define-vop (return-single)
898   (:args (ocfp :scs (any-reg))
899          (return-pc :scs (descriptor-reg))
900          (value))
901   (:ignore value)
902   (:temporary (:scs (interior-reg)) lip)
903   (:vop-var vop)
904   (:generator 6
905     ;; Clear the number stack.
906     (trace-table-entry trace-table-fun-epilogue)
907     (let ((cur-nfp (current-nfp-tn vop)))
908       (when cur-nfp
909         (inst addu nsp-tn cur-nfp
910               (bytes-needed-for-non-descriptor-stack-frame))))
911     ;; Clear the control stack, and restore the frame pointer.
912     (move csp-tn cfp-tn)
913     (move cfp-tn ocfp)
914     ;; Out of here.
915     (lisp-return return-pc lip :offset 2)
916     (trace-table-entry trace-table-normal)))
917
918
919 ;;; Do unknown-values return of a fixed number of values.  The Values are
920 ;;; required to be set up in the standard passing locations.  Nvals is the
921 ;;; number of values returned.
922 ;;;
923 ;;; If returning a single value, then deallocate the current frame, restore
924 ;;; FP and jump to the single-value entry at Return-PC + 8.
925 ;;;
926 ;;; If returning other than one value, then load the number of values returned,
927 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
928 ;;; When there are stack values, we must initialize the argument pointer to
929 ;;; point to the beginning of the values block (which is the beginning of the
930 ;;; current frame.)
931 ;;;
932 (define-vop (return)
933   (:args (ocfp :scs (any-reg))
934          (return-pc :scs (descriptor-reg) :to (:eval 1))
935          (values :more t))
936   (:ignore values)
937   (:info nvals)
938   (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
939   (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
940   (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
941   (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
942   (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
943   (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
944   (:temporary (:sc any-reg :offset nargs-offset) nargs)
945   (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
946   (:temporary (:scs (interior-reg)) lip)
947   (:vop-var vop)
948   (:generator 6
949     ;; Clear the number stack.
950     (trace-table-entry trace-table-fun-epilogue)
951     (let ((cur-nfp (current-nfp-tn vop)))
952       (when cur-nfp
953         (inst addu nsp-tn cur-nfp
954               (bytes-needed-for-non-descriptor-stack-frame))))
955     (cond ((= nvals 1)
956            ;; Clear the control stack, and restore the frame pointer.
957            (move csp-tn cfp-tn)
958            (move cfp-tn ocfp)
959            ;; Out of here.
960            (lisp-return return-pc lip :offset 2))
961           (t
962            ;; Establish the values pointer and values count.
963            (move val-ptr cfp-tn)
964            (inst li nargs (fixnumize nvals))
965            ;; restore the frame pointer and clear as much of the control
966            ;; stack as possible.
967            (move cfp-tn ocfp)
968            (inst addu csp-tn val-ptr (* nvals n-word-bytes))
969            ;; pre-default any argument register that need it.
970            (when (< nvals register-arg-count)
971              (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
972                (move reg null-tn)))
973            ;; And away we go.
974            (lisp-return return-pc lip)))
975     (trace-table-entry trace-table-normal)))
976
977 ;;; Do unknown-values return of an arbitrary number of values (passed on the
978 ;;; stack.)  We check for the common case of a single return value, and do that
979 ;;; inline using the normal single value return convention.  Otherwise, we
980 ;;; branch off to code that calls an assembly-routine.
981 ;;;
982 (define-vop (return-multiple)
983   (:args (ocfp-arg :scs (any-reg) :target ocfp)
984          (lra-arg :scs (descriptor-reg) :target lra)
985          (vals-arg :scs (any-reg) :target vals)
986          (nvals-arg :scs (any-reg) :target nvals))
987
988   (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) ocfp)
989   (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
990   (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
991   (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
992   (:temporary (:sc descriptor-reg :offset a0-offset) a0)
993   (:temporary (:scs (interior-reg)) lip)
994
995   (:vop-var vop)
996
997   (:generator 13
998     (trace-table-entry trace-table-fun-epilogue)
999     (let ((not-single (gen-label)))
1000       ;; Clear the number stack.
1001       (let ((cur-nfp (current-nfp-tn vop)))
1002         (when cur-nfp
1003           (inst addu nsp-tn cur-nfp
1004                 (bytes-needed-for-non-descriptor-stack-frame))))
1005
1006       ;; Check for the single case.
1007       (inst li a0 (fixnumize 1))
1008       (inst bne nvals-arg a0 not-single)
1009       (inst lw a0 vals-arg)
1010
1011       ;; Return with one value.
1012       (move csp-tn cfp-tn)
1013       (move cfp-tn ocfp-arg)
1014       (lisp-return lra-arg lip :offset 2)
1015
1016       ;; Nope, not the single case.
1017       (emit-label not-single)
1018       (move ocfp ocfp-arg)
1019       (move lra lra-arg)
1020       (move vals vals-arg)
1021
1022       (inst j (make-fixup 'return-multiple :assembly-routine))
1023       (move nvals nvals-arg t))
1024     (trace-table-entry trace-table-normal)))
1025
1026
1027 \f
1028 ;;;; XEP hackery:
1029
1030
1031 ;;; We don't need to do anything special for regular functions.
1032 ;;;
1033 (define-vop (setup-environment)
1034   (:info label)
1035   (:ignore label)
1036   (:generator 0
1037     ;; Don't bother doing anything.
1038     ))
1039
1040 ;;; Get the lexical environment from its passing location.
1041 ;;;
1042 (define-vop (setup-closure-environment)
1043   (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1044                :to (:result 0))
1045               lexenv)
1046   (:results (closure :scs (descriptor-reg)))
1047   (:info label)
1048   (:ignore label)
1049   (:generator 6
1050     ;; Get result.
1051     (move closure lexenv)))
1052
1053 ;;; Copy a more arg from the argument area to the end of the current frame.
1054 ;;; Fixed is the number of non-more arguments.
1055 ;;;
1056 (define-vop (copy-more-arg)
1057   (:temporary (:sc any-reg :offset nl0-offset) result)
1058   (:temporary (:sc any-reg :offset nl1-offset) count)
1059   (:temporary (:sc any-reg :offset nl2-offset) src)
1060   (:temporary (:sc any-reg :offset nl3-offset) dst)
1061   (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1062   (:info fixed)
1063   (:generator 20
1064     (let ((loop (gen-label))
1065           (do-regs (gen-label))
1066           (done (gen-label)))
1067       (when (< fixed register-arg-count)
1068         ;; Save a pointer to the results so we can fill in register args.
1069         ;; We don't need this if there are more fixed args than reg args.
1070         (move result csp-tn))
1071       ;; Allocate the space on the stack.
1072       (cond ((zerop fixed)
1073              (inst beq nargs-tn done)
1074              (inst addu csp-tn csp-tn nargs-tn))
1075             (t
1076              (inst addu count nargs-tn (fixnumize (- fixed)))
1077              (inst blez count done)
1078              (inst nop)
1079              (inst addu csp-tn csp-tn count)))
1080       (when (< fixed register-arg-count)
1081         ;; We must stop when we run out of stack args, not when we run out of
1082         ;; more args.
1083         (inst addu count nargs-tn (fixnumize (- register-arg-count))))
1084       ;; Everything of interest in registers.
1085       (inst blez count do-regs)
1086       ;; Initialize dst to be end of stack.
1087       (move dst csp-tn t)
1088       ;; Initialize src to be end of args.
1089       (inst addu src cfp-tn nargs-tn)
1090
1091       (emit-label loop)
1092       ;; *--dst = *--src, --count
1093       (inst addu src src (- n-word-bytes))
1094       (inst addu count count (fixnumize -1))
1095       (loadw temp src)
1096       (inst addu dst dst (- n-word-bytes))
1097       (inst bgtz count loop)
1098       (storew temp dst)
1099
1100       (emit-label do-regs)
1101       (when (< fixed register-arg-count)
1102         ;; Now we have to deposit any more args that showed up in registers.
1103         ;; We know there is at least one more arg, otherwise we would have
1104         ;; branched to done up at the top.
1105         (inst subu count nargs-tn (fixnumize (1+ fixed)))
1106         (do ((i fixed (1+ i)))
1107             ((>= i register-arg-count))
1108           ;; Is this the last one?
1109           (inst beq count done)
1110           ;; Store it relative to the pointer saved at the start.
1111           (storew (nth i *register-arg-tns*) result (- i fixed))
1112           ;; Decrement count.
1113           (inst subu count (fixnumize 1))))
1114       (emit-label done))))
1115
1116
1117 ;;; More args are stored consecutively on the stack, starting
1118 ;;; immediately at the context pointer.  The context pointer is not
1119 ;;; typed, so the lowtag is 0.
1120 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1121
1122 ;;; Turn more arg (context, count) into a list.
1123 (defoptimizer (%listify-rest-args stack-allocate-result) ((&rest args))
1124   t)
1125
1126 (define-vop (listify-rest-args)
1127   (:args (context-arg :target context :scs (descriptor-reg))
1128          (count-arg :target count :scs (any-reg)))
1129   (:arg-types * tagged-num)
1130   (:temporary (:scs (any-reg) :from (:argument 0)) context)
1131   (:temporary (:scs (any-reg) :from (:argument 1)) count)
1132   (:temporary (:scs (descriptor-reg) :from :eval) temp dst)
1133   (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
1134   (:results (result :scs (descriptor-reg)))
1135   (:translate %listify-rest-args)
1136   (:policy :safe)
1137   (:node-var node)
1138   (:generator 20
1139     (let* ((enter (gen-label))
1140            (loop (gen-label))
1141            (done (gen-label))
1142            (dx-p (node-stack-allocate-p node))
1143            (alloc-area-tn (if dx-p csp-tn alloc-tn)))
1144       (move context context-arg)
1145       (move count count-arg)
1146       ;; Check to see if there are any arguments.
1147       (inst beq count zero-tn done)
1148       (move result null-tn t)
1149
1150       ;; We need to do this atomically.
1151       (pseudo-atomic (pa-flag)
1152         (when dx-p
1153           (align-csp temp))
1154         ;; Allocate a cons (2 words) for each item.
1155         (inst srl result alloc-area-tn n-lowtag-bits)
1156         (inst sll result n-lowtag-bits)
1157         (inst or result list-pointer-lowtag)
1158         (move dst result)
1159         (inst sll temp count 1)
1160         (inst b enter)
1161         (inst addu alloc-area-tn temp)
1162
1163         ;; Store the current cons in the cdr of the previous cons.
1164         (emit-label loop)
1165         (inst addu dst dst (* 2 n-word-bytes))
1166         (storew dst dst -1 list-pointer-lowtag)
1167
1168         (emit-label enter)
1169         ;; Grab one value.
1170         (loadw temp context)
1171         (inst addu context n-word-bytes)
1172
1173         ;; Dec count, and if != zero, go back for more.
1174         (inst addu count count (fixnumize -1))
1175         (inst bne count zero-tn loop)
1176
1177         ;; Store the value in the car (in delay slot)
1178         (storew temp dst 0 list-pointer-lowtag)
1179
1180         ;; NIL out the last cons.
1181         (storew null-tn dst 1 list-pointer-lowtag))
1182       (emit-label done))))
1183
1184 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1185 ;;; Supplied is the total number of arguments supplied (originally passed in
1186 ;;; NARGS.)  Fixed is the number of non-rest arguments.
1187 ;;;
1188 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1189 ;;; time the environment is in a pretty brain-damaged state, preventing this
1190 ;;; info from being returned as values.  What we do is compute
1191 ;;; supplied - fixed, and return a pointer that many words below the current
1192 ;;; stack top.
1193 ;;;
1194 (define-vop (more-arg-context)
1195   (:policy :fast-safe)
1196   (:translate sb!c::%more-arg-context)
1197   (:args (supplied :scs (any-reg)))
1198   (:arg-types tagged-num (:constant fixnum))
1199   (:info fixed)
1200   (:results (context :scs (descriptor-reg))
1201             (count :scs (any-reg)))
1202   (:result-types t tagged-num)
1203   (:note "more-arg-context")
1204   (:generator 5
1205     (inst addu count supplied (fixnumize (- fixed)))
1206     (inst subu context csp-tn count)))
1207
1208
1209 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1210 ;;;
1211 (define-vop (verify-arg-count)
1212   (:policy :fast-safe)
1213   (:translate sb!c::%verify-arg-count)
1214   (:args (nargs :scs (any-reg)))
1215   (:arg-types positive-fixnum (:constant t))
1216   (:temporary (:scs (any-reg) :type fixnum) temp)
1217   (:info count)
1218   (:vop-var vop)
1219   (:save-p :compute-only)
1220   (:generator 3
1221     (let ((err-lab
1222            (generate-error-code vop invalid-arg-count-error nargs)))
1223       (cond ((zerop count)
1224              (inst bne nargs zero-tn err-lab)
1225              (inst nop))
1226             (t
1227              (inst li temp (fixnumize count))
1228              (inst bne nargs temp err-lab)
1229              (inst nop))))))
1230
1231 ;;; Various other error signalers.
1232 ;;;
1233 (macrolet ((frob (name error translate &rest args)
1234              `(define-vop (,name)
1235                 ,@(when translate
1236                     `((:policy :fast-safe)
1237                       (:translate ,translate)))
1238                 (:args ,@(mapcar #'(lambda (arg)
1239                                      `(,arg :scs (any-reg descriptor-reg)))
1240                                  args))
1241                 (:vop-var vop)
1242                 (:save-p :compute-only)
1243                 (:generator 1000
1244                   (error-call vop ,error ,@args)))))
1245   (frob arg-count-error invalid-arg-count-error
1246     sb!c::%arg-count-error nargs)
1247   (frob type-check-error object-not-type-error sb!c::%type-check-error
1248     object type)
1249   (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1250     object layout)
1251   (frob odd-key-args-error odd-key-args-error
1252     sb!c::%odd-key-args-error)
1253   (frob unknown-key-arg-error unknown-key-arg-error
1254     sb!c::%unknown-key-arg-error key)
1255   (frob nil-fun-returned-error nil-fun-returned-error nil fun))
1256
1257 ;;; Single-stepping
1258
1259 (define-vop (step-instrument-before-vop)
1260   (:policy :fast-safe)
1261   (:vop-var vop)
1262   (:generator 3
1263     ;; Stub! See the PPC backend for an example.
1264     (note-this-location vop :step-before-vop)))