1111#pragma once
1212
1313#include " ccmath/internal/config/type_support.hpp"
14- #include " ccmath/internal/math/runtime/simd/simd_vectorize.hpp"
1514#include " ccmath/internal/predef/unlikely.hpp"
16- #include " ccmath/internal/support/always_false.hpp"
1715#include " ccmath/internal/support/bits.hpp"
1816#include " ccmath/internal/support/fenv/rounding_mode.hpp"
1917#include " ccmath/internal/support/fp/fp_bits.hpp"
20- #include " ccmath/internal/support/is_constant_evaluated.hpp"
2118
2219#include < type_traits>
2320
@@ -174,7 +171,7 @@ namespace ccm::gen
174171 {
175172 using FPBits_t = support::fp::FPBits<T>;
176173 using storage_type = typename FPBits_t::storage_type;
177- constexpr storage_type one = storage_type (1 ) << FPBits_t::fraction_length;
174+ constexpr storage_type one = static_cast < storage_type> (1 ) << FPBits_t::fraction_length;
178175
179176 int x_exp = bits.get_exponent ();
180177 storage_type x_mant = bits.get_mantissa ();
@@ -197,30 +194,14 @@ namespace ccm::gen
197194 storage_type y = one;
198195 storage_type r = x_mant - one;
199196
200- if ( ccm::support::is_constant_evaluated () )
197+ for (storage_type current_bit = one >> 1 ; current_bit; current_bit >>= 1 )
201198 {
202- for (storage_type current_bit = one >> 1 ; current_bit; current_bit >>= 1 )
199+ r <<= 1 ;
200+ const storage_type tmp = (y << 1 ) + current_bit; // 2*y(n - 1) + 2^(-n-1)
201+ if (r >= tmp)
203202 {
204- r <<= 1 ;
205- const storage_type tmp = (y << 1 ) + current_bit; // 2*y(n - 1) + 2^(-n-1)
206- if (r >= tmp)
207- {
208- r -= tmp;
209- y += current_bit;
210- }
211- }
212- }
213- else // If we are not in a constant evaluated context, we can vectorize the loop.
214- {
215- CCM_SIMD_VECTORIZE for (storage_type current_bit = one >> 1 ; current_bit; current_bit >>= 1 )
216- {
217- r <<= 1 ;
218- const storage_type tmp = (y << 1 ) + current_bit; // 2 * y(n - 1) + 2^(-n-1)
219- if (r >= tmp)
220- {
221- r -= tmp;
222- y += current_bit;
223- }
203+ r -= tmp;
204+ y += current_bit;
224205 }
225206 }
226207
@@ -278,7 +259,7 @@ namespace ccm::gen
278259 if (CCM_UNLIKELY (bits.is_neg ())) { return -flt_nan; }
279260
280261 // If we didn't encounter any special cases, we can calculate the square root normally.
281- return sqrt_calc_bits (bits);
262+ return sqrt_calc_bits<T> (bits);
282263 }
283264 }
284265 } // namespace impl
0 commit comments