source: trunk/source/level-0/l0-utils.lisp @ 15601

Last change on this file since 15601 was 15093, checked in by gb, 8 years ago

New Linux ARM binaries.

The image and FASL versions changed on the ARM, but (if I did it right)
not on other platforms.

(The image and FASL versions are now architecture-specific. This may
make it somewhat easier and less disruptive to change them, since the
motivation for such a change is often also architecture-specific.)
The FASL and current image version are defined (in the "TARGET" package)
in the architecture-specific *-arch.lisp files; the min, max, and current
image versions are defined in the *constants*.h file for the architecture.

Most of the changes are ARM-specific.

Each TCR now contains a 256-word table at byte offset 256. (We've
been using about 168 bytes in the TCR, so there are still 88 bytes/22
words left for expansion.) The table is initialized at TCR-creation
time to contain the absolute addresses of the subprims (there are
currently around 130 defined); we try otherwise not to reference
subprims by absolute address. Jumping to a subprim is:

(ldr pc (:@ rcontext (:$ offset-of-subprim-in-tcr-table)))

and calling one involves loading its address from that table into a
register and doing (blx reg). We canonically use LR as the register,
since it's going to be clobbered by the blx anyway and there doesn't
seem to be a performance hazard there. The old scheme (which involved
using BA and BLA pseudoinstructions to jump to/call a hidden jump table
at the end of the function) is no longer supported.

