1 ;;;; optimizations for SAP operations
3 ;;;; This software is part of the SBCL system. See the README file for
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.
17 (deftransform foreign-symbol-address ((symbol &optional datap) (simple-string boolean))
18 (if (and (constant-lvar-p symbol) (constant-lvar-p datap))
19 `(sap-int (foreign-symbol-sap symbol datap))
20 (give-up-ir1-transform)))
22 (deftransform foreign-symbol-sap ((symbol &optional datap)
23 (simple-string &optional boolean))
26 (give-up-ir1-transform)
27 `(foreign-symbol-sap symbol))
29 (if (and (constant-lvar-p symbol) (constant-lvar-p datap))
30 (let ((name (lvar-value symbol))
31 (datap (lvar-value datap)))
32 (if (or #+sb-xc-host t ; only static symbols on host
34 (find-foreign-symbol-in-table name *static-foreign-symbols*))
35 `(foreign-symbol-sap ,name) ; VOP
36 `(foreign-symbol-dataref-sap ,name))) ; VOP
37 (give-up-ir1-transform)))
39 (defknown (sap< sap<= sap= sap>= sap>)
40 (system-area-pointer system-area-pointer) boolean
43 (defknown sap+ (system-area-pointer integer) system-area-pointer
45 (defknown sap- (system-area-pointer system-area-pointer)
46 (signed-byte #.sb!vm::n-word-bits)
49 (defknown sap-int (system-area-pointer)
50 (unsigned-byte #.sb!vm::n-machine-word-bits)
52 (defknown int-sap ((unsigned-byte #.sb!vm::n-machine-word-bits))
53 system-area-pointer (movable))
55 (defknown sap-ref-8 (system-area-pointer fixnum) (unsigned-byte 8)
57 (defknown %set-sap-ref-8 (system-area-pointer fixnum (unsigned-byte 8))
61 (defknown sap-ref-16 (system-area-pointer fixnum) (unsigned-byte 16)
63 (defknown %set-sap-ref-16 (system-area-pointer fixnum (unsigned-byte 16))
67 (defknown sap-ref-32 (system-area-pointer fixnum) (unsigned-byte 32)
69 (defknown %set-sap-ref-32 (system-area-pointer fixnum (unsigned-byte 32))
73 ;; FIXME These are supported natively on alpha and using deftransforms
74 ;; in compiler/x86/sap.lisp, which in OAO$n$ style need copying to
75 ;; other 32 bit systems
76 (defknown sap-ref-64 (system-area-pointer fixnum) (unsigned-byte 64)
78 (defknown %set-sap-ref-64 (system-area-pointer fixnum (unsigned-byte 64))
82 (defknown sap-ref-word (system-area-pointer fixnum)
83 (unsigned-byte #.sb!vm::n-machine-word-bits)
85 (defknown %set-sap-ref-word
86 (system-area-pointer fixnum (unsigned-byte #.sb!vm::n-machine-word-bits))
87 (unsigned-byte #.sb!vm::n-machine-word-bits)
90 (defknown signed-sap-ref-8 (system-area-pointer fixnum) (signed-byte 8)
92 (defknown %set-signed-sap-ref-8 (system-area-pointer fixnum (signed-byte 8))
96 (defknown signed-sap-ref-16 (system-area-pointer fixnum) (signed-byte 16)
98 (defknown %set-signed-sap-ref-16 (system-area-pointer fixnum (signed-byte 16))
102 (defknown signed-sap-ref-32 (system-area-pointer fixnum) (signed-byte 32)
104 (defknown %set-signed-sap-ref-32 (system-area-pointer fixnum (signed-byte 32))
108 (defknown signed-sap-ref-64 (system-area-pointer fixnum) (signed-byte 64)
110 (defknown %set-signed-sap-ref-64 (system-area-pointer fixnum (signed-byte 64))
114 (defknown signed-sap-ref-word (system-area-pointer fixnum)
115 (signed-byte #.sb!vm::n-machine-word-bits)
117 (defknown %set-signed-sap-ref-word
118 (system-area-pointer fixnum (signed-byte #.sb!vm::n-machine-word-bits))
119 (signed-byte #.sb!vm::n-machine-word-bits)
122 (defknown sap-ref-sap (system-area-pointer fixnum) system-area-pointer
124 (defknown %set-sap-ref-sap (system-area-pointer fixnum system-area-pointer)
128 (defknown sap-ref-single (system-area-pointer fixnum) single-float
130 (defknown sap-ref-double (system-area-pointer fixnum) double-float
132 #!+(or x86 long-float)
133 (defknown sap-ref-long (system-area-pointer fixnum) long-float
136 (defknown %set-sap-ref-single
137 (system-area-pointer fixnum single-float) single-float
139 (defknown %set-sap-ref-double
140 (system-area-pointer fixnum double-float) double-float
143 (defknown %set-sap-ref-long
144 (system-area-pointer fixnum long-float) long-float
147 ;;;; transforms for converting sap relation operators
149 (macrolet ((def (sap-fun int-fun)
150 `(deftransform ,sap-fun ((x y) * *)
151 `(,',int-fun (sap-int x) (sap-int y)))))
158 ;;;; transforms for optimizing SAP+
160 (deftransform sap+ ((sap offset))
161 (cond ((and (constant-lvar-p offset)
162 (eql (lvar-value offset) 0))
165 (extract-fun-args sap 'sap+ 2)
166 '(lambda (sap offset1 offset2)
167 (sap+ sap (+ offset1 offset2))))))
169 (macrolet ((def (fun)
170 `(deftransform ,fun ((sap offset) * *)
171 (extract-fun-args sap 'sap+ 2)
172 `(lambda (sap offset1 offset2)
173 (,',fun sap (+ offset1 offset2))))))
176 (def signed-sap-ref-8)
177 (def %set-signed-sap-ref-8)
179 (def %set-sap-ref-16)
180 (def signed-sap-ref-16)
181 (def %set-signed-sap-ref-16)
183 (def %set-sap-ref-32)
184 (def signed-sap-ref-32)
185 (def %set-signed-sap-ref-32)
187 (def %set-sap-ref-64)
188 (def signed-sap-ref-64)
189 (def %set-signed-sap-ref-64)
191 (def %set-sap-ref-sap)
193 (def %set-sap-ref-single)
195 (def %set-sap-ref-double)
196 ;; The original CMUCL code had #!+(and x86 long-float) for this first one,
197 ;; but only #!+long-float for the second. This was redundant, since the
198 ;; LONG-FLOAT target feature only exists on X86. So we removed the
199 ;; redundancy. --njf 2002-01-08
200 #!+long-float (def sap-ref-long)
201 #!+long-float (def %set-sap-ref-long))
203 (macrolet ((def (fun args 32-bit 64-bit)
204 `(deftransform ,fun (,args)
205 (ecase sb!vm::n-word-bits
206 (32 '(,32-bit ,@args))
207 (64 '(,64-bit ,@args))))))
208 (def sap-ref-word (sap offset) sap-ref-32 sap-ref-64)
209 (def signed-sap-ref-word (sap offset) signed-sap-ref-32 signed-sap-ref-64)
210 (def %set-sap-ref-word (sap offset value)
211 %set-sap-ref-32 %set-sap-ref-64)
212 (def %set-signed-sap-ref-word (sap offset value)
213 %set-signed-sap-ref-32 %set-signed-sap-ref-64))