move.lisp 9.17 KB
Newer Older
1
;;; -*- Package: MIPS -*-
wlott's avatar
wlott committed
2
3
;;;
;;; **********************************************************************
ram's avatar
ram committed
4
5
6
7
8
9
;;; This code was written as part of the CMU Common Lisp project at
;;; Carnegie Mellon University, and has been placed in the public domain.
;;; If you want to use this code or any part of CMU Common Lisp, please contact
;;; Scott Fahlman or slisp-group@cs.cmu.edu.
;;;
(ext:file-comment
10
  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/mips/move.lisp,v 1.32 1992/08/15 15:18:11 wlott Exp $")
ram's avatar
ram committed
11
;;;
wlott's avatar
wlott committed
12
13
;;; **********************************************************************
;;;
14
;;;    This file contains the MIPS VM definition of operand loading/saving and
wlott's avatar
wlott committed
15
16
;;; the Move VOP.
;;;
17
18
;;; Written by Rob MacLachlan.
;;; MIPS conversion by William Lott.
wlott's avatar
wlott committed
19
;;;
20
(in-package "MIPS")
wlott's avatar
wlott committed
21

22
23

(define-move-function (load-immediate 1) (vop x y)
24
  ((null zero immediate)
25
   (any-reg descriptor-reg))
26
27
28
  (let ((val (tn-value x)))
    (etypecase val
      (integer
wlott's avatar
wlott committed
29
       (inst li y (fixnum val)))
30
31
32
33
34
      (null
       (move y null-tn))
      (symbol
       (load-symbol y val))
      (character
wlott's avatar
wlott committed
35
       (inst li y (logior (ash (char-code val) type-bits)
wlott's avatar
wlott committed
36
			  base-char-type))))))
37
38

(define-move-function (load-number 1) (vop x y)
39
  ((zero immediate)
40
   (signed-reg unsigned-reg))
wlott's avatar
wlott committed
41
  (inst li y (tn-value x)))
42

wlott's avatar
wlott committed
43
(define-move-function (load-base-char 1) (vop x y)
44
  ((immediate) (base-char-reg))
wlott's avatar
wlott committed
45
  (inst li y (char-code (tn-value x))))
46

wlott's avatar
wlott committed
47
(define-move-function (load-system-area-pointer 1) (vop x y)
48
  ((immediate) (sap-reg))
wlott's avatar
wlott committed
49
50
  (inst li y (sap-int (tn-value x))))

51
(define-move-function (load-constant 5) (vop x y)
52
  ((constant) (descriptor-reg any-reg))
53
54
55
56
57
58
59
  (loadw y code-tn (tn-offset x) other-pointer-type))

(define-move-function (load-stack 5) (vop x y)
  ((control-stack) (any-reg descriptor-reg))
  (load-stack-tn y x))

(define-move-function (load-number-stack 5) (vop x y)
wlott's avatar
wlott committed
60
  ((base-char-stack) (base-char-reg)
61
62
63
64
65
66
67
68
69
70
71
   (sap-stack) (sap-reg)
   (signed-stack) (signed-reg)
   (unsigned-stack) (unsigned-reg))
  (let ((nfp (current-nfp-tn vop)))
    (loadw y nfp (tn-offset x))))

(define-move-function (store-stack 5) (vop x y)
  ((any-reg descriptor-reg) (control-stack))
  (store-stack-tn y x))

(define-move-function (store-number-stack 5) (vop x y)
wlott's avatar
wlott committed
72
  ((base-char-reg) (base-char-stack)
73
74
75
76
77
78
   (sap-reg) (sap-stack)
   (signed-reg) (signed-stack)
   (unsigned-reg) (unsigned-stack))
  (let ((nfp (current-nfp-tn vop)))
    (storew x nfp (tn-offset y))))

wlott's avatar
wlott committed
79
80
81
82
83
84

;;;; The Move VOP:
;;;
(define-vop (move)
  (:args (x :target y
	    :scs (any-reg descriptor-reg)
85
	    :load-if (not (location= x y))))
wlott's avatar
wlott committed
86
  (:results (y :scs (any-reg descriptor-reg)
87
	       :load-if (not (location= x y))))
wlott's avatar
wlott committed
88
89
90
  (:effects)
  (:affected)
  (:generator 0
91
    (move y x)))
wlott's avatar
wlott committed
92

93
94
95
(define-move-vop move :move
  (any-reg descriptor-reg)
  (any-reg descriptor-reg))
wlott's avatar
wlott committed
96
97
98
99
100
101
102

;;; Make Move the check VOP for T so that type check generation doesn't think
;;; it is a hairy type.  This also allows checking of a few of the values in a
;;; continuation to fall out.
;;;
(primitive-type-vop move (:check) t)

103
104
105
106
107
108
;;;    The Move-Argument VOP is used for moving descriptor values into another
;;; frame for argument or known value passing.
;;;
(define-vop (move-argument)
  (:args (x :target y
	    :scs (any-reg descriptor-reg))
109
	 (fp :scs (any-reg)
110
111
112
113
114
115
116
117
118
119
120
121
122
123
	     :load-if (not (sc-is y any-reg descriptor-reg))))
  (:results (y))
  (:generator 0
    (sc-case y
      ((any-reg descriptor-reg)
       (move y x))
      (control-stack
       (storew x fp (tn-offset y))))))
;;;
(define-move-vop move-argument :move-argument
  (any-reg descriptor-reg)
  (any-reg descriptor-reg))


wlott's avatar
wlott committed
124
125
126
127
128
129
130
131
132

;;;; ILLEGAL-MOVE

;;; This VOP exists just to begin the lifetime of a TN that couldn't be written
;;; legally due to a type error.  An error is signalled before this VOP is
;;; so we don't need to do anything (not that there would be anything sensible
;;; to do anyway.)
;;;
(define-vop (illegal-move)
133
  (:args (x) (type))
wlott's avatar
wlott committed
134
135
  (:results (y))
  (:ignore y)
136
137
  (:vop-var vop)
  (:save-p :compute-only)
138
  (:generator 666
139
    (error-call vop object-not-type-error x type)))
