source: branches/1.2-devel/ccl/compiler/reg.lisp @ 15278

Last change on this file since 15278 was 3302, checked in by gb, 14 years ago

Constants again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1;;;-*- Mode: Lisp; Package: CCL-*-
2;;;
3;;;   Copyright (C) 1994-2001 Digitool, Inc
4;;;   This file is part of OpenMCL. 
5;;;
6;;;   OpenMCL is licensed under the terms of the Lisp Lesser GNU Public
7;;;   License , known as the LLGPL and distributed with OpenMCL as the
8;;;   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,
9;;;   which is distributed with OpenMCL as the file "LGPL".  Where these
10;;;   conflict, the preamble takes precedence. 
11;;;
12;;;   OpenMCL is referenced in the preamble as the "LIBRARY."
13;;;
14;;;   The LLGPL is also available online at
15;;;   http://opensource.franz.com/preamble.html
16(in-package "CCL")
17
18;;; A "register spec" is a fixnum.  Bit 28 is clear; bits 24-26
19;;; (inclusive) define the type of register-spec in question.  Of
20;;; course, a register spec can also be a "logical register" (lreg)
21;;; structure.  Someday soon, these might totally replace the fixnum
22;;; "hard regspecs" that're described in this file, and might be used
23;;; to refer to stack-based values as well as registers.  In the
24;;; meantime, we have to bootstrap a bit.
25
26(defmacro register-spec-p (regspec)
27  `(%register-spec-p ,regspec))
28
29(defun %register-spec-p (regspec)
30  (if (typep regspec 'fixnum)
31    (not (logbitp 28 (the fixnum regspec)))
32    (typep regspec 'lreg)))
33
34(defconstant regspec-type-byte (byte 3 24))
35(defmacro regspec-type (regspec)
36  `(%regspec-type ,regspec))
37
38(defun %regspec-type (regspec)
39  (if (typep regspec 'fixnum)
40    (the fixnum (ldb regspec-type-byte (the fixnum regspec)))
41    (if (typep regspec 'lreg)
42      (the fixnum (lreg-type regspec))
43      (error "bad regspec: ~s" regspec))))
44
45;;; Physical registers.
46;;; A regspec-type of 0 denotes some type of "physical" (machine) register:
47;;; a GPR, FPR, CR field, CR bit, or SPR.
48(defconstant regspec-hard-reg-type 0)
49; There are at most 32 members of any class of hard reg, so bytes 5-8 are
50; used to encode that information; the "value" of the hard reg in question
51; is in bits 0-4.
52; In some cases, we can also attach a "mode" to a hard-reg-spec.
53; Usually, non-0 values of the "mode" field are attached to the
54; "imm" (unboxed) registers.
55; A GPR whose "mode" is hard-reg-class-gpr-mode-node can have a "type"
56; field which asserts that the register's contents map onto one or more
57; of the primitive non-node types.  This information can help some of
58; the functions that copy between GPRs of different "mode" elide some
59; type-checking.
60(defconstant regspec-hard-reg-type-value-byte (byte 8 0))
61(defconstant regspec-hard-reg-type-class-byte (byte 3 8))
62(defconstant regspec-hard-reg-type-mode-byte (byte 4 11))
63(defconstant regspec-hard-reg-type-type-byte (byte 8 15))
64
65(defconstant hard-reg-class-gpr 0)
66(defconstant hard-reg-class-fpr 1)
67; This is ppc-specific
68(defconstant hard-reg-class-crf 2)      ; Value is one of 0, 4, 8, ... 28
69(defconstant hard-reg-class-crbit 3)
70(defconstant hard-reg-class-spr 4)
71
72; "mode" values for GPRs.
73(defconstant hard-reg-class-gpr-mode-node 0)    ; a tagged lisp object
74(defconstant hard-reg-class-gpr-mode-u32 1)     ; unboxed unsigned 32-bit value
75(defconstant hard-reg-class-gpr-mode-s32 2)     ; unboxed signed 32-bit value
76(defconstant hard-reg-class-gpr-mode-u16 3)     ; unboxed unsigned 16-bit value
77(defconstant hard-reg-class-gpr-mode-s16 4)     ; unboxed signed 16-bit value
78(defconstant hard-reg-class-gpr-mode-u8 5)      ; unboxed unsigned 8-bit value
79(defconstant hard-reg-class-gpr-mode-s8 6)      ; unboxed signed 8-bit value
80(defconstant hard-reg-class-gpr-mode-address 7) ; unboxed unsigned 32-bit address
81(defconstant hard-reg-class-gpr-mode-u64 8)
82(defconstant hard-reg-class-gpr-mode-s64 9)
83
84(defconstant hard-reg-class-gpr-mode-invalid -1) ; Never a valid mode.
85
86; "mode" values for FPRs.
87(defconstant hard-reg-class-fpr-mode-double 0)          ; unboxed IEEE double
88(defconstant hard-reg-class-fpr-mode-single 1)          ; unboxed IEEE single
89
90; "type" values for FPRs - type of SOURCE may be encoded herein
91(defconstant hard-reg-class-fpr-type-double 0)          ;  IEEE double
92(defconstant hard-reg-class-fpr-type-single 1)          ; IEEE single
93
94
95(defmacro set-regspec-mode (regspec mode)
96  `(%set-regspec-mode ,regspec ,mode))
97
98(defun %set-regspec-mode (regspec mode)
99  (if (typep regspec 'fixnum)
100    (dpb (the fixnum mode) regspec-hard-reg-type-mode-byte regspec)
101    (if (typep regspec 'lreg)
102      (progn (setf (lreg-mode regspec) mode) regspec)
103      (error "bad regspec: ~s" regspec))))
104
105(defmacro get-regspec-mode (regspec)
106  `(%get-regspec-mode ,regspec))
107
108(defun %get-regspec-mode (regspec)
109  (if (typep regspec 'fixnum)
110    (ldb regspec-hard-reg-type-mode-byte regspec)
111    (if (typep regspec 'lreg)
112      (lreg-mode regspec)
113      (error "bad regspec: ~s" regspec))))
114
115
116(defmacro node-regspec-type-modes (modes)
117  `(the fixnum (logior ,@(mapcar #'(lambda (x) `(ash 1 ,x)) modes))))
118
119(defmacro set-node-regspec-type-modes (regspec &rest modes)
120  `(%set-node-regspec-type-modes ,regspec (node-regspec-type-modes ,modes)))
121
122(defun %set-node-regspec-type-modes (regspec modes)
123  (if (typep regspec 'fixnum)
124    (dpb (the fixnum modes) regspec-hard-reg-type-type-byte (the fixnum regspec))
125    (if (typep regspec 'lreg)
126      (progn (setf (lreg-type regspec) modes) regspec)
127      (error "bad regspec: ~s" regspec))))
128
129(defmacro get-node-regspec-type-modes (regspec)
130  `(%get-regspec-type-modes ,regspec))
131
132(defun %get-regspec-type-modes (regspec)
133  (if (typep regspec 'fixnum)
134    (ldb regspec-hard-reg-type-type-byte (the fixnum regspec))
135    (if (typep regspec 'lreg)
136      (lreg-type regspec)
137      (error "bad regspec: ~s" regspec))))
138
139(defmacro hard-reg-class-mask (&rest classes)
140  `(the fixnum (logior ,@(mapcar #'(lambda (x) `(ash 1 ,x)) classes))))
141
142(defconstant hard-reg-class-gpr-mask (hard-reg-class-mask hard-reg-class-gpr))
143(defconstant hard-reg-class-gpr-crf-mask (hard-reg-class-mask hard-reg-class-gpr hard-reg-class-crf))
144
145; Assuming that "regspec" denotes a physical register, return its class.
146(defmacro hard-regspec-class (regspec)
147  `(%hard-regspec-class ,regspec))
148
149(defun %hard-regspec-class (regspec)
150  (if (typep regspec 'fixnum)
151    (the fixnum (ldb regspec-hard-reg-type-class-byte (the fixnum regspec)))
152    (if (typep regspec 'lreg)
153      (lreg-class regspec)
154      (error "bad regspec: ~s" regspec))))
155
156; Return physical regspec's value:
157(defmacro hard-regspec-value (regspec)
158  `(%hard-regspec-value ,regspec))
159
160(defun %hard-regspec-value (regspec)
161  (if (typep regspec 'fixnum)
162    (the fixnum (ldb regspec-hard-reg-type-value-byte (the fixnum regspec)))
163    (if (typep regspec 'lreg)
164      (lreg-value regspec)
165      (error "bad regspec: ~s" regspec))))
166
167;;; Logical (as opposed to "physical") registers are represented by structures
168;;; of type LREG.  The structures let us track information about assignments
169;;; and references to lregs, and the indirection lets us defer decisions about
170;;; storage mapping (register assignment, etc.) until later.
171
172;; A GPR which is allowed to hold any lisp object (but NOT an object header.)
173(defconstant regspec-lisp-reg-type 1)
174
175;; A GPR which is allowed to contain any -non- lisp object.
176(defconstant regspec-unboxed-reg-type 2)
177
178;; A GPR which can contain either an immediate lisp object (fixnum, immediate)
179;; or any non-lisp object.
180(defconstant regspec-any-gpr-reg-type (logior regspec-lisp-reg-type regspec-unboxed-reg-type))
181
182;; An FPR.  All FPRs are created equal; there's no reason to
183;; worry about whether an FPR's holding a 32 or 64-bit float.
184(defconstant regspec-fpr-reg-type 4)
185
186;; One of the 8 fields of the Condition Register.
187(defconstant regspec-crf-reg-type 5)
188
189;; One of the 32 bits of the Condition Register.
190(defconstant regspec-crbit-reg-type 6)
191
192(defmacro make-hard-crf-reg (crf)
193  `(dpb hard-reg-class-crf regspec-hard-reg-type-class-byte (the fixnum ,crf)))
194 
195(defmacro make-hard-fp-reg (regnum &optional (mode hard-reg-class-fpr-mode-double))
196  `(dpb (the fixnum ,mode) 
197        regspec-hard-reg-type-mode-byte 
198        (dpb hard-reg-class-fpr regspec-hard-reg-type-class-byte (the fixnum ,regnum))))
199 
200;;; "Memory specs" have bit 28 set.  Since bit 28 is the sign bit in 68K MCL,
201;;; we have to be a little careful when creating them to ensure that the result
202;;; is a fixnum.
203
204(defmacro memory-spec-p (thing)
205  `(if (typep ,thing 'fixnum) (logbitp 28 (the fixnum ,thing))))
206
207(defmacro make-memory-spec (thing)
208  `(logior (ash -1 28) (the fixnum ,thing)))
209
210;;; Bits 24-26 (inclusive) of a memory-spec define the type of memory-spec in question.
211(defconstant memspec-type-byte (byte 3 24))
212(defmacro memspec-type (memspec)
213  `(ldb memspec-type-byte (the fixnum ,memspec)))
214
215;;; A slot in the value-stack frame.  This needs to get interpreted
216;;; relative to the top of the vsp.  The low 15 bits denote the
217;;; offset in the frame; the low 2 bits are always clear, since the
218;;; vstack is always aligned on a 32-bit boundary.
219(defconstant memspec-frame-address 0)
220
221
222;;; Address-specs - whether memory- or register-based - might be used to indicate the
223;;; canonical address of a variable.  Sometimes, this address is actually the address
224;;; of a "value cell" object; if so, bit 27 will be set in the indicated address.
225
226(defun addrspec-vcell-p (x)
227  (logbitp 27 x))
228
229(defmacro make-vcell-memory-spec (x)
230  `(logior (ash 1 27) (the fixnum ,x)))
231
232(defmacro memspec-frame-address-offset (m)
233  `(logand (the fixnum ,m) #xffff))
234
235
236(provide "REG")
Note: See TracBrowser for help on using the repository browser.