From: Robin Dong <[email protected]> Add new macro 'HAVE_SSSE3', so we could choose zfec or isa-l by checking it.
Signed-off-by: Robin Dong <[email protected]> --- configure.ac | 10 ++++++++++ include/fec.h | 18 ++++++++++-------- lib/Makefile.am | 10 +++++++--- lib/fec.c | 8 +++++--- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index f78aa3b..81cdf24 100644 --- a/configure.ac +++ b/configure.ac @@ -198,6 +198,16 @@ LINT_FLAGS="-weak -unrecog +posixlib +ignoresigns -fcnuse \ AM_CONDITIONAL(BUILD_SHA1_HW, [[[[ $host = *x86_64* ]]]]) +AC_TRY_COMPILE([], + [ __asm__ __volatile__ ("addsubpd" " %" "xmm0" ", %" "xmm1");], + CPU_SSSE3=true) + +if test $CPU_SSSE3 = true; then + AC_DEFINE_UNQUOTED([HAVE_SSSE3], [1], [have ssse3]) +fi + +AM_CONDITIONAL(BUILD_ISAL_HW, test $CPU_SSSE3 = true) + AC_ARG_ENABLE([fatal-warnings], [ --enable-fatal-warnings : enable fatal warnings. ], [ default="no" ]) diff --git a/include/fec.h b/include/fec.h index 1ae32e4..b339c8d 100644 --- a/include/fec.h +++ b/include/fec.h @@ -172,17 +172,18 @@ static inline void ec_encode(struct fec *ctx, const uint8_t *ds[], uint8_t *ps[]) { int p = ctx->dp - ctx->d; - int pidx[p]; - for (int i = 0; i < p; i++) - pidx[i] = ctx->d + i; - - if (cpu_has_ssse3) + for (int i = 0; i < p; i++) { + #ifdef HAVE_SSSE3 ec_encode_data_sse(SD_EC_DATA_STRIPE_SIZE / ctx->d, ctx->d, p, ctx->ec_tbl, (unsigned char **)ds, ps); - else + #else + int pidx[p]; + pidx[i] = ctx->d + i; fec_encode(ctx, ds, ps, pidx, p, SD_EC_DATA_STRIPE_SIZE / ctx->d); + #endif + } } /* @@ -207,9 +208,10 @@ static inline void ec_destroy(struct fec *ctx) static inline void ec_decode_buffer(struct fec *ctx, uint8_t *input[], const int in_idx[], char *buf, int idx) { - if (cpu_has_ssse3) + #ifdef HAVE_SSSE3 isa_decode_buffer(ctx, input, in_idx, buf, idx); - else + #else fec_decode_buffer(ctx, input, in_idx, buf, idx); + #endif } #endif diff --git a/lib/Makefile.am b/lib/Makefile.am index a43076e..56ba504 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,6 +4,10 @@ AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include libsheepdog_a_DEPENDENCIES = +libsheepdog_a_SOURCES = event.c logger.c net.c util.c rbtree.c strbuf.c \ + sha1.c option.c work.c sockfd_cache.c fec.c sd_inode.c + +if BUILD_ISAL_HW noinst_LIBRARIES = libisa.a libsheepdog.a libisa_a_SOURCES = $(shell find isa-l/ -type f -regex ".*\.\(c\|h\|asm\)") \ @@ -12,9 +16,6 @@ libisa_a_SOURCES = $(shell find isa-l/ -type f -regex ".*\.\(c\|h\|asm\)") \ isa-l/Makefile.nmake \ isa-l/make.inc -libsheepdog_a_SOURCES = event.c logger.c net.c util.c rbtree.c strbuf.c \ - sha1.c option.c work.c sockfd_cache.c fec.c sd_inode.c - libsheepdog_a_LIBADD = isa-l/bin/ec_base.o \ isa-l/bin/ec_highlevel_func.o \ isa-l/bin/ec_multibinary.o \ @@ -26,6 +27,9 @@ libsheepdog_a_LIBADD = isa-l/bin/ec_base.o \ isa-l/bin/gf_vect_dot_prod_sse.o \ isa-l/bin/gf_vect_mul_avx.o \ isa-l/bin/gf_vect_mul_sse.o +else +noinst_LIBRARIES = libsheepdog.a +endif if BUILD_SHA1_HW libsheepdog_a_SOURCES += sha1_ssse3.S diff --git a/lib/fec.c b/lib/fec.c index c4e7a6f..6de716a 100644 --- a/lib/fec.c +++ b/lib/fec.c @@ -454,8 +454,9 @@ void fec_free(struct fec *p) assert(p != NULL && p->magic == (((FEC_MAGIC ^ p->d) ^ p->dp) ^ (unsigned long) (p->enc_matrix))); free(p->enc_matrix); - if (cpu_has_ssse3) + #ifdef HAVE_SSSE3 free(p->ec_tbl); + #endif free(p); } @@ -496,12 +497,13 @@ struct fec *fec_new(unsigned short d, unsigned short dp) *p = 1; free(tmp_m); - if (cpu_has_ssse3) { + #ifdef HAVE_SSSE3 retval->ec_tbl = xmalloc(dp * d * 32); ec_init_tables(d, dp - d, retval->enc_matrix + (d * d), retval->ec_tbl); - } else + #else retval->ec_tbl = NULL; + #endif return retval; } -- 1.9.1 -- sheepdog mailing list [email protected] http://lists.wpkg.org/mailman/listinfo/sheepdog
