src/{fvec,fmat}.c: use memcpy and memset to optimise when possible, add option to...
authorPaul Brossier <piem@piem.org>
Tue, 26 Nov 2013 03:44:17 +0000 (04:44 +0100)
committerPaul Brossier <piem@piem.org>
Tue, 26 Nov 2013 03:44:17 +0000 (04:44 +0100)
src/fmat.c
src/fvec.c
src/lvec.c
wscript

index a6d8931..8ff00e7 100644 (file)
@@ -86,7 +86,11 @@ void fmat_set(fmat_t *s, smpl_t val) {
 }
 
 void fmat_zeros(fmat_t *s) {
+#if HAVE_MEMCPY_HACKS
+  memset(s->data, 0, s->height * s->length * sizeof(smpl_t));
+#else
   fmat_set(s, 0.);
+#endif
 }
 
 void fmat_ones(fmat_t *s) {
@@ -113,21 +117,25 @@ void fmat_weight(fmat_t *s, fmat_t *weight) {
 }
 
 void fmat_copy(fmat_t *s, fmat_t *t) {
-  uint_t i,j;
-  uint_t height = MIN(s->height, t->height);
-  uint_t length = MIN(s->length, t->length);
   if (s->height != t->height) {
-    AUBIO_ERR("warning, trying to copy %d rows to %d rows \n", 
+    AUBIO_ERR("trying to copy %d rows to %d rows \n",
             s->height, t->height);
+    return;
   }
   if (s->length != t->length) {
-    AUBIO_ERR("warning, trying to copy %d columns to %d columns\n", 
+    AUBIO_ERR("trying to copy %d columns to %d columns\n",
             s->length, t->length);
+    return;
   }
-  for (i=0; i< height; i++) {
-    for (j=0; j< length; j++) {
+#if HAVE_MEMCPY_HACKS
+  memcpy(t->data, s->data, t->height * t->length * sizeof(smpl_t));
+#else
+  uint_t i,j;
+  for (i=0; i< t->height; i++) {
+    for (j=0; j< t->length; j++) {
       t->data[i][j] = s->data[i][j];
     }
   }
+#endif
 }
 
index ea33b58..e62810e 100644 (file)
@@ -63,7 +63,11 @@ void fvec_set(fvec_t *s, smpl_t val) {
 }
 
 void fvec_zeros(fvec_t *s) {
+#if HAVE_MEMCPY_HACKS
+  memset(s->data, 0, s->length * sizeof(smpl_t));
+#else
   fvec_set(s, 0.);
+#endif
 }
 
 void fvec_ones(fvec_t *s) {
@@ -86,14 +90,17 @@ void fvec_weight(fvec_t *s, fvec_t *weight) {
 }
 
 void fvec_copy(fvec_t *s, fvec_t *t) {
-  uint_t j;
-  uint_t length = t->length;
   if (s->length != t->length) {
-    AUBIO_WRN("trying to copy %d elements to %d elements \n",
+    AUBIO_ERR("trying to copy %d elements to %d elements \n",
         s->length, t->length);
-    length = MIN(s->length, t->length);
+    return;
   }
-  for (j=0; j< length; j++) {
+#if HAVE_MEMCPY_HACKS
+  memcpy(t->data, s->data, t->length * sizeof(smpl_t));
+#else
+  uint_t j;
+  for (j=0; j< t->length; j++) {
     t->data[j] = s->data[j];
   }
+#endif
 }
index 4fb40cd..c906d57 100644 (file)
@@ -66,7 +66,11 @@ void lvec_set(lvec_t *s, smpl_t val) {
 }
 
 void lvec_zeros(lvec_t *s) {
+#if HAVE_MEMCPY_HACKS
+  memset(s->data, 0, s->length * sizeof(lsmp_t));
+#else
   lvec_set(s, 0.);
+#endif
 }
 
 void lvec_ones(lvec_t *s) {
diff --git a/wscript b/wscript
index 47e31b2..6513c52 100644 (file)
--- a/wscript
+++ b/wscript
@@ -58,6 +58,9 @@ def options(ctx):
           help_str = 'compile with sndfile (auto)', help_disable_str = 'disable sndfile')
   add_option_enable_disable(ctx, 'samplerate', default = None,
           help_str = 'compile with samplerate (auto)', help_disable_str = 'disable samplerate')
+  add_option_enable_disable(ctx, 'memcpy', default = True,
+          help_str = 'use memcpy hacks (default)',
+          help_disable_str = 'do not use memcpy hacks')
   add_option_enable_disable(ctx, 'double', default = False,
           help_str = 'compile aubio in double precision mode',
           help_disable_str = 'compile aubio in single precision mode (default)')
@@ -182,6 +185,12 @@ def configure(ctx):
   else:
     ctx.msg('Checking for FFT implementation', 'ooura')
 
+  # use memcpy hacks
+  if (ctx.options.enable_memcpy == True):
+    ctx.define('HAVE_MEMCPY_HACKS', 1)
+  else:
+    ctx.define('HAVE_MEMCPY_HACKS', 0)
+
   if (ctx.options.enable_jack != False):
     ctx.check_cfg(package = 'jack', atleast_version = '0.15.0',
     args = '--cflags --libs', mandatory = False)