Revert "Clean up %more-arg-values."
[sbcl.git] / src / compiler / mips / values.lisp
1 ;;;; the MIPS implementation of unknown-values VOPs
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 (define-vop (reset-stack-pointer)
15   (:args (ptr :scs (any-reg)))
16   (:generator 1
17     (move csp-tn ptr)))
18
19 (define-vop (%%pop-dx)
20   (:args (ptr :scs (any-reg)))
21   (:ignore ptr)
22   (:generator 1
23     (bug "VOP %%POP-DX is not implemented.")))
24
25 (define-vop (%%nip-dx)
26   (:args (last-nipped-ptr :scs (any-reg) :target dest)
27          (last-preserved-ptr :scs (any-reg) :target src)
28          (moved-ptrs :scs (any-reg) :more t))
29   (:results (r-moved-ptrs :scs (any-reg) :more t))
30   (:temporary (:sc any-reg) src)
31   (:temporary (:sc any-reg) dest)
32   (:temporary (:sc non-descriptor-reg) temp)
33   (:ignore r-moved-ptrs
34            last-nipped-ptr last-preserved-ptr moved-ptrs
35            src dest temp)
36   (:generator 1
37     (bug "VOP %%NIP-DX is not implemented.")))
38
39 (define-vop (%%nip-values)
40   (:args (last-nipped-ptr :scs (any-reg) :target dest)
41          (last-preserved-ptr :scs (any-reg) :target src)
42          (moved-ptrs :scs (any-reg) :more t))
43   (:results (r-moved-ptrs :scs (any-reg) :more t))
44   (:temporary (:sc any-reg) src)
45   (:temporary (:sc any-reg) dest)
46   (:temporary (:sc non-descriptor-reg) temp)
47   (:ignore r-moved-ptrs)
48   (:generator 1
49     (move src last-preserved-ptr)
50     (move dest last-nipped-ptr)
51     (inst sltu temp src csp-tn)
52     (inst beq temp DONE)
53     (inst nop) ; not strictly necessary
54     LOOP
55     (loadw temp src)
56     (inst add dest dest n-word-bytes)
57     (inst add src src n-word-bytes)
58     (storew temp dest -1)
59     (inst sltu temp src csp-tn)
60     (inst bne temp LOOP)
61     (inst nop)
62     DONE
63     (move csp-tn dest)
64     (inst sub src src dest)
65     (loop for moved = moved-ptrs then (tn-ref-across moved)
66           while moved
67           do (sc-case (tn-ref-tn moved)
68                ((descriptor-reg any-reg)
69                 (inst sub (tn-ref-tn moved) (tn-ref-tn moved) src))
70                ((control-stack)
71                 (load-stack-tn temp (tn-ref-tn moved))
72                 (inst sub temp temp src)
73                 (store-stack-tn (tn-ref-tn moved) temp))))))
74
75 ;;; Push some values onto the stack, returning the start and number of values
76 ;;; pushed as results.  It is assumed that the Vals are wired to the standard
77 ;;; argument locations.  Nvals is the number of values to push.
78 ;;;
79 ;;; The generator cost is pseudo-random.  We could get it right by defining a
80 ;;; bogus SC that reflects the costs of the memory-to-memory moves for each
81 ;;; operand, but this seems unworthwhile.
82 ;;;
83 (define-vop (push-values)
84   (:args
85    (vals :more t))
86   (:results
87    (start :scs (any-reg))
88    (count :scs (any-reg)))
89   (:info nvals)
90   (:temporary (:scs (descriptor-reg)) temp)
91   (:temporary (:scs (descriptor-reg)
92                :to (:result 0)
93                :target start)
94               start-temp)
95   (:generator 20
96     (move start-temp csp-tn)
97     (inst addu csp-tn csp-tn (* nvals n-word-bytes))
98     (do ((val vals (tn-ref-across val))
99          (i 0 (1+ i)))
100         ((null val))
101       (let ((tn (tn-ref-tn val)))
102         (sc-case tn
103           (descriptor-reg
104            (storew tn start-temp i))
105           (control-stack
106            (load-stack-tn temp tn)
107            (storew temp start-temp i)))))
108     (move start start-temp)
109     (inst li count (fixnumize nvals))))
110
111 ;;; Push a list of values on the stack, returning Start and Count as used in
112 ;;; unknown values continuations.
113 (define-vop (values-list)
114   (:args (arg :scs (descriptor-reg) :target list))
115   (:arg-types list)
116   (:policy :fast-safe)
117   (:results (start :scs (any-reg))
118             (count :scs (any-reg)))
119   (:temporary (:scs (descriptor-reg) :type list :from (:argument 0)) list)
120   (:temporary (:scs (descriptor-reg)) temp)
121   (:temporary (:scs (non-descriptor-reg)) ndescr)
122   (:vop-var vop)
123   (:save-p :compute-only)
124   (:generator 0
125     (move list arg)
126     (move start csp-tn)
127
128     LOOP
129     (inst beq list null-tn done)
130     (loadw temp list cons-car-slot list-pointer-lowtag)
131     (loadw list list cons-cdr-slot list-pointer-lowtag)
132     (inst addu csp-tn csp-tn n-word-bytes)
133     (storew temp csp-tn -1)
134     (inst and ndescr list lowtag-mask)
135     (inst xor ndescr list-pointer-lowtag)
136     (inst beq ndescr loop)
137     (inst nop)
138     (error-call vop bogus-arg-to-values-list-error list)
139
140     DONE
141     (inst subu count csp-tn start)))
142
143 ;;; Copy the more arg block to the top of the stack so we can use them
144 ;;; as function arguments.
145 (define-vop (%more-arg-values)
146   (:args (context :scs (descriptor-reg any-reg) :target src)
147          (skip :scs (any-reg zero immediate))
148          (num :scs (any-reg) :target count))
149   (:arg-types * positive-fixnum positive-fixnum)
150   (:temporary (:sc any-reg :from (:argument 0)) src)
151   (:temporary (:sc any-reg :from (:argument 2)) dst)
152   (:temporary (:sc descriptor-reg :from (:argument 1)) temp)
153   (:results (start :scs (any-reg))
154             (count :scs (any-reg)))
155   (:generator 20
156     (sc-case skip
157       (zero
158        (move src context))
159       (immediate
160        (inst addu src context (* (tn-value skip) n-word-bytes)))
161       (any-reg
162        (inst addu src context skip)))
163     (move count num)
164     (inst beq num done)
165     (move start csp-tn t)
166     (move dst csp-tn)
167     (inst addu csp-tn count)
168     LOOP
169     (inst lw temp src)
170     (inst addu src n-word-bytes)
171     (inst addu dst n-word-bytes)
172     (inst bne dst csp-tn loop)
173     (inst sw temp dst (- n-word-bytes))
174     DONE))