1 ;;;; the MIPS implementation of unknown-values VOPs
3 ;;;; This software is part of the SBCL system. See the README file for
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.
14 (define-vop (reset-stack-pointer)
15 (:args (ptr :scs (any-reg)))
19 (define-vop (%%nip-values)
20 (:args (last-nipped-ptr :scs (any-reg) :target dest)
21 (last-preserved-ptr :scs (any-reg) :target src)
22 (moved-ptrs :scs (any-reg) :more t))
23 (:results (r-moved-ptrs :scs (any-reg) :more t))
24 (:temporary (:sc any-reg) src)
25 (:temporary (:sc any-reg) dest)
26 (:temporary (:sc non-descriptor-reg) temp)
27 (:ignore r-moved-ptrs)
29 (inst move src last-preserved-ptr)
30 (inst move dest last-nipped-ptr)
31 (inst move temp zero-tn)
32 (inst sltu temp src csp-tn)
33 (inst beq temp zero-tn DONE)
34 (inst nop) ; not strictly necessary
37 (inst add dest dest n-word-bytes)
38 (inst add src src n-word-bytes)
40 (inst sltu temp src csp-tn)
41 (inst bne temp zero-tn LOOP)
44 (inst move csp-tn dest)
45 (inst sub src src dest)
46 (loop for moved = moved-ptrs then (tn-ref-across moved)
48 do (sc-case (tn-ref-tn moved)
49 ((descriptor-reg any-reg)
50 (inst sub (tn-ref-tn moved) (tn-ref-tn moved) src))
52 (load-stack-tn temp (tn-ref-tn moved))
53 (inst sub temp temp src)
54 (store-stack-tn (tn-ref-tn moved) temp))))))
56 ;;; Push some values onto the stack, returning the start and number of values
57 ;;; pushed as results. It is assumed that the Vals are wired to the standard
58 ;;; argument locations. Nvals is the number of values to push.
60 ;;; The generator cost is pseudo-random. We could get it right by defining a
61 ;;; bogus SC that reflects the costs of the memory-to-memory moves for each
62 ;;; operand, but this seems unworthwhile.
64 (define-vop (push-values)
68 (start :scs (any-reg))
69 (count :scs (any-reg)))
71 (:temporary (:scs (descriptor-reg)) temp)
72 (:temporary (:scs (descriptor-reg)
77 (move start-temp csp-tn)
78 (inst addu csp-tn csp-tn (* nvals n-word-bytes))
79 (do ((val vals (tn-ref-across val))
82 (let ((tn (tn-ref-tn val)))
85 (storew tn start-temp i))
87 (load-stack-tn temp tn)
88 (storew temp start-temp i)))))
89 (move start start-temp)
90 (inst li count (fixnumize nvals))))
92 ;;; Push a list of values on the stack, returning Start and Count as used in
93 ;;; unknown values continuations.
94 (define-vop (values-list)
95 (:args (arg :scs (descriptor-reg) :target list))
98 (:results (start :scs (any-reg))
99 (count :scs (any-reg)))
100 (:temporary (:scs (descriptor-reg) :type list :from (:argument 0)) list)
101 (:temporary (:scs (descriptor-reg)) temp)
102 (:temporary (:scs (non-descriptor-reg)) ndescr)
104 (:save-p :compute-only)
110 (inst beq list null-tn done)
111 (loadw temp list cons-car-slot list-pointer-lowtag)
112 (loadw list list cons-cdr-slot list-pointer-lowtag)
113 (inst addu csp-tn csp-tn n-word-bytes)
114 (storew temp csp-tn -1)
115 (inst and ndescr list lowtag-mask)
116 (inst xor ndescr list-pointer-lowtag)
117 (inst beq ndescr zero-tn loop)
119 (error-call vop bogus-arg-to-values-list-error list)
122 (inst subu count csp-tn start)))
124 ;;; Copy the more arg block to the top of the stack so we can use them
125 ;;; as function arguments.
126 (define-vop (%more-arg-values)
127 (:args (context :scs (descriptor-reg any-reg) :target src)
128 (skip :scs (any-reg zero immediate))
129 (num :scs (any-reg) :target count))
130 (:arg-types * positive-fixnum positive-fixnum)
131 (:temporary (:sc any-reg :from (:argument 0)) src)
132 (:temporary (:sc any-reg :from (:argument 2)) dst)
133 (:temporary (:sc descriptor-reg :from (:argument 1)) temp)
134 (:results (start :scs (any-reg))
135 (count :scs (any-reg)))
141 (inst addu src context (* (tn-value skip) n-word-bytes)))
143 (inst addu src context skip)))
145 (inst beq num zero-tn done)
146 (inst move start csp-tn)
147 (inst move dst csp-tn)
148 (inst addu csp-tn count)
153 (inst bne dst csp-tn loop)
154 (inst sw temp dst -4)