From 923a7a8011ed28c4759b62e70598d3de91f5eeec Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 26 Nov 2013 04:44:17 +0100 Subject: [PATCH] src/{fvec,fmat}.c: use memcpy and memset to optimise when possible, add option to disable --- src/fmat.c | 22 +++++++++++++++------- src/fvec.c | 17 ++++++++++++----- src/lvec.c | 4 ++++ wscript | 9 +++++++++ 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/fmat.c b/src/fmat.c index a6d8931a..8ff00e78 100644 --- a/src/fmat.c +++ b/src/fmat.c @@ -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 } diff --git a/src/fvec.c b/src/fvec.c index ea33b581..e62810e7 100644 --- a/src/fvec.c +++ b/src/fvec.c @@ -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 } diff --git a/src/lvec.c b/src/lvec.c index 4fb40cd6..c906d570 100644 --- a/src/lvec.c +++ b/src/lvec.c @@ -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 47e31b20..6513c525 100644 --- 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) -- 2.11.0