Tweaks to get sb-simd 1.3 to compile
[sbcl/simd.git] / src / compiler / mips / vm.lisp
blob9030f90567104a413581c765b19b85372e0eec0c
1 ;;;; miscellaneous VM definition noise for MIPS
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")
15 ;;;; Registers
17 (eval-when (:compile-toplevel :load-toplevel :execute)
18 (defvar *register-names* (make-array 32 :initial-element nil)))
20 (macrolet ((defreg (name offset)
21 (let ((offset-sym (symbolicate name "-OFFSET")))
22 `(eval-when (:compile-toplevel :load-toplevel :execute)
23 (def!constant ,offset-sym ,offset)
24 (setf (svref *register-names* ,offset-sym) ,(symbol-name name)))))
26 (defregset (name &rest regs)
27 `(eval-when (:compile-toplevel :load-toplevel :execute)
28 (defparameter ,name
29 (list ,@(mapcar #'(lambda (name) (symbolicate name "-OFFSET")) regs))))))
30 ;; Wired zero register.
31 (defreg zero 0) ; NULL
32 ;; Reserved for assembler use.
33 (defreg nl3 1) ; untagged temporary 3
34 ;; C return registers.
35 (defreg cfunc 2) ; FF function address, wastes a register
36 (defreg nl4 3) ; PA flag
37 ;; C argument registers.
38 (defreg nl0 4) ; untagged temporary 0
39 (defreg nl1 5) ; untagged temporary 1
40 (defreg nl2 6) ; untagged temporary 2
41 (defreg nargs 7) ; number of function arguments
42 ;; C unsaved temporaries.
43 (defreg a0 8) ; function arg 0
44 (defreg a1 9) ; function arg 1
45 (defreg a2 10) ; function arg 2
46 (defreg a3 11) ; function arg 3
47 (defreg a4 12) ; function arg 4
48 (defreg a5 13) ; function arg 5
49 (defreg fdefn 14) ; ?
50 (defreg lexenv 15) ; wastes a register
51 ;; C saved registers.
52 (defreg nfp 16) ; non-lisp frame pointer
53 (defreg ocfp 17) ; caller's control frame pointer
54 (defreg lra 18) ; tagged Lisp return address
55 (defreg l0 19) ; tagged temporary 0
56 (defreg null 20) ; NIL
57 (defreg bsp 21) ; binding stack pointer
58 (defreg cfp 22) ; control frame pointer
59 (defreg csp 23) ; control stack pointer
60 ;; More C unsaved temporaries.
61 (defreg l1 24) ; tagged temporary 1
62 (defreg alloc 25) ; ALLOC pointer
63 ;; 26 and 27 are used by the system kernel.
64 ;; 28 is the global pointer of our C runtime, and used for
65 ;; jump/branch relaxation in Lisp.
66 (defreg nsp 29) ; number (native) stack pointer
67 ;; C frame pointer, or additional saved register.
68 (defreg code 30) ; current function object
69 ;; Return link register.
70 (defreg lip 31) ; Lisp interior pointer
72 (defregset non-descriptor-regs
73 nl0 nl1 nl2 nl3 nl4 cfunc nargs)
75 (defregset descriptor-regs
76 a0 a1 a2 a3 a4 a5 fdefn lexenv nfp ocfp lra l0 l1)
78 (defregset *register-arg-offsets*
79 a0 a1 a2 a3 a4 a5)
81 (defregset reserve-descriptor-regs
82 fdefn lexenv)
84 (defregset reserve-non-descriptor-regs
85 nl4 cfunc))
88 ;;;; SB and SC definition:
90 (define-storage-base registers :finite :size 32)
91 (define-storage-base float-registers :finite :size 32)
92 (define-storage-base control-stack :unbounded :size 8)
93 (define-storage-base non-descriptor-stack :unbounded :size 0)
94 (define-storage-base constant :non-packed)
95 (define-storage-base immediate-constant :non-packed)
97 ;;;
98 ;;; Handy macro so we don't have to keep changing all the numbers whenever
99 ;;; we insert a new storage class.
101 (defmacro !define-storage-classes (&rest classes)
102 (do ((forms (list 'progn)
103 (let* ((class (car classes))
104 (sc-name (car class))
105 (constant-name (intern (concatenate 'simple-string
106 (string sc-name)
107 "-SC-NUMBER"))))
108 (list* `(define-storage-class ,sc-name ,index
109 ,@(cdr class))
110 `(defconstant ,constant-name ,index)
111 `(export ',constant-name)
112 forms)))
113 (index 0 (1+ index))
114 (classes classes (cdr classes)))
115 ((null classes)
116 (nreverse forms))))
118 (def!constant kludge-nondeterministic-catch-block-size 7)
120 (!define-storage-classes
122 ;; Non-immediate constants in the constant pool
123 (constant constant)
125 ;; Immediate constant.
126 (null immediate-constant)
127 (zero immediate-constant)
128 (immediate immediate-constant)
130 ;; **** The stacks.
132 ;; The control stack. (Scanned by GC)
133 (control-stack control-stack)
135 ;; We put ANY-REG and DESCRIPTOR-REG early so that their SC-NUMBER
136 ;; is small and therefore the error trap information is smaller.
137 ;; Moving them up here from their previous place down below saves
138 ;; ~250K in core file size. --njf, 2006-01-27
140 ;; Immediate descriptor objects. Don't have to be seen by GC, but nothing
141 ;; bad will happen if they are. (fixnums, characters, header values, etc).
142 (any-reg
143 registers
144 :locations #.(append non-descriptor-regs descriptor-regs)
145 :reserve-locations #.(append reserve-non-descriptor-regs
146 reserve-descriptor-regs)
147 :constant-scs (constant zero immediate)
148 :save-p t
149 :alternate-scs (control-stack))
151 ;; Pointer descriptor objects. Must be seen by GC.
152 (descriptor-reg registers
153 :locations #.descriptor-regs
154 :reserve-locations #.reserve-descriptor-regs
155 :constant-scs (constant null immediate)
156 :save-p t
157 :alternate-scs (control-stack))
159 ;; The non-descriptor stacks.
160 (signed-stack non-descriptor-stack) ; (signed-byte 32)
161 (unsigned-stack non-descriptor-stack) ; (unsigned-byte 32)
162 (character-stack non-descriptor-stack) ; non-descriptor characters.
163 (sap-stack non-descriptor-stack) ; System area pointers.
164 (single-stack non-descriptor-stack) ; single-floats
165 (double-stack non-descriptor-stack :element-size 2) ; double floats.
166 ;; complex-single-floats
167 (complex-single-stack non-descriptor-stack :element-size 2)
168 ;; complex-double-floats.
169 (complex-double-stack non-descriptor-stack :element-size 4 :alignment 2)
172 ;; **** Things that can go in the integer registers.
174 ;; Non-Descriptor characters
175 (character-reg registers
176 :locations #.non-descriptor-regs
177 :reserve-locations #.reserve-non-descriptor-regs
178 :constant-scs (immediate)
179 :save-p t
180 :alternate-scs (character-stack))
182 ;; Non-Descriptor SAP's (arbitrary pointers into address space)
183 (sap-reg registers
184 :locations #.non-descriptor-regs
185 :reserve-locations #.reserve-non-descriptor-regs
186 :constant-scs (immediate)
187 :save-p t
188 :alternate-scs (sap-stack))
190 ;; Non-Descriptor (signed or unsigned) numbers.
191 (signed-reg registers
192 :locations #.non-descriptor-regs
193 :reserve-locations #.reserve-non-descriptor-regs
194 :constant-scs (zero immediate)
195 :save-p t
196 :alternate-scs (signed-stack))
197 (unsigned-reg registers
198 :locations #.non-descriptor-regs
199 :reserve-locations #.reserve-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 (0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30)
218 :reserve-locations (26 28 30)
219 :constant-scs ()
220 :save-p t
221 :alternate-scs (single-stack))
223 ;; Non-Descriptor double-floats.
224 (double-reg float-registers
225 :locations (0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30)
226 :reserve-locations (26 28 30)
227 ;; Note: we don't bother with the element size, 'cause nothing can be
228 ;; allocated in the odd fp regs anyway.
229 :constant-scs ()
230 :save-p t
231 :alternate-scs (double-stack))
233 (complex-single-reg float-registers
234 :locations (0 4 8 12 16 20 24 28)
235 :element-size 4
236 :reserve-locations (24 28)
237 :constant-scs ()
238 :save-p t
239 :alternate-scs (complex-single-stack))
241 (complex-double-reg float-registers
242 :locations (0 4 8 12 16 20 24 28)
243 :element-size 4
244 :reserve-locations (24 28)
245 :constant-scs ()
246 :save-p t
247 :alternate-scs (complex-double-stack))
249 ;; A catch or unwind block.
250 (catch-block control-stack :element-size kludge-nondeterministic-catch-block-size)
252 ;; floating point numbers temporarily stuck in integer registers for c-call
253 (single-int-carg-reg registers
254 :locations (4 5 6 7)
255 :alternate-scs ()
256 :constant-scs ())
257 (double-int-carg-reg registers
258 :locations (4 6)
259 :constant-scs ()
260 :alternate-scs ()
261 :alignment 2 ;is this needed?
262 :element-size 2))
267 ;;;; Random TNs for interesting registers
269 (macrolet ((defregtn (name sc)
270 (let ((offset-sym (symbolicate name "-OFFSET"))
271 (tn-sym (symbolicate name "-TN")))
272 `(defparameter ,tn-sym
273 (make-random-tn :kind :normal
274 :sc (sc-or-lose ',sc)
275 :offset ,offset-sym)))))
276 (defregtn zero any-reg)
277 (defregtn nargs any-reg)
279 (defregtn fdefn descriptor-reg)
280 (defregtn lexenv descriptor-reg)
282 (defregtn nfp any-reg)
283 (defregtn ocfp any-reg)
285 (defregtn null descriptor-reg)
287 (defregtn bsp any-reg)
288 (defregtn cfp any-reg)
289 (defregtn csp any-reg)
290 (defregtn alloc any-reg)
291 (defregtn nsp any-reg)
293 (defregtn code descriptor-reg)
294 (defregtn lip interior-reg))
296 ;;; If VALUE can be represented as an immediate constant, then return the
297 ;;; appropriate SC number, otherwise return NIL.
298 (!def-vm-support-routine immediate-constant-sc (value)
299 (typecase value
300 ((integer 0 0)
301 (sc-number-or-lose 'zero))
302 (null
303 (sc-number-or-lose 'null))
304 (symbol
305 (if (static-symbol-p value)
306 (sc-number-or-lose 'immediate)
307 nil))
308 ((or (integer #.sb!xc:most-negative-fixnum #.sb!xc:most-positive-fixnum)
309 system-area-pointer character)
310 (sc-number-or-lose 'immediate))
311 (system-area-pointer
312 (sc-number-or-lose 'immediate))
313 (character
314 (sc-number-or-lose 'immediate))))
317 ;;;; Function Call Parameters
319 ;;; The SC numbers for register and stack arguments/return values.
321 (defconstant register-arg-scn (meta-sc-number-or-lose 'descriptor-reg))
322 (defconstant immediate-arg-scn (meta-sc-number-or-lose 'any-reg))
323 (defconstant control-stack-arg-scn (meta-sc-number-or-lose 'control-stack))
325 (eval-when (:compile-toplevel :load-toplevel :execute)
327 ;;; Offsets of special stack frame locations
328 (defconstant ocfp-save-offset 0)
329 (defconstant lra-save-offset 1)
330 (defconstant nfp-save-offset 2)
332 ;;; The number of arguments/return values passed in registers.
334 (defconstant register-arg-count 6)
336 ;;; The offsets within the register-arg SC that we pass values in, first
337 ;;; value first.
340 ;;; Names to use for the argument registers.
342 (defconstant-eqx register-arg-names '(a0 a1 a2 a3 a4 a5) #'equal)
344 ) ; EVAL-WHEN
347 ;;; A list of TN's describing the register arguments.
349 (defparameter *register-arg-tns*
350 (mapcar #'(lambda (n)
351 (make-random-tn :kind :normal
352 :sc (sc-or-lose 'descriptor-reg)
353 :offset n))
354 *register-arg-offsets*))
356 ;;; This is used by the debugger.
357 (defconstant single-value-return-byte-offset 8)
359 ;;; This function is called by debug output routines that want a pretty name
360 ;;; for a TN's location. It returns a thing that can be printed with PRINC.
361 (!def-vm-support-routine location-print-name (tn)
362 (declare (type tn tn))
363 (let ((sb (sb-name (sc-sb (tn-sc tn))))
364 (offset (tn-offset tn)))
365 (ecase sb
366 (registers (or (svref *register-names* offset)
367 (format nil "R~D" offset)))
368 (float-registers (format nil "F~D" offset))
369 (control-stack (format nil "CS~D" offset))
370 (non-descriptor-stack (format nil "NS~D" offset))
371 (constant (format nil "Const~D" offset))
372 (immediate-constant "Immed"))))
374 (!def-vm-support-routine combination-implementation-style (node)
375 (declare (type sb!c::combination node) (ignore node))
376 (values :default nil))