f3aad0993ccac4973b116a35ded4607a44c14caa
[sbcl.git] / src / compiler / hppa / move.lisp
1 (in-package "SB!VM")
2
3 (define-move-fun (load-immediate 1) (vop x y)
4   ((null zero immediate)
5    (any-reg descriptor-reg))
6   (let ((val (tn-value x)))
7     (etypecase val
8       (integer
9        (inst li (fixnumize val) y))
10       (null
11        (move null-tn y))
12       (symbol
13        (load-symbol y val))
14       (character
15        (inst li (logior (ash (char-code val) n-widetag-bits)
16                         base-char-widetag)
17              y)))))
18
19 (define-move-fun (load-number 1) (vop x y)
20   ((immediate zero)
21    (signed-reg unsigned-reg))
22   (let ((x (tn-value x)))
23     (inst li (if (>= x (ash 1 31)) (logior (ash -1 32) x) x) y)))
24
25 (define-move-fun (load-base-char 1) (vop x y)
26   ((immediate) (base-char-reg))
27   (inst li (char-code (tn-value x)) y))
28
29 (define-move-fun (load-system-area-pointer 1) (vop x y)
30   ((immediate) (sap-reg))
31   (inst li (sap-int (tn-value x)) y))
32
33 (define-move-fun (load-constant 5) (vop x y)
34   ((constant) (descriptor-reg))
35   (loadw y code-tn (tn-offset x) other-pointer-lowtag))
36
37 (define-move-fun (load-stack 5) (vop x y)
38   ((control-stack) (any-reg descriptor-reg))
39   (load-stack-tn y x))
40
41 (define-move-fun (load-number-stack 5) (vop x y)
42   ((base-char-stack) (base-char-reg)
43    (sap-stack) (sap-reg)
44    (signed-stack) (signed-reg)
45    (unsigned-stack) (unsigned-reg))
46   (let ((nfp (current-nfp-tn vop)))
47     (loadw y nfp (tn-offset x))))
48
49 (define-move-fun (store-stack 5) (vop x y)
50   ((any-reg descriptor-reg) (control-stack))
51   (store-stack-tn y x))
52
53 (define-move-fun (store-number-stack 5) (vop x y)
54   ((base-char-reg) (base-char-stack)
55    (sap-reg) (sap-stack)
56    (signed-reg) (signed-stack)
57    (unsigned-reg) (unsigned-stack))
58   (let ((nfp (current-nfp-tn vop)))
59     (storew x nfp (tn-offset y))))
60
61 \f
62 ;;;; The Move VOP:
63 ;;;
64 (define-vop (move)
65   (:args (x :target y
66             :scs (any-reg descriptor-reg)
67             :load-if (not (location= x y))))
68   (:results (y :scs (any-reg descriptor-reg)
69                :load-if (not (location= x y))))
70   (:effects)
71   (:affected)
72   (:generator 0
73     (move x y)))
74
75 (define-move-vop move :move
76   (any-reg descriptor-reg)
77   (any-reg descriptor-reg))
78
79 ;;; Make Move the check VOP for T so that type check generation doesn't think
80 ;;; it is a hairy type.  This also allows checking of a few of the values in a
81 ;;; continuation to fall out.
82 ;;;
83 (primitive-type-vop move (:check) t)
84
85 ;;;    The Move-Argument VOP is used for moving descriptor values into another
86 ;;; frame for argument or known value passing.
87 ;;;
88 (define-vop (move-argument)
89   (:args (x :target y
90             :scs (any-reg descriptor-reg))
91          (fp :scs (any-reg)
92              :load-if (not (sc-is y any-reg descriptor-reg))))
93   (:results (y))
94   (:generator 0
95     (sc-case y
96       ((any-reg descriptor-reg)
97        (move x y))
98       (control-stack
99        (storew x fp (tn-offset y))))))
100 ;;;
101 (define-move-vop move-argument :move-arg
102   (any-reg descriptor-reg)
103   (any-reg descriptor-reg))
104
105
106 \f
107 ;;;; ILLEGAL-MOVE
108
109 ;;; This VOP exists just to begin the lifetime of a TN that couldn't be written
110 ;;; legally due to a type error.  An error is signalled before this VOP is
111 ;;; so we don't need to do anything (not that there would be anything sensible
112 ;;; to do anyway.)
113 ;;;
114 (define-vop (illegal-move)
115   (:args (x) (type))
116   (:results (y))
117   (:ignore y)
118   (:vop-var vop)
119   (:save-p :compute-only)
120   (:generator 666
121     (error-call vop object-not-type-error x type)))
122
123
124 \f
125 ;;;; Moves and coercions:
126
127 ;;; These MOVE-TO-WORD VOPs move a tagged integer to a raw full-word
128 ;;; representation.  Similarly, the MOVE-FROM-WORD VOPs converts a raw integer
129 ;;; to a tagged bignum or fixnum.
130
131 ;;; Arg is a fixnum, so just shift it.  We need a type restriction because some
132 ;;; possible arg SCs (control-stack) overlap with possible bignum arg SCs.
133 ;;;
134 (define-vop (move-to-word/fixnum)
135   (:args (x :scs (any-reg descriptor-reg)))
136   (:results (y :scs (signed-reg unsigned-reg)))
137   (:arg-types tagged-num)
138   (:note "fixnum untagging")
139   (:generator 1
140     (inst sra x 2 y)))
141 ;;;
142 (define-move-vop move-to-word/fixnum :move
143   (any-reg descriptor-reg) (signed-reg unsigned-reg))
144
145 ;;; Arg is a non-immediate constant, load it.
146 (define-vop (move-to-word-c)
147   (:args (x :scs (constant)))
148   (:results (y :scs (signed-reg unsigned-reg)))
149   (:note "constant load")
150   (:generator 1
151     (inst li (tn-value x) y)))
152 ;;;
153 (define-move-vop move-to-word-c :move
154   (constant) (signed-reg unsigned-reg))
155
156 ;;; Arg is a fixnum or bignum, figure out which and load if necessary.
157 (define-vop (move-to-word/integer)
158   (:args (x :scs (descriptor-reg)))
159   (:results (y :scs (signed-reg unsigned-reg)))
160   (:note "integer to untagged word coercion")
161   (:generator 3
162     (inst extru x 31 2 zero-tn :<>)
163     (inst sra x 2 y :tr)
164     (loadw y x bignum-digits-offset other-pointer-lowtag)))
165 ;;;
166 (define-move-vop move-to-word/integer :move
167   (descriptor-reg) (signed-reg unsigned-reg))
168
169 ;;; Result is a fixnum, so we can just shift.  We need the result type
170 ;;; restriction because of the control-stack ambiguity noted above.
171 ;;;
172 (define-vop (move-from-word/fixnum)
173   (:args (x :scs (signed-reg unsigned-reg)))
174   (:results (y :scs (any-reg descriptor-reg)))
175   (:result-types tagged-num)
176   (:note "fixnum tagging")
177   (:generator 1
178     (inst sll x 2 y)))
179 ;;;
180 (define-move-vop move-from-word/fixnum :move
181   (signed-reg unsigned-reg) (any-reg descriptor-reg))
182
183 ;;; Result may be a bignum, so we have to check.  Use a worst-case cost to make
184 ;;; sure people know they may be number consing.
185 ;;;
186 (define-vop (move-from-signed)
187   (:args (x :scs (signed-reg unsigned-reg) :to (:eval 1)))
188   (:results (y :scs (any-reg descriptor-reg) :from (:eval 0)))
189   (:temporary (:scs (non-descriptor-reg)) temp)
190   (:note "signed word to integer coercion")
191   (:generator 18
192     ;; Extract the top three bits.
193     (inst extrs x 2 3 temp :=)
194     ;; Invert them (unless they are already zero).
195     (inst uaddcm zero-tn temp temp)
196     ;; If we are left with zero, it will fit in a fixnum.  So branch around
197     ;; the bignum-construction, doing the shift in the delay slot.
198     (inst comb := temp zero-tn done)
199     (inst sll x 2 y)
200     ;; Make a single-digit bignum.
201     (with-fixed-allocation (y temp bignum-widetag (1+ bignum-digits-offset))
202       (storew x y bignum-digits-offset other-pointer-lowtag))
203     DONE))
204 ;;;
205 (define-move-vop move-from-signed :move
206   (signed-reg) (descriptor-reg))
207
208
209 ;;; Check for fixnum, and possibly allocate one or two word bignum result.  Use
210 ;;; a worst-case cost to make sure people know they may be number consing.
211 ;;;
212 (define-vop (move-from-unsigned)
213   (:args (x :scs (signed-reg unsigned-reg) :to (:eval 1)))
214   (:results (y :scs (any-reg descriptor-reg) :from (:eval 0)))
215   (:temporary (:scs (non-descriptor-reg)) temp)
216   (:note "unsigned word to integer coercion")
217   (:generator 20
218     ;; Grab the top three bits.
219     (inst extrs x 2 3 temp)
220     ;; If zero, it will fit as a fixnum.
221     (inst comib := 0 temp done)
222     (inst sll x 2 y)
223     ;; Make a bignum.
224     (pseudo-atomic (:extra (pad-data-block (1+ bignum-digits-offset)))
225       ;; Create the result pointer.
226       (inst move alloc-tn y)
227       (inst dep other-pointer-lowtag 31 3 y)
228       ;; Check the high bit, and skip the next instruction if it's 0.
229       (inst comclr x zero-tn zero-tn :>=)
230       ;; The high bit is set, so allocate enough space for a two-word bignum.
231       ;; We always skip the following instruction, so it is only executed
232       ;; when we want one word.
233       (inst addi (pad-data-block 1) alloc-tn alloc-tn :tr)
234       ;; Set up the header for one word.  Use ADDI instead of LI so we can
235       ;; skip the next instruction.
236       (inst addi (logior (ash 1 n-widetag-bits) bignum-widetag) zero-tn temp :tr)
237       ;; Set up the header for two words.
238       (inst li (logior (ash 2 n-widetag-bits) bignum-widetag) temp)
239       ;; Store the header and the data.
240       (storew temp y 0 other-pointer-lowtag)
241       (storew x y bignum-digits-offset other-pointer-lowtag))
242     DONE))
243 ;;;
244 (define-move-vop move-from-unsigned :move
245   (unsigned-reg) (descriptor-reg))
246
247
248 ;;; Move untagged numbers.
249 ;;;
250 (define-vop (word-move)
251   (:args (x :target y
252             :scs (signed-reg unsigned-reg)
253             :load-if (not (location= x y))))
254   (:results (y :scs (signed-reg unsigned-reg)
255                :load-if (not (location= x y))))
256   (:effects)
257   (:affected)
258   (:note "word integer move")
259   (:generator 0
260     (move x y)))
261 ;;;
262 (define-move-vop word-move :move
263   (signed-reg unsigned-reg) (signed-reg unsigned-reg))
264
265
266 ;;; Move untagged number arguments/return-values.
267 ;;;
268 (define-vop (move-word-argument)
269   (:args (x :target y
270             :scs (signed-reg unsigned-reg))
271          (fp :scs (any-reg)
272              :load-if (not (sc-is y sap-reg))))
273   (:results (y))
274   (:note "word integer argument move")
275   (:generator 0
276     (sc-case y
277       ((signed-reg unsigned-reg)
278        (move x y))
279       ((signed-stack unsigned-stack)
280        (storew x fp (tn-offset y))))))
281 ;;;
282 (define-move-vop move-word-argument :move-arg
283   (descriptor-reg any-reg signed-reg unsigned-reg) (signed-reg unsigned-reg))
284
285
286 ;;; Use standard MOVE-ARGUMENT + coercion to move an untagged number to a
287 ;;; descriptor passing location.
288 ;;;
289 (define-move-vop move-argument :move-arg
290   (signed-reg unsigned-reg) (any-reg descriptor-reg))