[Ecls-list] Integer dot product

Waldek Hebisch hebisch at math.uni.wroc.pl
Wed Sep 2 01:47:58 UTC 2009


The following file at safety 0 in 64-bit sbcl produces inline code
(with no function calls in inner loop).  However, in ecl operations
are done via function calls.  If I replace types with specified
accuracy by fixnum array access, addition and multiplication
is done via inline code.  However, I would like to avoid
overhead for untagging values and extra space taken by
fixnums on 64-bit machines.  Also, fixnum accuracy on 32-bit
machines is too low, so I have to specify 64-bit type.

I wonder how much effort it would take to generate inline
code for 32-bit and 64-bit types.  I looked at sysfun.lsp
and it seems that before defining inline I need a correct
"representation types".

Remark: For the specific code I could probably put all code
in a single C inline.  But I would like to compose several
similar functions using macros...

----------------<cut here>---------------------------

;;; (proclaim '(optimize (speed 3) (safety 0)))

;;; Vectors of 32-bit numbers

(defmacro ELT32(v i)
    `(aref (the (simple-array (unsigned-byte 32) (*)) ,v) ,i))

;;; (x*y + z) using 32-bit x and y and 64-bit z and assuming that
;;; intermediate results fits into 64 bits
(defmacro QSMULADD64-32 (x y z)
    `(the (unsigned-byte 64)
         (+ (the (unsigned-byte 64)
               (* (the (unsigned-byte 32) ,x)
                  (the (unsigned-byte 32) ,y)))
            (the (unsigned-byte 64) ,z))))

(defmacro QSMUL64-32 (x y)
    `(the (unsigned-byte 64)
         (* (the (unsigned-byte 32) ,x)
            (the (unsigned-byte 32) ,y))))


(defmacro QSMOD64-32 (x p)
    `(the (unsigned-byte 32)
         (rem (the (unsigned-byte 64) ,x) (the (unsigned-byte 32) ,p))))

(defmacro QSPLUS (x y)
    `(the fixnum (+ (the fixnum ,x) (the fixnum ,y))))

(defmacro QMODDOT0 (eltfun varg1 varg2 ind1 ind2 kk s0 p)
    `(let ((s ,s0)
           (v1 ,varg1)
           (v2 ,varg2)
           (i1 ,ind1)
           (i2 ,ind2)
           (k0 ,kk)
           (k 0))
          (declare (type (unsigned-byte 64) s)
                   (type fixnum i1 i2 k k0))
          (prog ()
             l1
              (if (>= k k0) (return (QSMOD64-32 s ,p)))
              (setf s (QSMULADD64-32 (,eltfun v1 (QSPLUS i1 k))
                                     (,eltfun v2 (QSPLUS i2 k))
                                     s))
              (setf k (QSPLUS k 1))
              (go l1))))

(defmacro QMODDOT32 (v1 v2 ind1 ind2 kk s0 p)
     `(QMODDOT0 ELT32 ,v1 ,v2 ,ind1 ,ind2 ,kk ,s0 ,p))

(defun |myDot| (v1 v2 ind1 ind2 kk s0 p) (QMODDOT32 v1 v2 ind1 ind2 kk s0 p))

-----------------------<cut here>----------------------------------------

-- 
                              Waldek Hebisch
hebisch at math.uni.wroc.pl 




More information about the ecl-devel mailing list