diff --git a/src/SPECK1D_INT_DEC.cpp b/src/SPECK1D_INT_DEC.cpp index 8d73e0e1..e3bd78c7 100644 --- a/src/SPECK1D_INT_DEC.cpp +++ b/src/SPECK1D_INT_DEC.cpp @@ -26,12 +26,13 @@ void sperr::SPECK1D_INT_DEC::m_sorting_pass() value &= value - 1; } #else - if (value != 0) { - for (size_t j = 0; j < 64; j++) { - if ((value >> j) & uint64_t{1}) { - size_t dummy = 0; - m_process_P(i + j, dummy, true); - } + for (size_t j = 0; j < 64; j++) { + if (value == 0) + break; + if ((value >> j) & uint64_t{1}) { + size_t dummy = 0; + m_process_P(i + j, dummy, true); + value &= value - 1; } } #endif diff --git a/src/SPECK1D_INT_ENC.cpp b/src/SPECK1D_INT_ENC.cpp index 45373b04..3d4486b0 100644 --- a/src/SPECK1D_INT_ENC.cpp +++ b/src/SPECK1D_INT_ENC.cpp @@ -26,12 +26,13 @@ void sperr::SPECK1D_INT_ENC::m_sorting_pass() value &= value - 1; } #else - if (value != 0) { - for (size_t j = 0; j < 64; j++) { - if ((value >> j) & uint64_t{1}) { - size_t dummy = 0; - m_process_P(i + j, SigType::Dunno, dummy, true); - } + for (size_t j = 0; j < 64; j++) { + if (value == 0) + break; + if ((value >> j) & uint64_t{1}) { + size_t dummy = 0; + m_process_P(i + j, SigType::Dunno, dummy, true); + value &= value - 1; } } #endif diff --git a/src/SPECK2D_INT.cpp b/src/SPECK2D_INT.cpp index fdb69e3e..84503df5 100644 --- a/src/SPECK2D_INT.cpp +++ b/src/SPECK2D_INT.cpp @@ -24,12 +24,13 @@ void sperr::SPECK2D_INT::m_sorting_pass() value &= value - 1; } #else - if (value != 0) { - for (size_t j = 0; j < 64; j++) { - if ((value >> j) & uint64_t{1}) { - size_t dummy = 0; - m_process_P(i + j, dummy, true); - } + for (size_t j = 0; j < 64; j++) { + if (value == 0) + break; + if ((value >> j) & uint64_t{1}) { + size_t dummy = 0; + m_process_P(i + j, dummy, true); + value &= value - 1; } } #endif diff --git a/src/SPECK3D_INT.cpp b/src/SPECK3D_INT.cpp index 763db790..667db95b 100644 --- a/src/SPECK3D_INT.cpp +++ b/src/SPECK3D_INT.cpp @@ -113,10 +113,12 @@ void sperr::SPECK3D_INT::m_sorting_pass() value &= value - 1; } #else - if (value != 0) { - for (size_t j = 0; j < 64; j++) { - if ((value >> j) & uint64_t{1}) - m_process_P_lite(i + j); + for (size_t j = 0; j < 64; j++) { + if (value == 0) + break; + if ((value >> j) & uint64_t{1}) { + m_process_P_lite(i + j); + value &= value - 1; } } #endif diff --git a/src/SPECK_INT.cpp b/src/SPECK_INT.cpp index 1fa457c6..3fbb5c04 100644 --- a/src/SPECK_INT.cpp +++ b/src/SPECK_INT.cpp @@ -326,13 +326,14 @@ void sperr::SPECK_INT::m_refinement_pass_encode() value &= value - 1; } #else - if (value != 0) { - for (size_t j = 0; j < 64; j++) { - if ((value >> j) & uint64_t{1}) { - const bool o1 = m_coeff_buf[i + j] >= m_threshold; - m_coeff_buf[i + j] -= tmp1[o1]; - m_bit_buffer.wbit(o1); - } + for (size_t j = 0; j < 64; j++) { + if (value == 0) + break; + if ((value >> j) & uint64_t{1}) { + const bool o1 = m_coeff_buf[i + j] >= m_threshold; + m_coeff_buf[i + j] -= tmp1[o1]; + m_bit_buffer.wbit(o1); + value &= value - 1; } } #endif @@ -386,16 +387,17 @@ void sperr::SPECK_INT::m_refinement_pass_decode() value &= value - 1; } #else - if (value != 0) { - for (size_t j = 0; j < 64; j++) { - if ((value >> j) & uint64_t{1}) { - if (m_bit_buffer.rbit()) - m_coeff_buf[i + j] += half_t; - else - m_coeff_buf[i + j] -= half_t; - if (++read_pos == m_avail_bits) // <-- Point 3 - goto INITIALIZE_NEWLY_FOUND_POINTS_LABEL; // <-- Point 4 - } + for (size_t j = 0; j < 64; j++) { + if (value == 0) + break; + if ((value >> j) & uint64_t{1}) { + if (m_bit_buffer.rbit()) + m_coeff_buf[i + j] += half_t; + else + m_coeff_buf[i + j] -= half_t; + if (++read_pos == m_avail_bits) // <-- Point 3 + goto INITIALIZE_NEWLY_FOUND_POINTS_LABEL; // <-- Point 4 + value &= value - 1; } } #endif @@ -426,11 +428,14 @@ void sperr::SPECK_INT::m_refinement_pass_decode() } #else for (size_t j = 0; j < 64; j++) { + if (value == 0) + break; if ((value >> j) & uint64_t{1}) { if (m_bit_buffer.rbit()) ++(m_coeff_buf[i + j]); if (++read_pos == m_avail_bits) goto INITIALIZE_NEWLY_FOUND_POINTS_LABEL; + value &= value - 1; } } #endif