Reduce stack usage by unwind-block.
[sbcl.git] / src / compiler / alpha / vm.lisp
blobef2465691124fab35c520d8b8d17e5796c5fbb4d
1 ;;;; miscellaneous VM definition noise for the Alpha
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.
12 (in-package "SB!VM")
14 ;;;; defining the registers
16 (eval-when (:compile-toplevel :load-toplevel :execute)
17 (defvar *register-names* (make-array 32 :initial-element nil)))
19 (macrolet ((defreg (name offset)
20 (let ((offset-sym (symbolicate name "-OFFSET")))
21 `(eval-when (:compile-toplevel :load-toplevel :execute)
22 (def!constant ,offset-sym ,offset)
23 (setf (svref *register-names* ,offset-sym)
24 ,(symbol-name name)))))
25 (defregset (name &rest regs)
26 `(eval-when (:compile-toplevel :load-toplevel :execute)
27 (defparameter ,name
28 (list ,@(mapcar (lambda (name)
29 (symbolicate name "-OFFSET"))
30 regs))))))
31 ;; c.f. src/runtime/alpha-lispregs.h
33 ;; Ra
34 (defreg lip 0)
35 ;; Caller saved 0-7
36 (defreg a0 1)
37 (defreg a1 2)
38 (defreg a2 3)
39 (defreg a3 4)
40 (defreg a4 5)
41 (defreg a5 6)
42 (defreg l0 7)
43 (defreg nargs 8)
44 ;; Callee saved 0-6
45 (defreg csp 9)
46 (defreg cfp 10)
47 (defreg ocfp 11)
48 (defreg bsp 12)
49 (defreg lexenv 13)
50 (defreg code 14)
51 (defreg null 15)
52 ;; Arg 0-5
53 (defreg nl0 16)
54 (defreg nl1 17)
55 (defreg nl2 18)
56 (defreg nl3 19)
57 (defreg nl4 20)
58 (defreg nl5 21)
59 ;; Caller saved 8-11
60 (defreg alloc 22)
61 (defreg fdefn 23)
62 (defreg cfunc 24)
63 (defreg nfp 25)
64 ;; Ra
65 (defreg lra 26)
66 ;; Caller saved 12
67 (defreg l1 27)
68 ;; Assembler temp (at)
69 (defreg l2 28)
70 ;; Global pointer (gp)
71 (defreg gp 29)
72 ;; Stack pointer
73 (defreg nsp 30)
74 ;; Wired zero
75 (defreg zero 31)
77 (defregset non-descriptor-regs
78 nl0 nl1 nl2 nl3 nl4 nl5 nfp cfunc)
80 (defregset descriptor-regs
81 fdefn lexenv nargs ocfp lra a0 a1 a2 a3 a4 a5 l0 l1 l2)
83 (defregset *register-arg-offsets*
84 a0 a1 a2 a3 a4 a5)
85 (defparameter register-arg-names '(a0 a1 a2 a3 a4 a5)))
87 (define-storage-base registers :finite :size 32)
88 (define-storage-base float-registers :finite :size 64)
89 (define-storage-base control-stack :unbounded :size 8)
90 (define-storage-base non-descriptor-stack :unbounded :size 0)
91 (define-storage-base constant :non-packed)
92 (define-storage-base immediate-constant :non-packed)
94 ;;; a handy macro so we don't have to keep changing all the numbers
95 ;;; whenever we insert a new storage class.
97 (defmacro !define-storage-classes (&rest classes)
98 (do ((forms (list 'progn)
99 (let* ((class (car classes))
100 (sc-name (car class))
101 (constant-name (intern (concatenate 'simple-string
102 (string sc-name)
103 "-SC-NUMBER"))))
104 (list* `(define-storage-class ,sc-name ,index
105 ,@(cdr class))
106 `(def!constant ,constant-name ,index)
107 ;; (The CMU CL version of this macro did
108 ;; `(EXPORT ',CONSTANT-NAME)
109 ;; here, but in SBCL we try to have package
110 ;; structure described statically in one
111 ;; master source file, instead of building it
112 ;; dynamically by letting all the system code
113 ;; modify it as the system boots.)
114 forms)))
115 (index 0 (1+ index))
116 (classes classes (cdr classes)))
117 ((null classes)
118 (nreverse forms))))
120 (!define-storage-classes
122 ;; non-immediate constants in the constant pool
123 (constant constant)
125 ;; ZERO and NULL are in registers.
126 (zero immediate-constant)
127 (null immediate-constant)
128 (fp-single-zero immediate-constant)
129 (fp-double-zero immediate-constant)
131 ;; Anything else that can be an immediate.
132 (immediate immediate-constant)
135 ;; **** The stacks.
137 ;; The control stack. (Scanned by GC)
138 (control-stack control-stack)
140 ;; We put ANY-REG and DESCRIPTOR-REG early so that their SC-NUMBER
141 ;; is small and therefore the error trap information is smaller.
142 ;; Moving them up here from their previous place down below saves
143 ;; ~250K in core file size. --njf, 2006-01-27
145 ;; Immediate descriptor objects. Don't have to be seen by GC, but nothing
146 ;; bad will happen if they are. (fixnums, characters, header values, etc).
147 (any-reg
148 registers
149 :locations #.(append non-descriptor-regs descriptor-regs)
150 :constant-scs (zero immediate)
151 :save-p t
152 :alternate-scs (control-stack))
154 ;; Pointer descriptor objects. Must be seen by GC.
155 (descriptor-reg registers
156 :locations #.descriptor-regs
157 :constant-scs (constant null immediate)
158 :save-p t
159 :alternate-scs (control-stack))
161 ;; The non-descriptor stacks.
162 (signed-stack non-descriptor-stack
163 :element-size 2 :alignment 2) ; (signed-byte 64)
164 (unsigned-stack non-descriptor-stack
165 :element-size 2 :alignment 2) ; (unsigned-byte 64)
166 (character-stack non-descriptor-stack) ; non-descriptor characters.
167 (sap-stack non-descriptor-stack
168 :element-size 2 :alignment 2) ; System area pointers.
169 (single-stack non-descriptor-stack) ; single-floats
170 (double-stack non-descriptor-stack
171 :element-size 2 :alignment 2) ; double floats.
172 (complex-single-stack non-descriptor-stack :element-size 2)
173 (complex-double-stack non-descriptor-stack :element-size 4 :alignment 2)
176 ;; **** Things that can go in the integer registers.
178 ;; Non-Descriptor characters
179 (character-reg registers
180 :locations #.non-descriptor-regs
181 :constant-scs (immediate)
182 :save-p t
183 :alternate-scs (character-stack))
185 ;; Non-Descriptor SAP's (arbitrary pointers into address space)
186 (sap-reg registers
187 :locations #.non-descriptor-regs
188 :constant-scs (immediate)
189 :save-p t
190 :alternate-scs (sap-stack))
192 ;; Non-Descriptor (signed or unsigned) numbers.
193 (signed-reg registers
194 :locations #.non-descriptor-regs
195 :constant-scs (zero immediate)
196 :save-p t
197 :alternate-scs (signed-stack))
198 (unsigned-reg registers
199 :locations #.non-descriptor-regs
200 :constant-scs (zero immediate)
201 :save-p t
202 :alternate-scs (unsigned-stack))
204 ;; Random objects that must not be seen by GC. Used only as temporaries.
205 (non-descriptor-reg registers
206 :locations #.non-descriptor-regs)
208 ;; Pointers to the interior of objects. Used only as an temporary.
209 (interior-reg registers
210 :locations (#.lip-offset))
213 ;; **** Things that can go in the floating point registers.
215 ;; Non-Descriptor single-floats.
216 (single-reg float-registers
217 :locations #.(loop for i from 4 to 30 collect i)
218 :constant-scs (fp-single-zero)
219 :save-p t
220 :alternate-scs (single-stack))
222 ;; Non-Descriptor double-floats.
223 (double-reg float-registers
224 :locations #.(loop for i from 4 to 30 collect i)
225 :constant-scs (fp-double-zero)
226 :save-p t
227 :alternate-scs (double-stack))
229 (complex-single-reg float-registers
230 :locations #.(loop for i from 4 to 28 by 2 collect i)
231 :element-size 2
232 :constant-scs ()
233 :save-p t
234 :alternate-scs (complex-single-stack))
236 (complex-double-reg float-registers
237 :locations #.(loop for i from 4 to 28 by 2 collect i)
238 :element-size 2
239 :constant-scs ()
240 :save-p t
241 :alternate-scs (complex-double-stack))
243 (catch-block control-stack :element-size catch-block-size)
244 (unwind-block control-stack :element-size unwind-block-size))
246 ;;; Make some random tns for important registers.
247 (macrolet ((defregtn (name sc)
248 (let ((offset-sym (symbolicate name "-OFFSET"))
249 (tn-sym (symbolicate name "-TN")))
250 `(defparameter ,tn-sym
251 (make-random-tn :kind :normal
252 :sc (sc-or-lose ',sc)
253 :offset ,offset-sym)))))
255 ;; These, we access by foo-TN only
257 (defregtn zero any-reg)
258 (defregtn null descriptor-reg)
259 (defregtn code descriptor-reg)
260 (defregtn alloc any-reg)
261 (defregtn bsp any-reg)
262 (defregtn csp any-reg)
263 (defregtn cfp any-reg)
264 (defregtn nsp any-reg)
266 ;; These alias regular locations, so we have to make sure we don't bypass
267 ;; the register allocator when using them.
268 (defregtn nargs any-reg)
269 (defregtn ocfp any-reg)
270 (defregtn lip interior-reg))
272 ;; and some floating point values..
273 (defparameter fp-single-zero-tn
274 (make-random-tn :kind :normal
275 :sc (sc-or-lose 'single-reg)
276 :offset 31))
277 (defparameter fp-double-zero-tn
278 (make-random-tn :kind :normal
279 :sc (sc-or-lose 'double-reg)
280 :offset 31))
282 ;;; If value can be represented as an immediate constant, then return
283 ;;; the appropriate SC number, otherwise return NIL.
284 (defun immediate-constant-sc (value)
285 (typecase value
286 ((integer 0 0)
287 (sc-number-or-lose 'zero))
288 (null
289 (sc-number-or-lose 'null ))
290 ((or (integer #.sb!xc:most-negative-fixnum #.sb!xc:most-positive-fixnum)
291 character)
292 (sc-number-or-lose 'immediate ))
293 (symbol
294 (if (static-symbol-p value)
295 (sc-number-or-lose 'immediate )
296 nil))
297 (single-float
298 (if (eql value 0f0)
299 (sc-number-or-lose 'fp-single-zero )
300 nil))
301 (double-float
302 (if (eql value 0d0)
303 (sc-number-or-lose 'fp-double-zero )
304 nil))))
306 (defun boxed-immediate-sc-p (sc)
307 (or (eql sc (sc-number-or-lose 'zero))
308 (eql sc (sc-number-or-lose 'null))
309 (eql sc (sc-number-or-lose 'immediate))))
311 ;;; A predicate to see if a character can be used as an inline
312 ;;; constant (the immediate field in the instruction used is eight
313 ;;; bits wide, which is not the same as any defined subtype of
314 ;;; CHARACTER, as BASE-CHAR is seven bits wide).
315 (defun inlinable-character-constant-p (char)
316 (and (characterp char)
317 (< (char-code char) #x100)))
319 ;;;; function call parameters
321 ;;; the SC numbers for register and stack arguments/return values
322 (def!constant immediate-arg-scn (sc-number-or-lose 'any-reg))
323 (def!constant control-stack-arg-scn (sc-number-or-lose 'control-stack))
325 (eval-when (:compile-toplevel :load-toplevel :execute)
327 ;;; offsets of special stack frame locations
328 (def!constant ocfp-save-offset 0)
329 (def!constant lra-save-offset 1)
330 (def!constant nfp-save-offset 2)
332 ;;; the number of arguments/return values passed in registers
333 (def!constant register-arg-count 6)
335 ;;; (Names to use for the argument registers would go here, but there
336 ;;; are none.)
338 ); EVAL-WHEN
340 ;;; a list of TN's describing the register arguments
341 (defparameter *register-arg-tns*
342 (mapcar (lambda (n)
343 (make-random-tn :kind :normal
344 :sc (sc-or-lose 'descriptor-reg)
345 :offset n))
346 *register-arg-offsets*))
348 ;;; This is used by the debugger.
349 (def!constant single-value-return-byte-offset 4)
351 ;;; This function is called by debug output routines that want a
352 ;;; pretty name for a TN's location. It returns a thing that can be
353 ;;; printed with PRINC.
354 (defun location-print-name (tn)
355 ; (declare (type tn tn))
356 (let ((sb (sb-name (sc-sb (tn-sc tn))))
357 (offset (tn-offset tn)))
358 (ecase sb
359 (registers (or (svref *register-names* offset)
360 (format nil "R~D" offset)))
361 (float-registers (format nil "F~D" offset))
362 (control-stack (format nil "CS~D" offset))
363 (non-descriptor-stack (format nil "NS~D" offset))
364 (constant (format nil "Const~D" offset))
365 (immediate-constant "Immed"))))
367 (defun combination-implementation-style (node)
368 (declare (type sb!c::combination node) (ignore node))
369 (values :default nil))
371 (defun primitive-type-indirect-cell-type (ptype)
372 (declare (ignore ptype))
373 nil)