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