ARM Subprims no longer need to be aligned (on anything more than an
instruction boundary.) Some remnants of the consequences of an old
scheme (where subprims had to "fit" in small regions and sometimes
had to jump out of line if they would overflow that region's bounds)
still remain, but we can repair that (and it'll be a bit more straightforward
to add new ARM subprims.) We no longer care (much) about where subprims
are mapped in memory, and don't have to bias suprimitive addresses by
a platform-specific constant (and have to figure out whether or not we've
already done so) on (e.g.) Android.

Rather than setting the first element (fn.entrypoint) of a
newly-created function to the (absolute) address of a subprim that updates
that entrypoint on the first call, we use a little LAP function to correct
the address before the function can be called.

Non-function objects that can be stored in symbols' function cells
(the UNDEFINED-FUNCTION object, the things that encapsulate
special-operator names and global macro-functions) need to be
structured like FUNCTIONS: the need to have a word-aligned entrypoint
in element 0 that tracks the CODE-VECTOR object in element 1. We
don't want these things to be of type FUNCTION, but do want the GC to
adjust the entrypoint if the codevector moves. We've been essentially
out of GVECTOR subtags on 32-bit platforms, largely because of the
constraints that vector/array subtags must be greater than other
subtags and numeric types be less. The first constraint is probably
reasonable, but the second isn't: other typecodes (tag-list, etc) may
be less than the maximum numeric typecode, so tests like NUMBERP can't
reliably involve a simple comparison. (As long as a mask of all
numeric typecodes will fit in a machine word/FIXNUM, a simple LOGBITP
test can be used instead.) Removed all portable and ARM-specific code
that made assumptions about numeric typecode ordering, made a few more
gvector typecodes available, and used one of them to define a new
"pseudofunction" type. Made the GC update the entrypoints of
pseudofunctions and used them for the undefined-function object and
for the function cells of macros/special-operators.

Since we don't need the subprim jump table at the end of each function
anymore, we can more easily revive the idea of embedded pc-relative
constant data ("constant pools") and initialize FPRs from constant
data, avoiding most remaining traffic between FPRs and GPRs.

I've had a fairly-reproducible cache-coherency problem: on the first
GC in the cold load, the thread misbehaves mysteriously when it
resumes. The GC tries to synchronize the I and D caches on the entire
range of addresses that may contain newly-moved code-vectors. I'm not
at all sure why, but walking that range and flushing the cache for
each code-vector individually seems to avoid the problem (and may actually
be faster.)

Fix ticket:894

Fixed a few typos in error messages/comments/etc.

I -think- that the non-ARM-specific changes (how FASL/image versions are
defined) should bootstrap cleanly, but won't know for sure until this is
committed. (I imagine that the buildbot will complain if not.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1; -*- Mode: Lisp;  Package: CCL; -*-
2;;;
3;;;   Copyright (C) 2009 Clozure Associates
4;;;   Copyright (C) 1994-2001 Digitool, Inc
5;;;   This file is part of Clozure CL. 
6;;;
7;;;   Clozure CL is licensed under the terms of the Lisp Lesser GNU Public
8;;;   License , known as the LLGPL and distributed with Clozure CL as the
9;;;   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,
10;;;   which is distributed with Clozure CL as the file "LGPL".  Where these
11;;;   conflict, the preamble takes precedence. 
12;;;
13;;;   Clozure CL is referenced in the preamble as the "LIBRARY."
14;;;
15;;;   The LLGPL is also available online at
16;;;   http://opensource.franz.com/preamble.html
17
18
19
20; l0-utils.lisp
21
22
23(in-package "CCL")
24
25(defun %proclaim-notspecial (sym)
26  (%symbol-bits sym (logandc2 (%symbol-bits sym) (ash 1 $sym_bit_special))))
27
28
29(defun heap-area-name (code)
30  (cond ((eq code area-void) :void)
31        ((eq code area-cstack) :cstack)
32        ((eq code area-vstack) :vstack)
33        ((eq code area-tstack) :tstack)
34        ((eq code area-readonly) :readonly)
35        ((eq code area-watched) :watched)
36        ((eq code area-managed-static) :managed-static)
37        ((eq code area-static) :static)
38        ((eq code area-dynamic) :dynamic)
39        (t code)))
40
41(defun heap-area-code (name)
42  (case name
43    (:void area-void)
44    (:cstack area-cstack)
45    (:vstack area-vstack)
46    (:tstack area-tstack)
47    (:readonly area-readonly)
48    (:watched area-watched)
49    (:managed-static area-managed-static)
50    (:static area-static)
51    (:dynamic area-dynamic)
52    (t (if (and (fixnump name)
53                (<= area-readonly name area-dynamic))
54         name
55         (heap-area-code (require-type name '(member :void :cstack :vstack :tstack
56                                                     :readonly :managed-static :static :dynamic)))))))
57
58
59;;; We MAY need a scheme for finding all of the areas in a lisp library.
60(defun %map-areas (function &optional area)
61  (let* ((area (cond ((or (eq area t) (eq area nil)) nil)
62                     ((consp area) (mapcar #'heap-area-code area)) ;; list of areas
63                     (t (heap-area-code area))))
64         (mincode area-readonly)
65         (maxcode area-dynamic))
66  (declare (fixnum maxcode mincode))
67  (do* ((a (%normalize-areas) (%lisp-word-ref a (ash target::area.succ (- target::fixnumshift))))
68        (code area-dynamic (%lisp-word-ref a (ash target::area.code (- target::fixnumshift))))
69        (dynamic t nil))
70       ((= code area-void))
71    (declare (fixnum code))
72    (if (and (<= code maxcode)
73             (>= code mincode)
74             (or (null area)
75                 (eql code area)
76                 (and (consp area) (member code area))))
77      (if dynamic 
78        (walk-dynamic-area a function)
79        (unless (= code area-dynamic)        ; ignore egc areas, 'cause walk-dynamic-area sees them.
80          (walk-static-area a function)))))))
81
82
83;;; there'll be functions in static lib areas.
84;;; (Well, there would be if there were really static lib areas.)
85
86(defun %map-lfuns (f)
87  (let* ((filter #'(lambda (obj) (when (= (the fixnum (typecode obj))
88                                          target::subtag-function)
89                                   (funcall f (lfun-vector-lfun obj))))))
90    (declare (dynamic-extent filter))
91    (%map-areas filter '(:dynamic :static :managed-static :readonly))))
92
93
94(defun ensure-simple-string (s)
95  (cond ((simple-string-p s) s)
96        ((stringp s)
97         (let* ((len (length s))
98                (new (make-string len :element-type 'base-char)))
99           (declare (fixnum len)(optimize (speed 3)(safety 0)))
100           (multiple-value-bind (ss offset) (array-data-and-offset s)
101             (%copy-ivector-to-ivector ss (ash offset 2) new 0 (ash len 2)))
102           new))
103        (t (report-bad-arg s 'string))))
104
105(defun nremove (elt list)
106  (let* ((handle (cons nil list))
107         (splice handle))
108    (declare (dynamic-extent handle))
109    (loop
110      (if (eq elt (car (%cdr splice)))
111        (unless (setf (%cdr splice) (%cddr splice)) (return))
112        (unless (cdr (setq splice (%cdr splice)))
113          (return))))
114    (%cdr handle)))
115
116
117(eval-when (:compile-toplevel :execute)
118  (defmacro need-use-eql-macro (key)
119    `(let* ((typecode (typecode ,key)))
120       (declare (fixnum typecode))
121       (or (= typecode target::subtag-macptr)
122            (and (< typecode (- target::nbits-in-word target::fixnumshift))
123         (logbitp (the (integer 0 (#.(- target::nbits-in-word target::fixnumshift)))
124                    typecode)
125                  (logior (ash 1 target::tag-fixnum)
126                          (ash 1 target::subtag-bignum)
127                          (ash 1 target::subtag-single-float)
128                          (ash 1 target::subtag-double-float)
129                          (ash 1 target::subtag-ratio)
130                          (ash 1 target::subtag-complex)))))))
131
132)
133
134(defun asseql (item list)
135  (if (need-use-eql-macro item)
136    (dolist (pair list)
137      (if pair
138        (if (eql item (car pair))
139          (return pair))))
140    (assq item list)))
141
142(defun assequal (item list)
143  (dolist (pair list)
144    (if pair
145      (if (equal item (car pair))
146        (return pair)))))
147
148
149;;; (memeql item list) <=> (member item list :test #'eql :key #'identity)
150(defun memeql (item list)
151  (if (need-use-eql-macro item)
152    (do* ((l list (%cdr l)))
153         ((endp l))
154      (when (eql (%car l) item) (return l)))
155    (memq item list)))
156
157(defun memequal (item list)
158  (do* ((l list (%cdr l)))
159       ((endp l))
160    (when (equal (%car l) item) (return l))))
161
162
163; (member-test item list test-fn)
164;   <=>
165;     (member item list :test test-fn :key #'identity)
166(defun member-test (item list test-fn)
167  (if (or (eq test-fn 'eq)(eq test-fn  #'eq)
168          (and (or (eq test-fn 'eql)(eq test-fn  #'eql))
169               (not (need-use-eql-macro item))))
170    (do* ((l list (cdr l)))
171         ((null l))
172      (when (eq item (car l))(return l)))
173    (if (or (eq test-fn 'eql)(eq test-fn  #'eql))
174      (do* ((l list (cdr l)))
175           ((null l))
176        (when (eql item (car l))(return l)))   
177      (do* ((l list (cdr l)))
178           ((null l))
179        (when (funcall test-fn item (car l)) (return l))))))
180
181(defun s32->u32 (s32)
182  (%stack-block ((buf 4))
183    (setf (%get-signed-long buf) s32)
184    (%get-unsigned-long buf)))
185
186(defun u32->s32 (u32)
187  (%stack-block ((buf 4))
188    (setf (%get-unsigned-long buf) u32)
189    (%get-signed-long buf)))
190
191
192; end
Note: See TracBrowser for help on using the repository browser.