Skip to content
New issue

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

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

Already on GitHub? # to your account

Workaround intel bug #3652

Merged
merged 5 commits into from
Sep 21, 2023
Merged

Workaround intel bug #3652

merged 5 commits into from
Sep 21, 2023

Conversation

gsjaardema
Copy link
Contributor

Potential workaround / restructure for the intel bug that is the cause of #3645.

Make the variable in the external struct instead an embedded static constexpr variable in the only function that uses the variable.

Potential workaround / restructure for the intel bug that is the cause of fmtlib#3645.

Make the variable in the external struct instead an embedded static constexpr variable in the only function that uses the variable.
@gsjaardema gsjaardema closed this Sep 20, 2023
@gsjaardema
Copy link
Contributor Author

Pull request not correct for certain c++ std levels. Will let someone with more knowledge propose a solution.

// For checking rounding thresholds.
// The kth entry is chosen to be the smallest integer such that the
// upper 32-bits of 10^(k+1) times it is strictly bigger than 5 * 10^k.
static constexpr uint32_t fractional_part_rounding_thresholds[8] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to drop static here:

/Users/runner/work/fmt/fmt/include/fmt/format.h:3268:29: error: definition of a static variable in a constexpr function is a C++2b extension [-Werror,-Wc++2b-extensions]
  static constexpr uint32_t fractional_part_rounding_thresholds[8] = {
                            ^

Also please move to a separate function to avoid parametrization on Float, something like

FMT_CONSTEXPR uint32_t fractional_part_rounding_threshold(int index) {
  constexpr uint32_t thresholds[] = {...};
  return thresholds[index];
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vitaut
Will a non-static constexpr array be optimized by the compiler?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¯_(ツ)_/¯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vitaut

It doesn't get optimized: https://godbolt.org/z/drn31x9zK

Maybe revert this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should revert this PR but ideas/PRs to optimize it would be welcome.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vitaut
Solution for GCC, Clang: https://godbolt.org/z/ezj9GhnYW
But not for MSVC (current code: https://godbolt.org/z/5Pxn3zMfT)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have another idea: 06b2038.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vitaut Solution for GCC, Clang: https://godbolt.org/z/ezj9GhnYW But not for MSVC (current code: https://godbolt.org/z/5Pxn3zMfT)

That looks good. I had something similar but didn't think of the unreachable to quiet the warnings and keep the optimization.

@gsjaardema gsjaardema reopened this Sep 20, 2023
Moved variable out of function to avoid specialization on Float.  Made it a separate function that is called from format_float.
@vitaut vitaut merged commit 7529af8 into fmtlib:master Sep 21, 2023
@vitaut
Copy link
Contributor

vitaut commented Sep 21, 2023

Thanks

ckerr pushed a commit to transmission/fmt that referenced this pull request Nov 7, 2023
* Workaround intel bug

Potential workaround / restructure for the intel bug that is the cause of fmtlib#3645.

Make the variable in the external struct instead an embedded static constexpr variable in the only function that uses the variable.

* Finish the proposed change -- remove struct accessor

* Refactor proposed intel fix.

Moved variable out of function to avoid specialization on Float.  Made it a separate function that is called from format_float.

* Fix incorrect function name.

* Add missing inline.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants