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

Cleanup useless/non-constexpr branchs #2025

Merged
merged 7 commits into from
Nov 28, 2024
Merged

Conversation

SadiinsoSnowfall
Copy link
Collaborator

No description provided.

@SadiinsoSnowfall SadiinsoSnowfall marked this pull request as draft November 21, 2024 13:06
@SadiinsoSnowfall SadiinsoSnowfall marked this pull request as ready for review November 21, 2024 15:09
@jfalcou
Copy link
Owner

jfalcou commented Nov 23, 2024

I am OK with the x86 fixes.
The shuffle ones, aren't those function only use at constexpr anyway ? Is the correct fix to make them co steal instead ? Same for top_bits::is_cheap().

@DenisYaroshevskiy
Copy link
Collaborator

I am against replaicing constexpr with consteval:

  1. there is no reason.
  2. Now I can't log in them for testing

Copy link
Collaborator

@DenisYaroshevskiy DenisYaroshevskiy left a comment

Choose a reason for hiding this comment

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

Please put it back - constexpr functions are better like they were

@@ -65,52 +65,52 @@ struct swap_adjacent_t
}

template<simd_value T, std::ptrdiff_t G>
static constexpr std::ptrdiff_t level(eve::as<T> tgt, eve::fixed<G> g)
Copy link
Collaborator

Choose a reason for hiding this comment

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

these tests in level were deliberately not if constexpr where posssible.
main consideration is that if constexpr is probably slower to compile.
it also, for example, does not to do else branches.

{
using half_t = decltype(T {}.slice(lower_));
return level(as<half_t> {}, g);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure thids change improves things. maybe to not compile level(half)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that was the idea.

if constexpr (current_api == avx) return 4;
if constexpr (g_size >= 8) return 2;
if constexpr (g_size >= 4) return 3;
if constexpr (g_size >= 2 && current_api == avx512) return 3;
Copy link
Collaborator

Choose a reason for hiding this comment

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

you see - now you push things to comile time switching instead of just evaluating. I don't know how this works under the hood, but it seems worse.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Could you expand on that a little bit ? I don't think I quite get it.

{
if constexpr ( is_aggregated ) return top_bits<half_logical>::bits_per_element;
else return decltype(movemask(logical_type{}).second){}();
}

static constexpr bool is_cheap_impl()
static consteval bool is_cheap_impl()
Copy link
Collaborator

Choose a reason for hiding this comment

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

same story here - we don't want the ifs to be constexpr when t doesn't have to. And I don't like consteval for no reason.

@SadiinsoSnowfall
Copy link
Collaborator Author

Setting aside the consteval aspect (which I will revert as some of these functions are indeed used at runtime), a good part of these branchs were already if-constexpr. Also, these branchs depends on template parameters, wouldn't marking them as constexpr help with the compile times, if only a little ?

@DenisYaroshevskiy
Copy link
Collaborator

a good part of these branchs were already if-constexpr.

Where I had to.

these branchs depends on template parameters, wouldn't marking them as constexpr help with the compile times?

this is my thinking, which may be wrong. I do not know for sure. I work with some people I can ask - so I will when I have the chance.

When you do an if constexpr - the condition has to evaluate during compilation of that constexpr function.
When you do an if it evaluates during the execution of that constexpr function.

I suspect that if constexpr mechanism is similar to some template stuff and might be heavier on the compiler.
Wether or not that's true - I don't actually know.

We can park this until I confirm.

@SadiinsoSnowfall
Copy link
Collaborator Author

My reasoning is as follows: since these branches can be marked as constexpr, the compiler will likely eliminate them at compile time. If that’s the case, marking them as constexpr might reduce the scope of this optimization for each function template instantiation.

I would also like to know which approcach is in fact more compiler-friendly.
In the meantime I will split this part of the PR as a new draft.

@DenisYaroshevskiy
Copy link
Collaborator

My reasoning is as follows: since these branches can be marked as constexpr, the compiler will likely eliminate them at compile time

everything here is compile time! We want less compile time.

@SadiinsoSnowfall
Copy link
Collaborator Author

I have extracted the constexpr-related stuff into another draft PR, only the "bug fix" remains.

@SadiinsoSnowfall SadiinsoSnowfall merged commit d56b7d6 into main Nov 28, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants