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