-From 1b0dafa7a6920dd2e9ce97a1c8c084e4c8fc5f68 Mon Sep 17 00:00:00 2001
-From: Alexander Evseev <aevseev@mirantis.com>
-Date: Wed, 29 Jul 2015 16:13:32 +0300
-Subject: [PATCH] Fix build for 32 bit targets
-
- * Define CPU flags for non-x86_64 targets
- * Use non-SSE version of ec_encode_data for non-x86_64 targets
- * Add make variable "arch" as it should be used in isa-l
-
-Signed-off-by: Alexander Evseev <aevseev@mirantis.com>
----
- configure.ac | 1 +
- include/compiler.h | 6 ++++++
- lib/Makefile.am | 14 ++++++++++++--
- lib/fec.c | 5 ++++-
- 4 files changed, 23 insertions(+), 3 deletions(-)
-
-diff --git a/configure.ac b/configure.ac
-index e637f42..66b733b 100644
---- a/configure.ac
-+++ b/configure.ac
-@@ -199,6 +199,7 @@ LINT_FLAGS="-weak -unrecog +posixlib +ignoresigns -fcnuse \
- -badflag -D__gnuc_va_list=va_list -D__attribute\(x\)="
-
- AM_CONDITIONAL(BUILD_SHA1_HW, [[[[ $host = *x86_64* ]]]])
-+AM_CONDITIONAL(X86_64, [[[[ $host = *x86_64* ]]]])
-
- AC_ARG_ENABLE([fatal-warnings],
- [ --enable-fatal-warnings : enable fatal warnings. ],
-diff --git a/include/compiler.h b/include/compiler.h
-index 3c68b75..64ab6b4 100644
---- a/include/compiler.h
-+++ b/include/compiler.h
-@@ -155,6 +155,12 @@ static inline uint64_t xgetbv(uint32_t idx)
- #define cpu_has_avx cpu_has(X86_FEATURE_AVX)
- #define cpu_has_osxsave cpu_has(X86_FEATURE_OSXSAVE)
-
-+#else /* __x86_64__ */
-+
-+#define cpu_has_ssse3 0
-+#define cpu_has_avx 0
-+#define cpu_has_osxsave 0
-+
- #endif /* __x86_64__ */
-
- #endif /* SD_COMPILER_H */
-diff --git a/lib/Makefile.am b/lib/Makefile.am
-index dec81c7..dfb2fb0 100644
---- a/lib/Makefile.am
-+++ b/lib/Makefile.am
-@@ -38,7 +38,7 @@ libsd_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 common.c
-
--libsheepdog_a_LIBADD = isa-l/bin/ec_base.o \
-+libsheepdog_a_LIBADD_ = isa-l/bin/ec_base.o \
- isa-l/bin/ec_highlevel_func.o \
- isa-l/bin/ec_multibinary.o \
- isa-l/bin/gf_2vect_dot_prod_sse.o \
-@@ -50,6 +50,16 @@ libsd_a_LIBADD = isa-l/bin/ec_base.o \
- isa-l/bin/gf_vect_mul_avx.o \
- isa-l/bin/gf_vect_mul_sse.o
-
-+libsheepdog_a_LIBADD_32 = isa-l/bin/ec_base.o \
-+ isa-l/bin/ec_highlevel_func.o \
-+ isa-l/bin/ec_multibinary.o
-+
-+if !X86_64
-+arch = 32
-+endif
-+
-+libsheepdog_a_LIBADD = $(libsheepdog_a_LIBADD_$(arch))
-+
- if BUILD_SHA1_HW
- libsd_a_SOURCES += sha1_ssse3.S
- endif
-@@ -74,7 +84,7 @@ check-style:
- @$(CHECK_STYLE) $(libsd_a_SOURCES)
-
- libisa.a:
-- cd isa-l/ && $(MAKE) && cd ..
-+ cd isa-l/ && $(MAKE) arch=$(arch) && cd ..
-
- clean-local:
- rm -f *.o gmon.out *.da *.bb *.bbg
-diff --git a/lib/fec.c b/lib/fec.c
-index e0908bc..e2d5cd1 100644
---- a/lib/fec.c
-+++ b/lib/fec.c
-@@ -739,5 +739,8 @@ void isa_decode_buffer(struct fec *ctx, uint8_t *input[], const int in_idx[],
-
- lost[0] = (unsigned char *)buf;
- ec_init_tables(ed, 1, cm, ec_tbl);
-- ec_encode_data_sse(len, ed, 1, ec_tbl, input, lost);
-+ if (cpu_has_ssse3)
-+ ec_encode_data_sse(len, ed, 1, ec_tbl, input, lost);
-+ else
-+ ec_encode_data(len, ed, 1, ec_tbl, input, lost);
- }