cfdecacf7e564279406d9c5eb9994f30647e4bcb
[sbcl.git] / src / compiler / alpha / values.lisp
1 ;;;; the Alpha 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 ptr csp-tn)))
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 last-nipped-ptr dest)
50     (move last-preserved-ptr src)
51     (inst cmple csp-tn src temp)
52     (inst bne temp DONE)
53     LOOP
54     (loadw temp src)
55     (inst addq dest n-word-bytes dest)
56     (inst addq src n-word-bytes src)
57     (storew temp dest -1)
58     (inst cmple csp-tn src temp)
59     (inst beq temp LOOP)
60     DONE
61     (inst lda csp-tn 0 dest)
62     (inst subq src dest src)
63     (loop for moved = moved-ptrs then (tn-ref-across moved)
64           while moved
65           do (sc-case (tn-ref-tn moved)
66                ((descriptor-reg any-reg)
67                 (inst subq (tn-ref-tn moved) src (tn-ref-tn moved)))
68                ((control-stack)
69                 (load-stack-tn temp (tn-ref-tn moved))
70                 (inst subq temp src temp)
71                 (store-stack-tn (tn-ref-tn moved) temp))))))
72
73 ;;; Push some values onto the stack, returning the start and number of
74 ;;; values pushed as results. It is assumed that the Vals are wired to
75 ;;; the standard argument locations. Nvals is the number of values to
76 ;;; push.
77 ;;;
78 ;;; The generator cost is pseudo-random. We could get it right by
79 ;;; defining a bogus SC that reflects the costs of the
80 ;;; memory-to-memory moves for each operand, but this seems
81 ;;; unworthwhile.
82 (define-vop (push-values)
83   (:args
84    (vals :more t))
85   (:results
86    (start :scs (any-reg))
87    (count :scs (any-reg)))
88   (:info nvals)
89   (:temporary (:scs (descriptor-reg)) temp)
90   (:temporary (:scs (descriptor-reg)
91                :to (:result 0)
92                :target start)
93               start-temp)
94   (:generator 20
95     (move csp-tn start-temp)
96     (inst lda csp-tn (* nvals n-word-bytes) csp-tn)
97     (do ((val vals (tn-ref-across val))
98          (i 0 (1+ i)))
99         ((null val))
100       (let ((tn (tn-ref-tn val)))
101         (sc-case tn
102           (descriptor-reg
103            (storew tn start-temp i))
104           (control-stack
105            (load-stack-tn temp tn)
106            (storew temp start-temp i)))))
107     (move start-temp start)
108     (inst li (fixnumize nvals) count)))
109
110 ;;; Push a list of values on the stack, returning Start and Count as
111 ;;; used in unknown values continuations.
112 (define-vop (values-list)
113   (:args (arg :scs (descriptor-reg) :target list))
114   (:arg-types list)
115   (:policy :fast-safe)
116   (:results (start :scs (any-reg))
117             (count :scs (any-reg)))
118   (:temporary (:scs (descriptor-reg) :type list :from (:argument 0)) list)
119   (:temporary (:scs (non-descriptor-reg)) temp)
120   (:temporary (:scs (non-descriptor-reg)) ndescr)
121   (:vop-var vop)
122   (:save-p :compute-only)
123   (:generator 0
124     (move arg list)
125     (move csp-tn start)
126     
127     LOOP
128     (inst cmpeq list null-tn temp)
129     (inst bne temp done)
130     (loadw temp list cons-car-slot list-pointer-lowtag)
131     (loadw list list cons-cdr-slot list-pointer-lowtag)
132     (inst lda csp-tn n-word-bytes csp-tn)
133     (storew temp csp-tn -1)
134     (inst and list lowtag-mask ndescr)
135     (inst xor ndescr list-pointer-lowtag ndescr)
136     (inst beq ndescr loop)
137     (error-call vop bogus-arg-to-values-list-error list)
138     
139     DONE
140     (inst subq csp-tn start count)))
141
142 ;;; Copy the &MORE arg block to the top of the stack so we can use
143 ;;; them as function arguments.
144 (define-vop (%more-arg-values)
145   (:args (context :scs (descriptor-reg any-reg) :target src)
146          (skip :scs (any-reg zero immediate))
147          (num :scs (any-reg) :target count))
148   (:arg-types * positive-fixnum positive-fixnum)
149   (:temporary (:sc any-reg :from (:argument 0)) src)
150   (:temporary (:sc any-reg :from (:argument 2)) dst)
151   (:temporary (:sc descriptor-reg :from (:argument 1)) temp)
152   (:temporary (:sc non-descriptor-reg) temp1)
153   (:results (start :scs (any-reg))
154             (count :scs (any-reg)))
155   (:generator 20
156     (sc-case skip
157       (zero
158        (move context src))
159       (immediate
160        (inst lda src (* (tn-value skip) n-word-bytes) context))
161       (any-reg
162        (inst addq context skip src)))
163     (move num count)
164     (inst move csp-tn start)
165     (inst beq num done)
166     (inst move csp-tn dst)
167     (inst addq csp-tn count csp-tn)
168     LOOP
169     (inst ldl temp 0 src)
170     (inst addq src 4 src)
171     (inst addq dst 4 dst)
172     (inst stl temp -4 dst)
173     (inst cmpeq dst csp-tn temp1)
174     (inst beq temp1 loop)
175     DONE))