vsum   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/core/math.xtm

Implementation

(bind-func vsum
  (lambda (buf:float* len:i64)
    (let ((tot:float 0.) (i 0))
      (if (> len 3)
        (let ((chunks (/ len 4)) (vbuf:/4,float/* (cast buf)) (vtot:/4,float/* (salloc)))
          (vfill! vtot 0. 0. 0. 0.)
          (let ((totref (pref vtot 0)))
            (dotimes (i chunks)
              (set! totref (+ totref (pref-ptr vbuf i))))
            (set! tot (+ (vref totref 0) (vref totref 1) (vref totref 2) (vref totref 3))))
          (set! len (& len 3))
          (set! buf (pref-ptr buf (* i 4)))))
      (dotimes (i len)
        (set! tot (+ tot (pref buf i))))
      tot)))


Back to Index

Similar Entries