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))
52 (defknown sap-ref-64 (system-area-pointer fixnum) (unsigned-byte 64)
55 (defknown %set-sap-ref-64 (system-area-pointer fixnum (unsigned-byte 64))
59 (defknown signed-sap-ref-8 (system-area-pointer fixnum) (signed-byte 8)
61 (defknown %set-signed-sap-ref-8 (system-area-pointer fixnum (signed-byte 8))
65 (defknown signed-sap-ref-16 (system-area-pointer fixnum) (signed-byte 16)
67 (defknown %set-signed-sap-ref-16 (system-area-pointer fixnum (signed-byte 16))
71 (defknown signed-sap-ref-32 (system-area-pointer fixnum) (signed-byte 32)
73 (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)
81 (defknown %set-signed-sap-ref-64 (system-area-pointer fixnum (signed-byte 64))
85 (defknown sap-ref-sap (system-area-pointer fixnum) system-area-pointer
87 (defknown %set-sap-ref-sap (system-area-pointer fixnum system-area-pointer)
91 (defknown sap-ref-single (system-area-pointer fixnum) single-float
93 (defknown sap-ref-double (system-area-pointer fixnum) double-float
95 #!+(or x86 long-float)
96 (defknown sap-ref-long (system-area-pointer fixnum) long-float
99 (defknown %set-sap-ref-single
100 (system-area-pointer fixnum single-float) single-float
102 (defknown %set-sap-ref-double
103 (system-area-pointer fixnum double-float) double-float
106 (defknown %set-sap-ref-long
107 (system-area-pointer fixnum long-float) long-float
110 ;;;; transforms for converting sap relation operators
112 (macrolet ((def (sap-fun int-fun)
113 `(deftransform ,sap-fun ((x y) * *)
114 `(,',int-fun (sap-int x) (sap-int y)))))
121 ;;;; transforms for optimizing SAP+
123 (deftransform sap+ ((sap offset))
124 (cond ((and (constant-continuation-p offset)
125 (eql (continuation-value offset) 0))
128 (extract-fun-args sap 'sap+ 2)
129 '(lambda (sap offset1 offset2)
130 (sap+ sap (+ offset1 offset2))))))
132 (macrolet ((def (fun)
133 `(deftransform ,fun ((sap offset) * *)
134 (extract-fun-args sap 'sap+ 2)
135 `(lambda (sap offset1 offset2)
136 (,',fun sap (+ offset1 offset2))))))
139 (def signed-sap-ref-8)
140 (def %set-signed-sap-ref-8)
142 (def %set-sap-ref-16)
143 (def signed-sap-ref-16)
144 (def %set-signed-sap-ref-16)
146 (def %set-sap-ref-32)
147 (def signed-sap-ref-32)
148 (def %set-signed-sap-ref-32)
150 (def %set-sap-ref-sap)
152 (def %set-sap-ref-single)
154 (def %set-sap-ref-double)
155 ;; The original CMUCL code had #!+(and x86 long-float) for this first one,
156 ;; but only #!+long-float for the second. This was redundant, since the
157 ;; LONG-FLOAT target feature only exists on X86. So we removed the
158 ;; redundancy. --njf 2002-01-08
159 #!+long-float (def sap-ref-long)
160 #!+long-float (def %set-sap-ref-long))