vsum   xtlang


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

Implementation

(bind-func vsum
  (lambda (buf:i64* len:i64)
    (let ((tot 0) (i 0))
      (if (> len 1)
        (let ((chunks (/ len 2)) (vbuf:/2,i64/* (cast buf)) (vtot:/2,i64/* (salloc)))
          (vfill! vtot 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))))
        (set! len (& len 1))
        (set! buf (pref-ptr buf (* i 2)))))
      (dotimes (i len)
        (set! tot (+ tot (pref buf i))))
      tot)))


Back to Index

Similar Entries