sbcl-0.8.14.11:
[sbcl.git] / src / compiler / sparc / values.lisp
1 ;;;; the sparc 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 (%%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)
28   (:generator 1
29     (inst move dest last-nipped-ptr)
30     (inst move src last-preserved-ptr)
31     (inst cmp csp-tn src)
32     (inst b :le DONE)
33     (inst nop) ; not strictly necessary
34     LOOP
35     (loadw temp src)
36     (inst add dest dest n-word-bytes)
37     (inst add src src n-word-bytes)
38     (storew temp dest -1)
39     (inst cmp csp-tn src)
40     (inst b :gt LOOP)
41     (inst nop)
42     DONE
43     (inst move csp-tn dest)
44     (inst sub src src dest)
45     (loop for moved = moved-ptrs then (tn-ref-across moved)
46           while moved
47           do (sc-case (tn-ref-tn moved)
48                ((descriptor-reg any-reg)
49                 (inst sub (tn-ref-tn moved) (tn-ref-tn moved) src))
50                ((control-stack)
51                 (load-stack-tn temp (tn-ref-tn moved))
52                 (inst sub temp temp src)
53                 (store-stack-tn (tn-ref-tn moved) temp))))))
54
55 ;;; Push some values onto the stack, returning the start and number of
56 ;;; values pushed as results.  It is assumed that the Vals are wired
57 ;;; to the standard argument locations.  Nvals is the number of values
58 ;;; to push.
59 ;;;
60 ;;; The generator cost is pseudo-random.  We could get it right by
61 ;;; defining a bogus SC that reflects the costs of the
62 ;;; memory-to-memory moves for each operand, but this seems
63 ;;; unworthwhile.
64 (define-vop (push-values)
65   (:args (vals :more t))
66   (:results (start :scs (any-reg) :from :load)
67             (count :scs (any-reg)))
68   (:info nvals)
69   (:temporary (:scs (descriptor-reg)) temp)
70   (:generator 20
71     (inst move start csp-tn)
72     (inst add csp-tn csp-tn (* nvals n-word-bytes))
73     (do ((val vals (tn-ref-across val))
74          (i 0 (1+ i)))
75         ((null val))
76       (let ((tn (tn-ref-tn val)))
77         (sc-case tn
78           (descriptor-reg
79            (storew tn start i))
80           (control-stack
81            (load-stack-tn temp tn)
82            (storew temp start i)))))
83     (inst li count (fixnumize nvals))))
84
85 ;;; Push a list of values on the stack, returning Start and Count as
86 ;;; used in unknown values continuations.
87 (define-vop (values-list)
88   (:args (arg :scs (descriptor-reg) :target list))
89   (:arg-types list)
90   (:policy :fast-safe)
91   (:results (start :scs (any-reg))
92             (count :scs (any-reg)))
93   (:temporary (:scs (descriptor-reg) :type list :from (:argument 0)) list)
94   (:temporary (:scs (descriptor-reg)) temp)
95   (:temporary (:scs (non-descriptor-reg)) ndescr)
96   (:vop-var vop)
97   (:save-p :compute-only)
98   (:generator 0
99     (let ((loop (gen-label))
100           (done (gen-label)))
101
102       (move list arg)
103       (move start csp-tn)
104
105       (emit-label loop)
106       (inst cmp list null-tn)
107       (inst b :eq done)
108       (loadw temp list cons-car-slot list-pointer-lowtag)
109       (loadw list list cons-cdr-slot list-pointer-lowtag)
110       (inst add csp-tn csp-tn n-word-bytes)
111       (storew temp csp-tn -1)
112       (test-type list loop nil (list-pointer-lowtag) :temp ndescr)
113       (error-call vop bogus-arg-to-values-list-error list)
114
115       (emit-label done)
116       (inst sub count csp-tn start))))
117
118
119
120 ;;; Copy the more arg block to the top of the stack so we can use them
121 ;;; as function arguments.
122 (define-vop (%more-arg-values)
123   (:args (context :scs (descriptor-reg any-reg) :target src)
124          (skip :scs (any-reg zero immediate))
125          (num :scs (any-reg) :target count))
126   (:arg-types * positive-fixnum positive-fixnum)
127   (:temporary (:sc any-reg :from (:argument 0)) src)
128   (:temporary (:sc any-reg :from (:argument 2)) dst)
129   (:temporary (:sc descriptor-reg :from (:argument 1)) temp)
130   (:temporary (:sc any-reg) i)
131   (:results (start :scs (any-reg))
132             (count :scs (any-reg)))
133   (:generator 20
134     (sc-case skip
135       (zero
136        (move src context))
137       (immediate
138        (inst add src context (* (tn-value skip) n-word-bytes)))
139       (any-reg
140        (inst add src context skip)))
141     (inst orcc count zero-tn num)
142     (inst b :eq done)
143     (inst move start csp-tn)
144     (inst move dst csp-tn)
145     (inst add csp-tn count)
146     (inst move i count)
147     LOOP
148     (inst subcc i 4)
149     (inst ld temp src i)
150     (inst b :ne loop)
151     (inst st temp dst i)
152     DONE))