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