Add missing trace-table-fun-prologue.
[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 simple-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-lip 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 ;;;     callee 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 csp 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           (inst 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 t)))
286
287         ;; Do the single value case.
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 t))
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               (aver defaults)
323               (assemble (*elsewhere*)
324                 (emit-label default-stack-vals)
325                 (trace-table-entry trace-table-fun-prologue)
326                 (do ((remaining defaults (cdr remaining)))
327                     ((null remaining))
328                   (let ((def (car remaining)))
329                     (emit-label (car def))
330                     (when (null (cdr remaining))
331                       (inst b defaulting-done))
332                     (store-stack-tn (cdr def) null-tn)))
333                 (trace-table-entry trace-table-normal)))))
334
335         (when lra-label
336           (inst compute-code-from-lra code-tn code-tn lra-label temp))))
337   (values))
338
339 \f
340 ;;;; Unknown values receiving:
341
342 ;;;    Emit code needed at the return point for an unknown-values call for an
343 ;;; arbitrary number of values.
344 ;;;
345 ;;;    We do the single and non-single cases with no shared code: there doesn't
346 ;;; seem to be any potential overlap, and receiving a single value is more
347 ;;; important efficiency-wise.
348 ;;;
349 ;;;    When there is a single value, we just push it on the stack, returning
350 ;;; the old SP and 1.
351 ;;;
352 ;;;    When there is a variable number of values, we move all of the argument
353 ;;; registers onto the stack, and return Args and Nargs.
354 ;;;
355 ;;;    Args and Nargs are TNs wired to the named locations.  We must
356 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
357 ;;; results Start and Count (also, it's nice to be able to target them).
358 ;;;
359 (defun receive-unknown-values (args nargs start count lra-label temp)
360   (declare (type tn args nargs start count temp))
361   (let ((variable-values (gen-label))
362         (done (gen-label)))
363     (without-scheduling ()
364       (inst b variable-values)
365       (inst nop))
366
367     (when lra-label
368       (inst compute-code-from-lra code-tn code-tn lra-label temp))
369     (inst addu csp-tn csp-tn 4)
370     (storew (first *register-arg-tns*) csp-tn -1)
371     (inst addu start csp-tn -4)
372     (inst li count (fixnumize 1))
373
374     (emit-label done)
375
376     (assemble (*elsewhere*)
377       (trace-table-entry trace-table-fun-prologue)
378       (emit-label variable-values)
379       (when lra-label
380         (inst compute-code-from-lra code-tn code-tn lra-label temp))
381       (do ((arg *register-arg-tns* (rest arg))
382            (i 0 (1+ i)))
383           ((null arg))
384         (storew (first arg) args i))
385       (move start args)
386       (inst b done)
387       (move count nargs t)
388       (trace-table-entry trace-table-normal)))
389   (values))
390
391
392 ;;; VOP that can be inherited by unknown values receivers.  The main thing this
393 ;;; handles is allocation of the result temporaries.
394 ;;;
395 (define-vop (unknown-values-receiver)
396   (:results
397    (start :scs (any-reg))
398    (count :scs (any-reg)))
399   (:temporary (:sc descriptor-reg :offset ocfp-offset
400                    :from :eval :to (:result 0))
401               values-start)
402   (:temporary (:sc any-reg :offset nargs-offset
403                :from :eval :to (:result 1))
404               nvals)
405   (:temporary (:scs (non-descriptor-reg)) temp))
406
407
408 \f
409 ;;;; Local call with unknown values convention return:
410
411 ;;; Non-TR local call for a fixed number of values passed according to the
412 ;;; unknown values convention.
413 ;;;
414 ;;; Args are the argument passing locations, which are specified only to
415 ;;; terminate their lifetimes in the caller.
416 ;;;
417 ;;; Values are the return value locations (wired to the standard passing
418 ;;; locations).
419 ;;;
420 ;;; Save is the save info, which we can ignore since saving has been done.
421 ;;; Return-PC is the TN that the return PC should be passed in.
422 ;;; Target is a continuation pointing to the start of the called function.
423 ;;; Nvals is the number of values received.
424 ;;;
425 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
426 ;;; registers may be tied up by the more operand.  Instead, we use
427 ;;; MAYBE-LOAD-STACK-TN.
428 ;;;
429 (define-vop (call-local)
430   (:args (fp)
431          (nfp)
432          (args :more t))
433   (:results (values :more t))
434   (:save-p t)
435   (:move-args :local-call)
436   (:info arg-locs callee target nvals)
437   (:vop-var vop)
438   (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
439   (:temporary (:scs (non-descriptor-reg)) temp)
440   (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
441   (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
442   (:ignore arg-locs args ocfp)
443   (:generator 5
444     (let ((label (gen-label))
445           (cur-nfp (current-nfp-tn vop)))
446       (when cur-nfp
447         (store-stack-tn nfp-save cur-nfp))
448       (let ((callee-nfp (callee-nfp-tn callee)))
449         (when callee-nfp
450           (maybe-load-stack-tn callee-nfp nfp)))
451       (maybe-load-stack-tn cfp-tn fp)
452       (trace-table-entry trace-table-call-site)
453       (inst compute-lra-from-code
454             (callee-return-pc-tn callee) code-tn label temp)
455       (note-this-location vop :call-site)
456       (inst b target)
457       (inst nop)
458       (trace-table-entry trace-table-normal)
459       (emit-return-pc label)
460       (default-unknown-values vop values nvals move-temp temp label)
461       (when cur-nfp
462         (load-stack-tn cur-nfp nfp-save)))))
463
464
465 ;;; Non-TR local call for a variable number of return values passed according
466 ;;; to the unknown values convention.  The results are the start of the values
467 ;;; glob and the number of values received.
468 ;;;
469 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
470 ;;; registers may be tied up by the more operand.  Instead, we use
471 ;;; MAYBE-LOAD-STACK-TN.
472 ;;;
473 (define-vop (multiple-call-local unknown-values-receiver)
474   (:args (fp)
475          (nfp)
476          (args :more t))
477   (:save-p t)
478   (:move-args :local-call)
479   (:info save callee target)
480   (:ignore args save)
481   (:vop-var vop)
482   (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
483   (:generator 20
484     (let ((label (gen-label))
485           (cur-nfp (current-nfp-tn vop)))
486       (when cur-nfp
487         (store-stack-tn nfp-save cur-nfp))
488       (let ((callee-nfp (callee-nfp-tn callee)))
489         (when callee-nfp
490           (maybe-load-stack-tn callee-nfp nfp)))
491       (maybe-load-stack-tn cfp-tn fp)
492       (trace-table-entry trace-table-call-site)
493       (inst compute-lra-from-code
494             (callee-return-pc-tn callee) code-tn label temp)
495       (note-this-location vop :call-site)
496       (inst b target)
497       (inst nop)
498       (trace-table-entry trace-table-normal)
499       (emit-return-pc label)
500       (note-this-location vop :unknown-return)
501       (receive-unknown-values values-start nvals start count label temp)
502       (when cur-nfp
503         (load-stack-tn cur-nfp nfp-save)))))
504
505 \f
506 ;;;; Local call with known values return:
507
508 ;;; Non-TR local call with known return locations.  Known-value return works
509 ;;; just like argument passing in local call.
510 ;;;
511 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
512 ;;; registers may be tied up by the more operand.  Instead, we use
513 ;;; MAYBE-LOAD-STACK-TN.
514 ;;;
515 (define-vop (known-call-local)
516   (:args (fp)
517          (nfp)
518          (args :more t))
519   (:results (res :more t))
520   (:move-args :local-call)
521   (:save-p t)
522   (:info save callee target)
523   (:ignore args res save)
524   (:vop-var vop)
525   (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
526   (:temporary (:scs (non-descriptor-reg)) temp)
527   (:generator 5
528     (let ((label (gen-label))
529           (cur-nfp (current-nfp-tn vop)))
530       (when cur-nfp
531         (store-stack-tn nfp-save cur-nfp))
532       (let ((callee-nfp (callee-nfp-tn callee)))
533         (when callee-nfp
534           (maybe-load-stack-tn callee-nfp nfp)))
535       (maybe-load-stack-tn cfp-tn fp)
536       (trace-table-entry trace-table-call-site)
537       (inst compute-lra-from-code
538             (callee-return-pc-tn callee) code-tn label temp)
539       (note-this-location vop :call-site)
540       (inst b target)
541       (inst nop)
542       (trace-table-entry trace-table-normal)
543       (emit-return-pc label)
544       (note-this-location vop :known-return)
545       (when cur-nfp
546         (load-stack-tn cur-nfp nfp-save)))))
547
548 ;;; Return from known values call.  We receive the return locations as
549 ;;; arguments to terminate their lifetimes in the returning function.  We
550 ;;; restore FP and CSP and jump to the Return-PC.
551 ;;;
552 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
553 ;;; registers may be tied up by the more operand.  Instead, we use
554 ;;; MAYBE-LOAD-STACK-TN.
555 ;;;
556 (define-vop (known-return)
557   (:args (ocfp :target ocfp-temp)
558          (return-pc :target return-pc-temp)
559          (vals :more t))
560   (:temporary (:sc any-reg :from (:argument 0)) ocfp-temp)
561   (:temporary (:sc descriptor-reg :from (:argument 1))
562               return-pc-temp)
563   (:temporary (:scs (interior-reg)) lip)
564   (:move-args :known-return)
565   (:info val-locs)
566   (:ignore val-locs vals)
567   (:vop-var vop)
568   (:generator 6
569     (trace-table-entry trace-table-fun-epilogue)
570     (maybe-load-stack-tn ocfp-temp ocfp)
571     (maybe-load-stack-tn return-pc-temp return-pc)
572     (move csp-tn cfp-tn)
573     (let ((cur-nfp (current-nfp-tn vop)))
574       (when cur-nfp
575         (inst addu nsp-tn cur-nfp
576               (bytes-needed-for-non-descriptor-stack-frame))))
577     (inst addu lip return-pc-temp (- n-word-bytes other-pointer-lowtag))
578     (inst j lip)
579     (move cfp-tn ocfp-temp t)
580     (trace-table-entry trace-table-normal)))
581
582 \f
583 ;;;; Full call:
584 ;;;
585 ;;;    There is something of a cross-product effect with full calls.  Different
586 ;;; versions are used depending on whether we know the number of arguments or
587 ;;; the name of the called function, and whether we want fixed values, unknown
588 ;;; values, or a tail call.
589 ;;;
590 ;;; In full call, the arguments are passed creating a partial frame on the
591 ;;; stack top and storing stack arguments into that frame.  On entry to the
592 ;;; callee, this partial frame is pointed to by FP.  If there are no stack
593 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
594 ;;; to SP just before the call.
595
596 ;;;    This macro helps in the definition of full call VOPs by avoiding code
597 ;;; replication in defining the cross-product VOPs.
598 ;;;
599 ;;; Name is the name of the VOP to define.
600 ;;;
601 ;;; Named is true if the first argument is a symbol whose global function
602 ;;; definition is to be called.
603 ;;;
604 ;;; Return is either :Fixed, :Unknown or :Tail:
605 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
606 ;;;    the standard passing locations (passed as result operands).
607 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
608 ;;;    result values are specified by the Start and Count as in the
609 ;;;    unknown-values continuation representation.
610 ;;; -- If :Tail, then do a tail-recursive call.  No values are returned.
611 ;;;    The Ocfp and Return-PC are passed as the second and third arguments.
612 ;;;
613 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
614 ;;; fixed argument.  If Variable is false, then the passing locations are
615 ;;; passed as a more arg.  Variable is true if there are a variable number of
616 ;;; arguments passed on the stack.  Variable cannot be specified with :Tail
617 ;;; return.  TR variable argument call is implemented separately.
618 ;;;
619 ;;; In tail call with fixed arguments, the passing locations are passed as a
620 ;;; more arg, but there is no new-FP, since the arguments have been set up in
621 ;;; the current frame.
622 ;;;
623 (defmacro define-full-call (name named return variable)
624   (aver (not (and variable (eq return :tail))))
625   `(define-vop (,name
626                 ,@(when (eq return :unknown)
627                     '(unknown-values-receiver)))
628      (:args
629       ,@(unless (eq return :tail)
630           '((new-fp :scs (any-reg) :to :eval)))
631
632       ,(if named
633            '(name :target name-pass)
634            '(arg-fun :target lexenv))
635
636       ,@(when (eq return :tail)
637           '((ocfp :target ocfp-pass)
638             (return-pc :target return-pc-pass)))
639
640       ,@(unless variable '((args :more t :scs (descriptor-reg)))))
641
642      ,@(when (eq return :fixed)
643          '((:results (values :more t))))
644
645      (:save-p ,(if (eq return :tail) :compute-only t))
646
647      ,@(unless (or (eq return :tail) variable)
648          '((:move-args :full-call)))
649
650      (:vop-var vop)
651      (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
652             ,@(unless variable '(nargs))
653             ,@(when (eq return :fixed) '(nvals)))
654
655      (:ignore ,@(unless (or variable (eq return :tail)) '(arg-locs))
656               ,@(unless variable '(args)))
657
658      (:temporary (:sc descriptor-reg
659                   :offset ocfp-offset
660                   :from (:argument 1)
661                   ,@(unless (eq return :fixed)
662                       '(:to :eval)))
663                  ocfp-pass)
664
665      (:temporary (:sc descriptor-reg
666                   :offset lra-offset
667                   :from (:argument ,(if (eq return :tail) 2 1))
668                   :to :eval)
669                  return-pc-pass)
670
671      ,@(if named
672          `((:temporary (:sc descriptor-reg :offset fdefn-offset
673                         :from (:argument ,(if (eq return :tail) 0 1))
674                         :to :eval)
675                        name-pass))
676
677          `((:temporary (:sc descriptor-reg :offset lexenv-offset
678                         :from (:argument ,(if (eq return :tail) 0 1))
679                         :to :eval)
680                        lexenv)
681            (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
682                        function)))
683
684      (:temporary (:sc any-reg :offset nargs-offset :to :eval)
685                  nargs-pass)
686
687      ,@(when variable
688          (mapcar #'(lambda (name offset)
689                      `(:temporary (:sc descriptor-reg
690                                    :offset ,offset
691                                    :to :eval)
692                          ,name))
693                  register-arg-names *register-arg-offsets*))
694      ,@(when (eq return :fixed)
695          '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
696
697      ,@(unless (eq return :tail)
698          '((:temporary (:scs (non-descriptor-reg)) temp)
699            (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
700
701      (:temporary (:sc interior-reg :offset lip-offset) entry-point)
702
703      (:generator ,(+ (if named 5 0)
704                      (if variable 19 1)
705                      (if (eq return :tail) 0 10)
706                      15
707                      (if (eq return :unknown) 25 0))
708        (let* ((cur-nfp (current-nfp-tn vop))
709               ,@(unless (eq return :tail)
710                   '((lra-label (gen-label))))
711               (filler
712                (remove nil
713                        (list :load-nargs
714                              ,@(if (eq return :tail)
715                                    '((unless (location= ocfp ocfp-pass)
716                                        :load-ocfp)
717                                      (unless (location= return-pc
718                                                         return-pc-pass)
719                                        :load-return-pc)
720                                      (when cur-nfp
721                                        :frob-nfp))
722                                    '(:comp-lra
723                                      (when cur-nfp
724                                        :frob-nfp)
725                                      :save-fp
726                                      :load-fp))))))
727          (flet ((do-next-filler ()
728                   (let* ((next (pop filler))
729                          (what (if (consp next) (car next) next)))
730                     (ecase what
731                       (:load-nargs
732                        ,@(if variable
733                              `((inst subu nargs-pass csp-tn new-fp)
734                                ,@(let ((index -1))
735                                    (mapcar #'(lambda (name)
736                                                `(inst lw ,name new-fp
737                                                       ,(ash (incf index)
738                                                             word-shift)))
739                                            register-arg-names)))
740                              '((inst li nargs-pass (fixnumize nargs)))))
741                       ,@(if (eq return :tail)
742                             '((:load-ocfp
743                                (sc-case ocfp
744                                  (any-reg
745                                   (move ocfp-pass ocfp t))
746                                  (control-stack
747                                   (inst lw ocfp-pass cfp-tn
748                                         (ash (tn-offset ocfp)
749                                              word-shift)))))
750                               (:load-return-pc
751                                (sc-case return-pc
752                                  (descriptor-reg
753                                   (move return-pc-pass return-pc t))
754                                  (control-stack
755                                   (inst lw return-pc-pass cfp-tn
756                                         (ash (tn-offset return-pc)
757                                              word-shift)))))
758                               (:frob-nfp
759                                (inst addu nsp-tn cur-nfp
760                                      (bytes-needed-for-non-descriptor-stack-frame))))
761                             `((:comp-lra
762                                (inst compute-lra-from-code
763                                      return-pc-pass code-tn lra-label temp))
764                               (:frob-nfp
765                                (store-stack-tn nfp-save cur-nfp))
766                               (:save-fp
767                                (move ocfp-pass cfp-tn t))
768                               (:load-fp
769                                ,(if variable
770                                     '(move cfp-tn new-fp)
771                                     '(if (> nargs register-arg-count)
772                                          (move cfp-tn new-fp)
773                                          (move cfp-tn csp-tn)))
774                                (trace-table-entry trace-table-call-site))))
775                       ((nil)
776                        (inst nop))))))
777
778            ,@(if named
779                  `((sc-case name
780                      (descriptor-reg (move name-pass name))
781                      (control-stack
782                       (inst lw name-pass cfp-tn
783                             (ash (tn-offset name) word-shift))
784                       (do-next-filler))
785                      (constant
786                       (inst lw name-pass code-tn
787                             (- (ash (tn-offset name) word-shift)
788                                other-pointer-lowtag))
789                       (do-next-filler)))
790                    (inst lw entry-point name-pass
791                          (- (ash fdefn-raw-addr-slot word-shift)
792                             other-pointer-lowtag))
793                    (do-next-filler))
794                  `((sc-case arg-fun
795                      (descriptor-reg (move lexenv arg-fun))
796                      (control-stack
797                       (inst lw lexenv cfp-tn
798                             (ash (tn-offset arg-fun) word-shift))
799                       (do-next-filler))
800                      (constant
801                       (inst lw lexenv code-tn
802                             (- (ash (tn-offset arg-fun) word-shift)
803                                other-pointer-lowtag))
804                       (do-next-filler)))
805                    (inst lw function lexenv
806                          (- (ash closure-fun-slot word-shift)
807                             fun-pointer-lowtag))
808                    (do-next-filler)
809                    (inst addu entry-point function
810                          (- (ash simple-fun-code-offset word-shift)
811                             fun-pointer-lowtag))))
812            (loop
813              (if (cdr filler)
814                  (do-next-filler)
815                  (return)))
816
817            (do-next-filler)
818            (note-this-location vop :call-site)
819            (inst j entry-point)
820            (inst nop))
821
822          ,@(ecase return
823              (:fixed
824               '((trace-table-entry trace-table-normal)
825                 (emit-return-pc lra-label)
826                 (default-unknown-values vop values nvals
827                                         move-temp temp lra-label)
828                 (when cur-nfp
829                   (load-stack-tn cur-nfp nfp-save))))
830              (:unknown
831               '((trace-table-entry trace-table-normal)
832                 (emit-return-pc lra-label)
833                 (note-this-location vop :unknown-return)
834                 (receive-unknown-values values-start nvals start count
835                                         lra-label temp)
836                 (when cur-nfp
837                   (load-stack-tn cur-nfp nfp-save))))
838              (:tail))))))
839
840
841 (define-full-call call nil :fixed nil)
842 (define-full-call call-named t :fixed nil)
843 (define-full-call multiple-call nil :unknown nil)
844 (define-full-call multiple-call-named t :unknown nil)
845 (define-full-call tail-call nil :tail nil)
846 (define-full-call tail-call-named t :tail nil)
847
848 (define-full-call call-variable nil :fixed t)
849 (define-full-call multiple-call-variable nil :unknown t)
850
851
852 ;;; Defined separately, since needs special code that BLT's the arguments
853 ;;; down.
854 ;;;
855 (define-vop (tail-call-variable)
856   (:args
857    (args-arg :scs (any-reg) :target args)
858    (function-arg :scs (descriptor-reg) :target lexenv)
859    (ocfp-arg :scs (any-reg) :target ocfp)
860    (lra-arg :scs (descriptor-reg) :target lra))
861
862   (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
863   (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
864   (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) ocfp)
865   (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
866
867   (:vop-var vop)
868
869   (:generator 75
870
871     ;; Move these into the passing locations if they are not already there.
872     (move args args-arg)
873     (move lexenv function-arg)
874     (move ocfp ocfp-arg)
875     (move lra lra-arg)
876
877     ;; Clear the number stack if anything is there and jump to the
878     ;; assembly-routine that does the bliting.
879     (inst j (make-fixup 'tail-call-variable :assembly-routine))
880     (let ((cur-nfp (current-nfp-tn vop)))
881       (if cur-nfp
882         (inst addu nsp-tn cur-nfp
883               (bytes-needed-for-non-descriptor-stack-frame))
884         (inst nop)))))
885
886 \f
887 ;;;; Unknown values return:
888
889 ;;; Return a single value using the unknown-values convention.
890 ;;;
891 (define-vop (return-single)
892   (:args (ocfp :scs (any-reg))
893          (return-pc :scs (descriptor-reg))
894          (value))
895   (:ignore value)
896   (:temporary (:scs (interior-reg)) lip)
897   (:vop-var vop)
898   (:generator 6
899     ;; Clear the number stack.
900     (trace-table-entry trace-table-fun-epilogue)
901     (let ((cur-nfp (current-nfp-tn vop)))
902       (when cur-nfp
903         (inst addu nsp-tn cur-nfp
904               (bytes-needed-for-non-descriptor-stack-frame))))
905     ;; Clear the control stack, and restore the frame pointer.
906     (move csp-tn cfp-tn)
907     (move cfp-tn ocfp)
908     ;; Out of here.
909     (lisp-return return-pc lip :offset 2)
910     (trace-table-entry trace-table-normal)))
911
912
913 ;;; Do unknown-values return of a fixed number of values.  The Values are
914 ;;; required to be set up in the standard passing locations.  Nvals is the
915 ;;; number of values returned.
916 ;;;
917 ;;; If returning a single value, then deallocate the current frame, restore
918 ;;; FP and jump to the single-value entry at Return-PC + 8.
919 ;;;
920 ;;; If returning other than one value, then load the number of values returned,
921 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
922 ;;; When there are stack values, we must initialize the argument pointer to
923 ;;; point to the beginning of the values block (which is the beginning of the
924 ;;; current frame.)
925 ;;;
926 (define-vop (return)
927   (:args (ocfp :scs (any-reg))
928          (return-pc :scs (descriptor-reg) :to (:eval 1))
929          (values :more t))
930   (:ignore values)
931   (:info nvals)
932   (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
933   (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
934   (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
935   (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
936   (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
937   (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
938   (:temporary (:sc any-reg :offset nargs-offset) nargs)
939   (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
940   (:temporary (:scs (interior-reg)) lip)
941   (:vop-var vop)
942   (:generator 6
943     ;; Clear the number stack.
944     (trace-table-entry trace-table-fun-epilogue)
945     (let ((cur-nfp (current-nfp-tn vop)))
946       (when cur-nfp
947         (inst addu nsp-tn cur-nfp
948               (bytes-needed-for-non-descriptor-stack-frame))))
949     ;; Establish the values pointer and values count.
950     (move val-ptr cfp-tn)
951     (inst li nargs (fixnumize nvals))
952     ;; restore the frame pointer and clear as much of the control
953     ;; stack as possible.
954     (move cfp-tn ocfp)
955     (inst addu csp-tn val-ptr (* nvals n-word-bytes))
956     ;; pre-default any argument register that need it.
957     (when (< nvals register-arg-count)
958       (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
959         (move reg null-tn)))
960     ;; And away we go.
961     (lisp-return return-pc lip)
962     (trace-table-entry trace-table-normal)))
963
964 ;;; Do unknown-values return of an arbitrary number of values (passed on the
965 ;;; stack.)  We check for the common case of a single return value, and do that
966 ;;; inline using the normal single value return convention.  Otherwise, we
967 ;;; branch off to code that calls an assembly-routine.
968 ;;;
969 (define-vop (return-multiple)
970   (:args (ocfp-arg :scs (any-reg) :target ocfp)
971          (lra-arg :scs (descriptor-reg) :target lra)
972          (vals-arg :scs (any-reg) :target vals)
973          (nvals-arg :scs (any-reg) :target nvals))
974
975   (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) ocfp)
976   (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
977   (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
978   (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
979   (:temporary (:sc descriptor-reg :offset a0-offset) a0)
980   (:temporary (:scs (interior-reg)) lip)
981
982   (:vop-var vop)
983
984   (:generator 13
985     (trace-table-entry trace-table-fun-epilogue)
986     (let ((not-single (gen-label)))
987       ;; Clear the number stack.
988       (let ((cur-nfp (current-nfp-tn vop)))
989         (when cur-nfp
990           (inst addu nsp-tn cur-nfp
991                 (bytes-needed-for-non-descriptor-stack-frame))))
992
993       ;; Check for the single case.
994       (inst li a0 (fixnumize 1))
995       (inst bne nvals-arg a0 not-single)
996       (inst lw a0 vals-arg)
997
998       ;; Return with one value.
999       (move csp-tn cfp-tn)
1000       (move cfp-tn ocfp-arg)
1001       (lisp-return lra-arg lip :offset 2)
1002
1003       ;; Nope, not the single case.
1004       (emit-label not-single)
1005       (move ocfp ocfp-arg)
1006       (move lra lra-arg)
1007       (move vals vals-arg)
1008
1009       (inst j (make-fixup 'return-multiple :assembly-routine))
1010       (move nvals nvals-arg t))
1011     (trace-table-entry trace-table-normal)))
1012
1013
1014 \f
1015 ;;;; XEP hackery:
1016
1017
1018 ;;; We don't need to do anything special for regular functions.
1019 ;;;
1020 (define-vop (setup-environment)
1021   (:info label)
1022   (:ignore label)
1023   (:generator 0
1024     ;; Don't bother doing anything.
1025     ))
1026
1027 ;;; Get the lexical environment from its passing location.
1028 ;;;
1029 (define-vop (setup-closure-environment)
1030   (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1031                :to (:result 0))
1032               lexenv)
1033   (:results (closure :scs (descriptor-reg)))
1034   (:info label)
1035   (:ignore label)
1036   (:generator 6
1037     ;; Get result.
1038     (move closure lexenv)))
1039
1040 ;;; Copy a more arg from the argument area to the end of the current frame.
1041 ;;; Fixed is the number of non-more arguments.
1042 ;;;
1043 (define-vop (copy-more-arg)
1044   (:temporary (:sc any-reg :offset nl0-offset) result)
1045   (:temporary (:sc any-reg :offset nl1-offset) count)
1046   (:temporary (:sc any-reg :offset nl2-offset) src)
1047   (:temporary (:sc any-reg :offset nl3-offset) dst)
1048   (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1049   (:info fixed)
1050   (:generator 20
1051     (let ((loop (gen-label))
1052           (do-regs (gen-label))
1053           (done (gen-label)))
1054       (when (< fixed register-arg-count)
1055         ;; Save a pointer to the results so we can fill in register args.
1056         ;; We don't need this if there are more fixed args than reg args.
1057         (move result csp-tn))
1058       ;; Allocate the space on the stack.
1059       (cond ((zerop fixed)
1060              (inst beq nargs-tn done)
1061              (inst addu csp-tn csp-tn nargs-tn))
1062             (t
1063              (inst addu count nargs-tn (fixnumize (- fixed)))
1064              (inst blez count done)
1065              (inst nop)
1066              (inst addu csp-tn csp-tn count)))
1067       (when (< fixed register-arg-count)
1068         ;; We must stop when we run out of stack args, not when we run out of
1069         ;; more args.
1070         (inst addu count nargs-tn (fixnumize (- register-arg-count))))
1071       ;; Everything of interest in registers.
1072       (inst blez count do-regs)
1073       ;; Initialize dst to be end of stack.
1074       (move dst csp-tn t)
1075       ;; Initialize src to be end of args.
1076       (inst addu src cfp-tn nargs-tn)
1077
1078       (emit-label loop)
1079       ;; *--dst = *--src, --count
1080       (inst addu src src (- n-word-bytes))
1081       (inst addu count count (fixnumize -1))
1082       (loadw temp src)
1083       (inst addu dst dst (- n-word-bytes))
1084       (inst bgtz count loop)
1085       (storew temp dst)
1086
1087       (emit-label do-regs)
1088       (when (< fixed register-arg-count)
1089         ;; Now we have to deposit any more args that showed up in registers.
1090         ;; We know there is at least one more arg, otherwise we would have
1091         ;; branched to done up at the top.
1092         (inst subu count nargs-tn (fixnumize (1+ fixed)))
1093         (do ((i fixed (1+ i)))
1094             ((>= i register-arg-count))
1095           ;; Is this the last one?
1096           (inst beq count done)
1097           ;; Store it relative to the pointer saved at the start.
1098           (storew (nth i *register-arg-tns*) result (- i fixed))
1099           ;; Decrement count.
1100           (inst subu count (fixnumize 1))))
1101       (emit-label done))))
1102
1103
1104 ;;; More args are stored consequtively on the stack, starting immediately at
1105 ;;; the context pointer.  The context pointer is not typed, so the lowtag is 0.
1106 ;;;
1107 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1108
1109
1110 ;;; Turn more arg (context, count) into a list.
1111 ;;;
1112 (define-vop (listify-rest-args)
1113   (:args (context-arg :target context :scs (descriptor-reg))
1114          (count-arg :target count :scs (any-reg)))
1115   (:arg-types * tagged-num)
1116   (:temporary (:scs (any-reg) :from (:argument 0)) context)
1117   (:temporary (:scs (any-reg) :from (:argument 1)) count)
1118   (:temporary (:scs (descriptor-reg) :from :eval) temp dst)
1119   (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
1120   (:results (result :scs (descriptor-reg)))
1121   (:translate %listify-rest-args)
1122   (:policy :safe)
1123   (:generator 20
1124     (let ((enter (gen-label))
1125           (loop (gen-label))
1126           (done (gen-label)))
1127       (move context context-arg)
1128       (move count count-arg)
1129       ;; Check to see if there are any arguments.
1130       (inst beq count zero-tn done)
1131       (move result null-tn t)
1132
1133       ;; We need to do this atomically.
1134       (pseudo-atomic (pa-flag)
1135         ;; Allocate a cons (2 words) for each item.
1136         (inst or result alloc-tn list-pointer-lowtag)
1137         (move dst result)
1138         (inst sll temp count 1)
1139         (inst b enter)
1140         (inst addu alloc-tn alloc-tn temp)
1141
1142         ;; Store the current cons in the cdr of the previous cons.
1143         (emit-label loop)
1144         (inst addu dst dst (* 2 n-word-bytes))
1145         (storew dst dst -1 list-pointer-lowtag)
1146
1147         (emit-label enter)
1148         ;; Grab one value.
1149         (loadw temp context)
1150         (inst addu context context n-word-bytes)
1151
1152         ;; Dec count, and if != zero, go back for more.
1153         (inst addu count count (fixnumize -1))
1154         (inst bne count zero-tn loop)
1155
1156         ;; Store the value in the car (in delay slot)
1157         (storew temp dst 0 list-pointer-lowtag)
1158
1159         ;; NIL out the last cons.
1160         (storew null-tn dst 1 list-pointer-lowtag))
1161       (emit-label done))))
1162
1163 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1164 ;;; Supplied is the total number of arguments supplied (originally passed in
1165 ;;; NARGS.)  Fixed is the number of non-rest arguments.
1166 ;;;
1167 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1168 ;;; time the environment is in a pretty brain-damaged state, preventing this
1169 ;;; info from being returned as values.  What we do is compute
1170 ;;; supplied - fixed, and return a pointer that many words below the current
1171 ;;; stack top.
1172 ;;;
1173 (define-vop (more-arg-context)
1174   (:policy :fast-safe)
1175   (:translate sb!c::%more-arg-context)
1176   (:args (supplied :scs (any-reg)))
1177   (:arg-types tagged-num (:constant fixnum))
1178   (:info fixed)
1179   (:results (context :scs (descriptor-reg))
1180             (count :scs (any-reg)))
1181   (:result-types t tagged-num)
1182   (:note "more-arg-context")
1183   (:generator 5
1184     (inst addu count supplied (fixnumize (- fixed)))
1185     (inst subu context csp-tn count)))
1186
1187
1188 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1189 ;;;
1190 (define-vop (verify-arg-count)
1191   (:policy :fast-safe)
1192   (:translate sb!c::%verify-arg-count)
1193   (:args (nargs :scs (any-reg)))
1194   (:arg-types positive-fixnum (:constant t))
1195   (:temporary (:scs (any-reg) :type fixnum) temp)
1196   (:info count)
1197   (:vop-var vop)
1198   (:save-p :compute-only)
1199   (:generator 3
1200     (let ((err-lab
1201            (generate-error-code vop invalid-arg-count-error nargs)))
1202       (cond ((zerop count)
1203              (inst bne nargs zero-tn err-lab)
1204              (inst nop))
1205             (t
1206              (inst li temp (fixnumize count))
1207              (inst bne nargs temp err-lab)
1208              (inst nop))))))
1209
1210 ;;; Various other error signalers.
1211 ;;;
1212 (macrolet ((frob (name error translate &rest args)
1213              `(define-vop (,name)
1214                 ,@(when translate
1215                     `((:policy :fast-safe)
1216                       (:translate ,translate)))
1217                 (:args ,@(mapcar #'(lambda (arg)
1218                                      `(,arg :scs (any-reg descriptor-reg)))
1219                                  args))
1220                 (:vop-var vop)
1221                 (:save-p :compute-only)
1222                 (:generator 1000
1223                   (error-call vop ,error ,@args)))))
1224   (frob arg-count-error invalid-arg-count-error
1225     sb!c::%arg-count-error nargs)
1226   (frob type-check-error object-not-type-error sb!c::%type-check-error
1227     object type)
1228   (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1229     object layout)
1230   (frob odd-key-args-error odd-key-args-error
1231     sb!c::%odd-key-args-error)
1232   (frob unknown-key-arg-error unknown-key-arg-error
1233     sb!c::%unknown-key-arg-error key)
1234   (frob nil-fun-returned-error nil-fun-returned-error nil fun))