ref: 923a7a8011ed28c4759b62e70598d3de91f5eeec
parent: 2dbcafa73126b9cb800721d77e478eab617bb84c
author: Paul Brossier <[email protected]>
date: Mon Nov 25 23:44:17 EST 2013
src/{fvec,fmat}.c: use memcpy and memset to optimise when possible, add option to disable
--- a/src/fmat.c
+++ b/src/fmat.c
@@ -86,7 +86,11 @@
}
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_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
}
--- a/src/fvec.c
+++ b/src/fvec.c
@@ -63,7 +63,11 @@
}
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_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
}
--- a/src/lvec.c
+++ b/src/lvec.c
@@ -66,7 +66,11 @@
}
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) {
--- a/wscript
+++ b/wscript
@@ -58,6 +58,9 @@
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)')
@@ -181,6 +184,12 @@
ctx.msg('Checking for FFT implementation', 'vDSP')
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',