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 (dolist (info '((sap< <) (sap<= <=) (sap= =) (sap>= >=) (sap> >)))
113 (destructuring-bind (sap-fun int-fun) info
114 (deftransform sap-fun ((x y) '* '* :eval-name t)
115 `(,int-fun (sap-int x) (sap-int y)))))
117 ;;;; transforms for optimizing SAP+
119 (deftransform sap+ ((sap offset))
120 (cond ((and (constant-continuation-p offset)
121 (eql (continuation-value offset) 0))
124 (extract-function-args sap 'sap+ 2)
125 '(lambda (sap offset1 offset2)
126 (sap+ sap (+ offset1 offset2))))))
128 (dolist (fun '(sap-ref-8 %set-sap-ref-8
129 signed-sap-ref-8 %set-signed-sap-ref-8
130 sap-ref-16 %set-sap-ref-16
131 signed-sap-ref-16 %set-signed-sap-ref-16
132 sap-ref-32 %set-sap-ref-32
133 signed-sap-ref-32 %set-signed-sap-ref-32
134 sap-ref-sap %set-sap-ref-sap
135 sap-ref-single %set-sap-ref-single
136 sap-ref-double %set-sap-ref-double
137 #!+(or x86 long-float) sap-ref-long
138 #!+long-float %set-sap-ref-long))
139 (deftransform fun ((sap offset) '* '* :eval-name t)
140 (extract-function-args sap 'sap+ 2)
141 `(lambda (sap offset1 offset2)
142 (,fun sap (+ offset1 offset2)))))