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