1 (in-package :sb-grovel)
3 ;;; borrowed from CMUCL manual, lightly ported
5 (defun array-data-address (array)
6 "Return the physical address of where the actual data of an array is
9 ARRAY must be a specialized array type - an array of one of these types:
20 (declare (type (or (array (signed-byte 8))
23 (array (signed-byte 16))
24 (array (signed-byte 32))
25 (array (unsigned-byte 8))
26 (array (unsigned-byte 16))
27 (array (unsigned-byte 32))
31 (optimize (speed 0) (debug 3) (safety 3)))
32 ;; with-array-data will get us to the actual data. However, because
33 ;; the array could have been displaced, we need to know where the
36 (let* ((type (car (multiple-value-list (array-element-type array))))
38 (cond ((or (equal type '(signed-byte 8))
39 (equal type 'cl::base-char)
40 (equal type '(unsigned-byte 8)))
42 ((or (equal type '(signed-byte 16))
43 (equal type '(unsigned-byte 16)))
45 ((or (equal type '(signed-byte 32))
46 (equal type '(unsigned-byte 32)))
48 ((equal type 'single-float)
50 ((equal type 'double-float)
52 (t (error "Unknown specialized array element type")))))
53 (sb-kernel::with-array-data ((data array)
56 (declare (ignore end))
57 ;; DATA is a specialized simple-array. Memory is laid out like this:
60 ;; 0 type code (e.g. 70 for double-float vector)
61 ;; 4 FIXNUMIZE(number of elements in vector)
62 ;; 8 1st element of vector
65 (let* ((addr (+ 8 (logandc1 7 (sb-kernel:get-lisp-obj-address data)))))
66 (declare (type (unsigned-byte 32) addr)
67 (optimize (speed 3) (safety 0)))
68 (sb-sys:int-sap (the (unsigned-byte 32)
69 (+ addr (* type-size start))))))))