wlott's avatar
wlott committed
140
141


142
143
144

;;;; Moves and coercions:

145
146
147
148
;;; These MOVE-TO-WORD VOPs move a tagged integer to a raw full-word
;;; representation.  Similarly, the MOVE-FROM-WORD VOPs converts a raw integer
;;; to a tagged bignum or fixnum.

149
150
151
;;; Arg is a fixnum, so just shift it.  We need a type restriction because some
;;; possible arg SCs (control-stack) overlap with possible bignum arg SCs.
;;;
152
(define-vop (move-to-word/fixnum)
153
  (:args (x :scs (any-reg descriptor-reg)))
154
  (:results (y :scs (signed-reg unsigned-reg)))
155
  (:arg-types tagged-num)
156
157
158
  (:note "fixnum untagging")
  (:generator 1
    (inst sra y x 2)))
159
;;;
160
(define-move-vop move-to-word/fixnum :move
161
  (any-reg descriptor-reg) (signed-reg unsigned-reg))
162
163
164
165

;;; Arg is a non-immediate constant, load it.
(define-vop (move-to-word-c)
  (:args (x :scs (constant)))
166
  (:results (y :scs (signed-reg unsigned-reg)))
167
168
169
170
171
172
173
174
175
176
177
178
  (:note "constant load")
  (:generator 1
    (inst li y (tn-value x))))
;;;
(define-move-vop move-to-word-c :move
  (constant) (signed-reg unsigned-reg))

;;; Arg is a fixnum or bignum, figure out which and load if necessary.
(define-vop (move-to-word/integer)
  (:args (x :scs (descriptor-reg)))
  (:results (y :scs (signed-reg unsigned-reg)))
  (:note "integer to untagged word coercion")
179
  (:temporary (:scs (non-descriptor-reg)) temp)
180
181
182
183
184
185
  (:generator 3
    (let ((done (gen-label)))
      (inst and temp x 3)
      (inst beq temp done)
      (inst sra y x 2)

186
      (loadw y x bignum-digits-offset other-pointer-type)
187
188
189
190
191
      (emit-label done))))
;;;
(define-move-vop move-to-word/integer :move
  (descriptor-reg) (signed-reg unsigned-reg))

192

193
194
195
;;; Result is a fixnum, so we can just shift.  We need the result type
;;; restriction because of the control-stack ambiguity noted above.
;;;
196
197
198
(define-vop (move-from-word/fixnum)
  (:args (x :scs (signed-reg unsigned-reg)))
  (:results (y :scs (any-reg descriptor-reg)))
199
  (:result-types tagged-num)
200
201
202
  (:note "fixnum tagging")
  (:generator 1
    (inst sll y x 2)))
