Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmath intrinsic functions missing for double #4998

Open
jbrezina opened this issue Oct 2, 2024 · 2 comments
Open

cmath intrinsic functions missing for double #4998

jbrezina opened this issue Oct 2, 2024 · 2 comments
Labels
performance Must go faster UCRT Related to the Universal CRT

Comments

@jbrezina
Copy link

jbrezina commented Oct 2, 2024

I'm using std::round from cmath header file. I want the __round intrinsic function to be used, but I could not find any function supporting just double parameter, there is only long double version which casts the parameter to double anyways.

_NODISCARD _Check_return_ inline long double round(_In_ long double _Xx) noexcept /* strengthened */ {
#if _HAS_CMATH_INTRINSICS
    return __round(static_cast<double>(_Xx));
#elif defined(__clang__)
    return __builtin_roundl(_Xx);
#else // ^^^ defined(__clang__) / intrinsics unavailable vvv
    return _CSTD roundl(_Xx);
#endif // ^^^ intrinsics unavailable ^^^
}

To use the version with __round intrinsic function I have to cast the parameter to long double otherwise the old C version from math.h (corecrt_math.h) header file is used, which is much slower.

Is there any reason for that or am I doing anything wrong?

const double number{ -0.493 };

const auto result{ std::round(number) }; // uses C function from math.h
const auto result{ std::round(static_cast<long double>(number)) }; // uses std::round from cmath with __round intrinsic function

I found this issue Use ceil/floor/round/etc. intrinsics so I don't know if this is still in progress, but it's been 4 years since the issue was opened..

@jbrezina jbrezina added the question Further information is requested label Oct 2, 2024
@frederick-vs-ja
Copy link
Contributor

The overload for double is provided by UCRT so it's unfortunate that we can't achieve optimization for it in MSVC STL.

Perhaps we can report this on Developer Community (DevCom). But UCRT seems somehow "frozen" and one of my previous report for conformance bugs was closed for low priority.

@StephanTLavavej StephanTLavavej added performance Must go faster UCRT Related to the Universal CRT and removed question Further information is requested labels Oct 2, 2024
@StephanTLavavej
Copy link
Member

While in general we shouldn't expect major changes from the UCRT, @CaseyCarter is currently looking into this area. Additionally, since coordinated changes with the UCRT will almost certainly be necessary to implement C++23/26 constexpr for <cmath> (#2530 and #3789), we're going to have to overhaul this area anyways, so it's the one place where we can reasonably expect UCRT improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster UCRT Related to the Universal CRT
Projects
None yet
Development

No branches or pull requests

3 participants