0.8.12.16:
[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 (%%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 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
35     LOOP
36     (loadw temp src)
37     (inst add dest dest n-word-bytes)
38     (inst add src src n-word-bytes)
39     (storew temp dest -1)
40     (inst sltu temp src csp-tn)
41     (inst bne temp zero-tn LOOP)
42     (inst nop)
43     DONE
44     (inst move csp-tn dest)
45     (inst sub src src dest)
46     (loop for moved = moved-ptrs then (tn-ref-across moved)
47           while 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))
51                ((control-stack)
52                 (load-stack-tn temp (tn-ref-tn moved))
53                 (inst sub temp temp src)
54                 (store-stack-tn (tn-ref-tn moved) temp))))))
55
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.
59 ;;;
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.
63 ;;;
64 (define-vop (push-values)
65   (:args
66    (vals :more t))
67   (:results
68    (start :scs (any-reg))
69    (count :scs (any-reg)))
70   (:info nvals)
71   (:temporary (:scs (descriptor-reg)) temp)
72   (:temporary (:scs (descriptor-reg)
73                :to (:result 0)
74                :target start)
75               start-temp)
76   (:generator 20
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))
80          (i 0 (1+ i)))
81         ((null val))
82       (let ((tn (tn-ref-tn val)))
83         (sc-case tn
84           (descriptor-reg
85            (storew tn start-temp i))
86           (control-stack
87            (load-stack-tn temp tn)
88            (storew temp start-temp i)))))
89     (move start start-temp)
90     (inst li count (fixnumize nvals))))
91
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))
96   (:arg-types list)
97   (:policy :fast-safe)
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)
103   (:vop-var vop)
104   (:save-p :compute-only)
105   (:generator 0
106     (move list arg)
107     (move start csp-tn)
108     
109     LOOP
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)
118     (inst nop)
119     (error-call vop bogus-arg-to-values-list-error list)
120     
121     DONE
122     (inst subu count csp-tn start)))
123
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)))
136   (:generator 20
137     (sc-case skip
138       (zero
139        (move src context))
140       (immediate
141        (inst addu src context (* (tn-value skip) n-word-bytes)))
142       (any-reg
143        (inst addu src context skip)))
144     (move count num)
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)
149     LOOP
150     (inst lw temp src)
151     (inst addu src 4)
152     (inst addu dst 4)
153     (inst bne dst csp-tn loop)
154     (inst sw temp dst -4)
155     DONE))