From 3665e27c82076a53bc6001368c46d4b87cfa3b47 Mon Sep 17 00:00:00 2001 From: Sylvain Laperche Date: Fri, 3 Aug 2018 09:16:16 +0200 Subject: [PATCH 1/3] fix compilation in debug mode with Clang On my machine, Clang cannot compile the code in debug mode. quadiron/src/arith.h:299: undefined reference to `__muloti4' quadiron/src/arith.h:303: undefined reference to `__muloti4' quadiron/src/arith.h:307: undefined reference to `__muloti4' This seems related to this bug: https://bugs.llvm.org/show_bug.cgi?id=16404 Removing `-ftrapv` for Clang solves the issue. --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c52a92da..49fd925b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,7 +153,6 @@ endforeach(flag) # Debug flags set(DEBUG_CXX_FLAGS -O0 -g3 -ggdb3 -fno-limit-debug-info - -ftrapv ) foreach(flag ${DEBUG_CXX_FLAGS}) check_cxx_compiler_flag(${flag} has_flag_${flag}) @@ -162,6 +161,11 @@ foreach(flag ${DEBUG_CXX_FLAGS}) endif(has_flag_${flag}) endforeach(flag) +# Seems buggy on Clang: see https://bugs.llvm.org/show_bug.cgi?id=16404 +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ftrapv") +endif() + # Release flags set(RELEASE_CXX_FLAGS -O3 -DNDEBUG From b62cc1e37c22b247949bd838a93a9a05c5f8f4c7 Mon Sep 17 00:00:00 2001 From: Sylvain Laperche Date: Fri, 3 Aug 2018 09:50:45 +0200 Subject: [PATCH 2/3] fix compilation on GCC 8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fix: - an `unused-but-set-variable` error in `fec_base.h` - a lot of `sign-compare` errors, mainly using signed loop counter with an unsigned loop count. - some `return-type` errors that look like false positives (switch on an enum where all cases were already handled) but well… --- src/fec_base.h | 13 +++++-------- src/fec_context.h | 13 +++++++++++-- src/fec_rs_fnt.h | 3 ++- src/fec_rs_gf2n_fft.h | 3 ++- src/fec_rs_gf2n_fft_add.h | 4 ++-- src/fec_rs_gfp_fft.h | 3 ++- src/fec_rs_nf4.h | 3 ++- src/gf_ring.h | 2 +- 8 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/fec_base.h b/src/fec_base.h index 6eec5cf2..e5cc810f 100644 --- a/src/fec_base.h +++ b/src/fec_base.h @@ -772,7 +772,7 @@ void FecCode::decode_prepare( vec::Vector* words) { const vec::Vector& fragments_ids = context.get_fragments_id(); - for (int i = 0; i < this->n_data; ++i) { + for (unsigned i = 0; i < this->n_data; ++i) { const int j = fragments_ids.get(i); auto data = props[j].get(ValueLocation(offset, j)); @@ -814,7 +814,7 @@ void FecCode::decode_apply( // compute N(x) and stored in vec1_n vec1_n.zero_fill(); - for (int i = 0; i <= k - 1; ++i) { + for (unsigned i = 0; i <= k - 1; ++i) { vec1_n.set( fragments_ids.get(i), this->gf->mul(words->get(i), inv_A_i.get(fragments_ids.get(i)))); @@ -927,11 +927,6 @@ bool FecCode::decode_packet( decode_build(); - int n_words = code_len; - if (type == FecType::SYSTEMATIC) { - n_words = n_data; - } - // vector of buffers storing data read from chunk vec::Buffers words_char(n_data, buf_size); std::vector* words_mem_char = words_char.get_mem(); @@ -1109,10 +1104,12 @@ void FecCode::decode_apply( unsigned k = this->n_data; // number of fragments received + assert(k != 0); + // compute N'(x) = sum_i{n_i * x^z_i} // where n_i=v_i/A'_i(x_i) buf1_n.zero_fill(); - for (int i = 0; i <= k - 1; ++i) { + for (unsigned i = 0; i <= k - 1; ++i) { this->gf->mul_coef_to_buf( inv_A_i.get(fragments_ids.get(i)), words->get(i), diff --git a/src/fec_context.h b/src/fec_context.h index 4fedda59..5d151dff 100644 --- a/src/fec_context.h +++ b/src/fec_context.h @@ -160,6 +160,9 @@ class DecodeContext { return *vec1_2k; case CtxVec::V2K2: return *vec2_2k; + // To quell an overzealous `Wreturn-type` from GCC. + default: + throw InvalidArgument("invalid Vec type"); } } @@ -170,6 +173,9 @@ class DecodeContext { return *A; case CtxPoly::S: return *S; + // To quell an overzealous `Wreturn-type` from GCC. + default: + throw InvalidArgument("invalid Poly type"); } } @@ -186,6 +192,9 @@ class DecodeContext { return *buf2_2k; case CtxBuf::B2KMK: return *buf1_len2k_minus_k; + // To quell an overzealous `Wreturn-type` from GCC. + default: + throw InvalidArgument("invalid Buf type"); } } @@ -222,7 +231,7 @@ class DecodeContext { A->set(0, 1); } - for (int i = 0; i < k; ++i) { + for (unsigned i = 0; i < k; ++i) { A->mul_to_x_plus_coef(this->gf->sub(0, vx.get(i))); } @@ -239,7 +248,7 @@ class DecodeContext { // compute 1/(x_i * A_i(x_i)) // we care only about elements corresponding to fragments_ids - for (unsigned i = 0; i < k; ++i) { + for (int i = 0; i < static_cast(k); ++i) { unsigned j = fragments_ids->get(i); if (i != vx_zero) { inv_A_i->set( diff --git a/src/fec_rs_fnt.h b/src/fec_rs_fnt.h index 6f6f767a..9a52eef6 100644 --- a/src/fec_rs_fnt.h +++ b/src/fec_rs_fnt.h @@ -120,8 +120,9 @@ class RsFnt : public FecCode { // vector stores r^{i} for i = 0, ... , n-1 this->r_powers = std::unique_ptr>( new vec::Vector(*(this->gf), this->n)); - for (int i = 0; i < this->n; i++) + for (unsigned i = 0; i < this->n; i++) { this->r_powers->set(i, this->gf->exp(this->r, i)); + } } int get_n_outputs() override diff --git a/src/fec_rs_gf2n_fft.h b/src/fec_rs_gf2n_fft.h index 5f47cc16..8c7c7a94 100644 --- a/src/fec_rs_gf2n_fft.h +++ b/src/fec_rs_gf2n_fft.h @@ -97,8 +97,9 @@ class RsGf2nFft : public FecCode { // vector stores r^{i} for i = 0, ... , k this->r_powers = std::unique_ptr>( new vec::Vector(*(this->gf), this->n)); - for (int i = 0; i < this->n; i++) + for (unsigned i = 0; i < this->n; i++) { this->r_powers->set(i, this->gf->exp(this->r, i)); + } } int get_n_outputs() override diff --git a/src/fec_rs_gf2n_fft_add.h b/src/fec_rs_gf2n_fft_add.h index 96a7a9f2..6d257dd6 100644 --- a/src/fec_rs_gf2n_fft_add.h +++ b/src/fec_rs_gf2n_fft_add.h @@ -144,7 +144,7 @@ class RsGf2nFftAdd : public FecCode { vec::Vector vx(*(this->gf), k); int vx_zero = -1; - for (int i = 0; i < this->n_data; ++i) { + for (unsigned i = 0; i < this->n_data; ++i) { T val = betas->get(fragments_ids.get(i)); vx.set(i, val); if (val == 0) { @@ -191,7 +191,7 @@ class RsGf2nFftAdd : public FecCode { // FIXME: split this step in decode_init as multiplicative FFT vec::Vector vx(*(this->gf), k); - for (int i = 0; i < this->n_data; ++i) { + for (unsigned i = 0; i < this->n_data; ++i) { vx.set(i, this->betas->get(fragments_ids.get(i))); } diff --git a/src/fec_rs_gfp_fft.h b/src/fec_rs_gfp_fft.h index e3b2207f..828e2ccc 100644 --- a/src/fec_rs_gfp_fft.h +++ b/src/fec_rs_gfp_fft.h @@ -152,8 +152,9 @@ class RsGfpFft : public FecCode { // vector stores r^{i} for i = 0, ... , k this->r_powers = std::unique_ptr>( new vec::Vector(*(this->gf), this->n)); - for (int i = 0; i < this->n; i++) + for (unsigned i = 0; i < this->n; i++) { this->r_powers->set(i, this->gf->exp(this->r, i)); + } } int get_n_outputs() override diff --git a/src/fec_rs_nf4.h b/src/fec_rs_nf4.h index 3afb742b..a296cc78 100644 --- a/src/fec_rs_nf4.h +++ b/src/fec_rs_nf4.h @@ -107,8 +107,9 @@ class RsNf4 : public FecCode { // vector stores r^{i} for i = 0, ... , k this->r_powers = std::unique_ptr>( new vec::Vector(*ngff4, this->n)); - for (int i = 0; i < this->n; i++) + for (unsigned i = 0; i < this->n; i++) { this->r_powers->set(i, ngff4->exp(this->r, i)); + } } int get_n_outputs() override diff --git a/src/gf_ring.h b/src/gf_ring.h index 731661b9..cae89d70 100644 --- a/src/gf_ring.h +++ b/src/gf_ring.h @@ -888,7 +888,7 @@ template void RingModN::neg(size_t n, T* x) const { // add y to the first half of `x` - for (int i = 0; i < n; i++) { + for (size_t i = 0; i < n; i++) { x[i] = sub(0, x[i]); } } From 576727f57c911ef0aab82fd0fef2ec4c4450e147 Mon Sep 17 00:00:00 2001 From: Sylvain Laperche Date: Fri, 3 Aug 2018 10:17:35 +0200 Subject: [PATCH 3/3] fix a false positive Clang seems to have issue with `_mm256_storeu2_m128i` --- src/simd_256_u32.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/simd_256_u32.h b/src/simd_256_u32.h index a888e2c8..383aca05 100644 --- a/src/simd_256_u32.h +++ b/src/simd_256_u32.h @@ -320,7 +320,7 @@ inline aint128 m256i_to_uint128(m256i v) { aint128 hi, lo; _mm256_storeu2_m128i((m128i*)&hi, (m128i*)&lo, v); - return lo; + return lo; // NOLINT(clang-analyzer-core.uninitialized.UndefReturn) } inline __uint128_t add(__uint128_t a, __uint128_t b)