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