sqrt causes consing ???
hi, i am trying to optimize some vector operations in lisp, and i seem to have run into a wall: ----------------------------8<---------------------------------- (deftype vec3f () `(simple-array single-float (3))) (defun make-vec3f (&rest args) (if args (make-array 3 :element-type 'single-float :initial-contents args) (make-array 3 :element-type 'single-float :initial-element 0.0f0))) (declaim (inline vec3f-length)) (defun vec3f-length (v) (declare (type vec3f v) (optimize (speed 3) (debug 0) (safety 0) (float 0))) (let* ((a0 (aref v 0)) (a1 (aref v 1)) (a2 (aref v 2)) (sq (+ (* a0 a0) (* a1 a1) (* a2 a2)))) (declare (type single-float a0 a1 a2 sq)) (the single-float (sqrt sq)))) (defun test () (declare (optimize (speed 3) (safety 0) (debug 0) (float 0))) (let ((v (make-vec3f 1.0 2.0 3.0))) (dotimes (i 1000000) (vec3f-length v)))) ----------------------------8<---------------------------------- running (time (test)) shows some considerable consing (approx 16 bytes per iteration). when i replace the "(sqrt sq)" with "sq", the consing stops. so i am guessing the sqrt case somehow boxes it's floats while the non-sqrt case does not. how do i get this to stop consing? i see this behaviour with lispworks professional 4.4.6 (linux) and lispworks personal 4.4.6(mac). regards, juergen -- Juergen Gmeiner <gj@gjdv.at>