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