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