src/fvec.c: use macros for single/double precision, prefere memset/memcpy over Accelerate
authorPaul Brossier <piem@piem.org>
Thu, 3 Sep 2015 07:21:19 +0000 (09:21 +0200)
committerPaul Brossier <piem@piem.org>
Thu, 3 Sep 2015 07:21:19 +0000 (09:21 +0200)
src/fvec.c

index ee2f867..abdf3d1 100644 (file)
 
 #ifdef HAVE_ACCELERATE
 #include <Accelerate/Accelerate.h>
+#if !HAVE_AUBIO_DOUBLE
+#define aubio_vDSP_mmov       vDSP_mmov
+#define aubio_vDSP_vmul       vDSP_vmul
+#define aubio_vDSP_vfill      vDSP_vfill
+#else /* HAVE_AUBIO_DOUBLE */
+#define aubio_vDSP_mmov       vDSP_mmovD
+#define aubio_vDSP_vmul       vDSP_vmulD
+#define aubio_vDSP_vfill      vDSP_vfillD
+#endif /* HAVE_AUBIO_DOUBLE */
 #endif
 
 fvec_t * new_fvec( uint_t length) {
@@ -70,27 +79,19 @@ void fvec_set_all (fvec_t *s, smpl_t val) {
     s->data[j] = val;
   }
 #else
-#if !HAVE_AUBIO_DOUBLE
-  vDSP_vfill(&val, s->data, 1, s->length);
-#else /* HAVE_AUBIO_DOUBLE */
-  vDSP_vfillD(&val, s->data, 1, s->length);
-#endif /* HAVE_AUBIO_DOUBLE */
+  aubio_vDSP_vfill(&val, s->data, 1, s->length);
 #endif
 }
 
 void fvec_zeros(fvec_t *s) {
-#ifndef HAVE_ACCELERATE
-#if HAVE_MEMCPY_HACKS
+#if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
+  fvec_set_all (s, 0.);
+#else
+#if defined(HAVE_MEMCPY_HACKS)
   memset(s->data, 0, s->length * sizeof(smpl_t));
 #else
-  fvec_set_all (s, 0.);
+  aubio_vDSP_vclr(s->data, 1, s->length);
 #endif
-#else
-#if !HAVE_AUBIO_DOUBLE
-  vDSP_vclr(s->data, 1, s->length);
-#else /* HAVE_AUBIO_DOUBLE */
-  vDSP_vclrD(s->data, 1, s->length);
-#endif /* HAVE_AUBIO_DOUBLE */
 #endif
 }
 
@@ -113,11 +114,7 @@ void fvec_weight(fvec_t *s, fvec_t *weight) {
     s->data[j] *= weight->data[j];
   }
 #else
-#if !HAVE_AUBIO_DOUBLE
-  vDSP_vmul(s->data, 1, weight->data, 1, s->data, 1, s->length);
-#else /* HAVE_AUBIO_DOUBLE */
-  vDSP_vmulD(s->data, 1, weight->data, 1, s->data, 1, s->length);
-#endif /* HAVE_AUBIO_DOUBLE */
+  aubio_vDSP_vmul(s->data, 1, weight->data, 1, s->data, 1, s->length);
 #endif /* HAVE_ACCELERATE */
 }
 
@@ -127,20 +124,16 @@ void fvec_copy(fvec_t *s, fvec_t *t) {
         s->length, t->length);
     return;
   }
-#ifndef HAVE_ACCELERATE
-#if HAVE_MEMCPY_HACKS
-  memcpy(t->data, s->data, t->length * sizeof(smpl_t));
-#else
+#if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
   uint_t j;
   for (j=0; j< t->length; j++) {
     t->data[j] = s->data[j];
   }
-#endif
 #else
-#if !HAVE_AUBIO_DOUBLE
-  vDSP_mmov(s->data, t->data, 1, s->length, 1, 1);
-#else /* HAVE_AUBIO_DOUBLE */
-  vDSP_mmovD(s->data, t->data, 1, s->length, 1, 1);
-#endif /* HAVE_AUBIO_DOUBLE */
-#endif /* HAVE_ACCELERATE */
+#if defined(HAVE_MEMCPY_HACKS)
+  memcpy(t->data, s->data, t->length * sizeof(smpl_t));
+#else
+  aubio_vDSP_mmov(s->data, t->data, 1, s->length, 1, 1);
+#endif
+#endif
 }