|
134 | 134 | (alexandria:once-only (x)
|
135 | 135 | `(logior ,x (- (mask-field (byte 1 (1- ,size)) ,x)))))
|
136 | 136 |
|
| 137 | +(defmacro negative-to-twos-complement/8 (x) |
| 138 | + (alexandria:once-only (x) |
| 139 | + `(progn |
| 140 | + (assert (< ,x 0)) |
| 141 | + (logand (+ 1 (logxor (- ,x) #xFF)) #xFF)))) |
| 142 | + |
| 143 | +(defmacro negative-to-twos-complement/16 (x) |
| 144 | + (alexandria:once-only (x) |
| 145 | + `(progn |
| 146 | + (assert (< ,x 0)) |
| 147 | + (logand (+ 1 (logxor (- ,x) #xFFFF)) #xFFFF)))) |
| 148 | + |
| 149 | +(defmacro negative-to-twos-complement/32 (x) |
| 150 | + (alexandria:once-only (x) |
| 151 | + `(progn |
| 152 | + (assert (< ,x 0)) |
| 153 | + (logand (+ 1 (logxor (- ,x) #xFFFFFFFF)) #xFFFFFFFF)))) |
| 154 | + |
137 | 155 | (defmacro negative-to-twos-complement/64 (x)
|
138 | 156 | (alexandria:once-only (x)
|
139 | 157 | `(progn
|
140 | 158 | (assert (< ,x 0))
|
141 | 159 | (logand (+ 1 (logxor (- ,x) #xFFFFFFFFFFFFFFFF)) #xFFFFFFFFFFFFFFFF))))
|
142 | 160 |
|
| 161 | +(defmacro signed-sap-ref-8 (sap offset) |
| 162 | + #+sbcl `(sb-sys:signed-sap-ref-8 ,sap ,offset) |
| 163 | + #-(or sbcl allegro) `(cffi:mem-ref ,sap :int8 ,offset) |
| 164 | + #+allegro `(mask-signed (sap-ref-8 ,sap ,offset) 8)) |
| 165 | + |
| 166 | +(defmacro signed-sap-ref-16 (sap offset) |
| 167 | + #+sbcl `(sb-sys:signed-sap-ref-16 ,sap ,offset) |
| 168 | + #-(or sbcl allegro) `(cffi:mem-ref ,sap :int16 ,offset) |
| 169 | + #+allegro `(mask-signed (sap-ref-16 ,sap ,offset) 16)) |
| 170 | + |
| 171 | +(defmacro signed-sap-ref-32 (sap offset) |
| 172 | + #+sbcl `(sb-sys:signed-sap-ref-32 ,sap ,offset) |
| 173 | + #-(or sbcl allegro) `(cffi:mem-ref ,sap :int32 ,offset) |
| 174 | + #+allegro `(mask-signed (sap-ref-32 ,sap ,offset) 32)) |
| 175 | + |
143 | 176 | (defmacro signed-sap-ref-64 (sap offset)
|
144 | 177 | #+sbcl `(sb-sys:signed-sap-ref-64 ,sap ,offset)
|
145 | 178 | #-(or sbcl allegro) `(cffi:mem-ref ,sap :int64 ,offset)
|
146 | 179 | #+allegro `(mask-signed (sap-ref-64 ,sap ,offset) 64))
|
147 | 180 |
|
| 181 | +(defmacro set-signed-sap-ref-8 (sap offset value) |
| 182 | + #+sbcl `(setf (sb-sys:signed-sap-ref-8 ,sap ,offset) ,value) |
| 183 | + #-(or sbcl allegro) `(setf (cffi:mem-ref ,sap :int8 ,offset) ,value) |
| 184 | + #+allegro |
| 185 | + (alexandria:once-only (sap offset value) |
| 186 | + ` (set-sap-ref-8 ,sap ,offset |
| 187 | + (if (< ,value 0) |
| 188 | + (negative-to-twos-complement/8 ,value) |
| 189 | + ,value)))) |
| 190 | + |
| 191 | +(defmacro set-signed-sap-ref-16 (sap offset value) |
| 192 | + #+sbcl `(setf (sb-sys:signed-sap-ref-16 ,sap ,offset) ,value) |
| 193 | + #-(or sbcl allegro) `(setf (cffi:mem-ref ,sap :int16 ,offset) ,value) |
| 194 | + #+allegro |
| 195 | + (alexandria:once-only (sap offset value) |
| 196 | + ` (set-sap-ref-16 ,sap ,offset |
| 197 | + (if (< ,value 0) |
| 198 | + (negative-to-twos-complement/16 ,value) |
| 199 | + ,value)))) |
| 200 | + |
| 201 | +(defmacro set-signed-sap-ref-32 (sap offset value) |
| 202 | + #+sbcl `(setf (sb-sys:signed-sap-ref-32 ,sap ,offset) ,value) |
| 203 | + #-(or sbcl allegro) `(setf (cffi:mem-ref ,sap :int32 ,offset) ,value) |
| 204 | + #+allegro |
| 205 | + (alexandria:once-only (sap offset value) |
| 206 | + ` (set-sap-ref-32 ,sap ,offset |
| 207 | + (if (< ,value 0) |
| 208 | + (negative-to-twos-complement/32 ,value) |
| 209 | + ,value)))) |
| 210 | + |
148 | 211 | (defmacro set-signed-sap-ref-64 (sap offset value)
|
149 | 212 | #+sbcl `(setf (sb-sys:signed-sap-ref-64 ,sap ,offset) ,value)
|
150 | 213 | #-(or sbcl allegro) `(setf (cffi:mem-ref ,sap :int64 ,offset) ,value)
|
|
0 commit comments