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