203
;;;
204
(define-move-vop move-from-word/fixnum :move
205
  (signed-reg unsigned-reg) (any-reg descriptor-reg))
206

207
208
209
210
211
212
213
;;; Result may be a bignum, so we have to check.  Use a worst-case cost to make
;;; sure people know they may be number consing.
;;;
(define-vop (move-from-signed)
  (:args (arg :scs (signed-reg unsigned-reg) :target x))
  (:results (y :scs (any-reg descriptor-reg)))
  (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) x temp)
214
  (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
215
216
217
218
219
220
221
222
223
224
225
  (:note "signed word to integer coercion")
  (:generator 18
    (move x arg)
    (let ((fixnum (gen-label))
	  (done (gen-label)))
      (inst sra temp x 29)
      (inst beq temp fixnum)
      (inst nor temp zero-tn)
      (inst beq temp done)
      (inst sll y x 2)
      
226
227
228
      (with-fixed-allocation
	  (y pa-flag temp bignum-type (1+ bignum-digits-offset))
	(storew x y bignum-digits-offset other-pointer-type))
229
230
231
232
233
234
235
236
237
      (inst b done)
      (inst nop)
      
      (emit-label fixnum)
      (inst sll y x 2)
      (emit-label done))))
;;;
(define-move-vop move-from-signed :move
  (signed-reg) (descriptor-reg))
238

239
240
241

;;; Check for fixnum, and possibly allocate one or two word bignum result.  Use
;;; a worst-case cost to make sure people know they may be number consing.
242
;;;
243
(define-vop (move-from-unsigned)
244
245
246
  (:args (arg :scs (signed-reg unsigned-reg) :target x))
  (:results (y :scs (any-reg descriptor-reg)))
  (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) x temp)
247
  (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
248
  (:note "unsigned word to integer coercion")
249
  (:generator 20
250
    (move x arg)
251
    (inst srl temp x 29)
252
253
    (inst beq temp done)
    (inst sll y x 2)
254
      
255
256
257
    (pseudo-atomic
	(pa-flag :extra (pad-data-block (+ bignum-digits-offset 2)))
      (inst or y alloc-tn other-pointer-type)
258
      (inst slt temp x zero-tn)
259
260
261
262
263
      (inst sll temp type-bits)
      (inst addu temp (logior (ash 1 type-bits) bignum-type))
      (storew temp y 0 other-pointer-type)
      (storew x y bignum-digits-offset other-pointer-type))
    DONE))
264
;;;
265
266
(define-move-vop move-from-unsigned :move
  (unsigned-reg) (descriptor-reg))
267
268
269
270


;;; Move untagged numbers.
;;;
271
(define-vop (word-move)
272
273
274
275
276
277
278
  (:args (x :target y
	    :scs (signed-reg unsigned-reg)
	    :load-if (not (location= x y))))
  (:results (y :scs (signed-reg unsigned-reg)
	       :load-if (not (location= x y))))
  (:effects)
  (:affected)
279
280
  (:note "word integer move")
  (:generator 0
281
282
    (move y x)))
;;;
283
(define-move-vop word-move :move
284
285
286
287
288
  (signed-reg unsigned-reg) (signed-reg unsigned-reg))


;;; Move untagged number arguments/return-values.
;;;
289
(define-vop (move-word-argument)
290
291
  (:args (x :target y
	    :scs (signed-reg unsigned-reg))
292
	 (fp :scs (any-reg)
293
294
	     :load-if (not (sc-is y sap-reg))))
  (:results (y))
295
  (:note "word integer argument move")
296
297
298
299
300
301
302
  (:generator 0
    (sc-case y
      ((signed-reg unsigned-reg)
       (move y x))
      ((signed-stack unsigned-stack)
       (storew x fp (tn-offset y))))))
;;;
303
(define-move-vop move-word-argument :move-argument
304
305
306
307
308
309
310
311
  (descriptor-reg any-reg signed-reg unsigned-reg) (signed-reg unsigned-reg))


;;; Use standard MOVE-ARGUMENT + coercion to move an untagged number to a
;;; descriptor passing location.
;;;
(define-move-vop move-argument :move-argument
  (signed-reg unsigned-reg) (any-reg descriptor-reg))