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.
16 (defknown foreign-symbol-address (simple-string) system-area-pointer
19 (defknown (sap< sap<= sap= sap>= sap>)
20 (system-area-pointer system-area-pointer) boolean
23 (defknown sap+ (system-area-pointer integer) system-area-pointer
25 (defknown sap- (system-area-pointer system-area-pointer) (signed-byte 32)
28 (defknown sap-int (system-area-pointer) (unsigned-byte #!-alpha 32 #!+alpha 64)
30 (defknown int-sap ((unsigned-byte #!-alpha 32 #!+alpha 64))
31 system-area-pointer (movable))
33 (defknown sap-ref-8 (system-area-pointer fixnum) (unsigned-byte 8)
35 (defknown %set-sap-ref-8 (system-area-pointer fixnum (unsigned-byte 8))
39 (defknown sap-ref-16 (system-area-pointer fixnum) (unsigned-byte 16)
41 (defknown %set-sap-ref-16 (system-area-pointer fixnum (unsigned-byte 16))
45 (defknown sap-ref-32 (system-area-pointer fixnum) (unsigned-byte 32)
47 (defknown %set-sap-ref-32 (system-area-pointer fixnum (unsigned-byte 32))
51 ;; FIXME These are supported natively on alpha and using deftransforms
52 ;; in compiler/x86/sap.lisp, which in OAO$n$ style need copying to
53 ;; other 32 bit systems
54 (defknown sap-ref-64 (system-area-pointer fixnum) (unsigned-byte 64)
56 (defknown %set-sap-ref-64 (system-area-pointer fixnum (unsigned-byte 64))
60 (defknown signed-sap-ref-8 (system-area-pointer fixnum) (signed-byte 8)
62 (defknown %set-signed-sap-ref-8 (system-area-pointer fixnum (signed-byte 8))
66 (defknown signed-sap-ref-16 (system-area-pointer fixnum) (signed-byte 16)
68 (defknown %set-signed-sap-ref-16 (system-area-pointer fixnum (signed-byte 16))
72 (defknown signed-sap-ref-32 (system-area-pointer fixnum) (signed-byte 32)
74 (defknown %set-signed-sap-ref-32 (system-area-pointer fixnum (signed-byte 32))
78 (defknown signed-sap-ref-64 (system-area-pointer fixnum) (signed-byte 64)
80 (defknown %set-signed-sap-ref-64 (system-area-pointer fixnum (signed-byte 64))
84 (defknown sap-ref-sap (system-area-pointer fixnum) system-area-pointer
86 (defknown %set-sap-ref-sap (system-area-pointer fixnum system-area-pointer)
90 (defknown sap-ref-single (system-area-pointer fixnum) single-float
92 (defknown sap-ref-double (system-area-pointer fixnum) double-float
94 #!+(or x86 long-float)
95 (defknown sap-ref-long (system-area-pointer fixnum) long-float
98 (defknown %set-sap-ref-single
99 (system-area-pointer fixnum single-float) single-float
101 (defknown %set-sap-ref-double
102 (system-area-pointer fixnum double-float) double-float
105 (defknown %set-sap-ref-long
106 (system-area-pointer fixnum long-float) long-float
109 ;;;; transforms for converting sap relation operators
111 (macrolet ((def (sap-fun int-fun)
112 `(deftransform ,sap-fun ((x y) * *)
113 `(,',int-fun (sap-int x) (sap-int y)))))
120 ;;;; transforms for optimizing SAP+
122 (deftransform sap+ ((sap offset))
123 (cond ((and (constant-lvar-p offset)
124 (eql (lvar-value offset) 0))
127 (extract-fun-args sap 'sap+ 2)
128 '(lambda (sap offset1 offset2)
129 (sap+ sap (+ offset1 offset2))))))
131 (macrolet ((def (fun)
132 `(deftransform ,fun ((sap offset) * *)
133 (extract-fun-args sap 'sap+ 2)
134 `(lambda (sap offset1 offset2)
135 (,',fun sap (+ offset1 offset2))))))
138 (def signed-sap-ref-8)
139 (def %set-signed-sap-ref-8)
141 (def %set-sap-ref-16)
142 (def signed-sap-ref-16)
143 (def %set-signed-sap-ref-16)
145 (def %set-sap-ref-32)
146 (def signed-sap-ref-32)
147 (def %set-signed-sap-ref-32)
149 (def %set-sap-ref-64)
150 (def signed-sap-ref-64)
151 (def %set-signed-sap-ref-64)
153 (def %set-sap-ref-sap)
155 (def %set-sap-ref-single)
157 (def %set-sap-ref-double)
158 ;; The original CMUCL code had #!+(and x86 long-float) for this first one,
159 ;; but only #!+long-float for the second. This was redundant, since the
160 ;; LONG-FLOAT target feature only exists on X86. So we removed the
161 ;; redundancy. --njf 2002-01-08
162 #!+long-float (def sap-ref-long)
163 #!+long-float (def %set-sap-ref-long))