Skip to content

Conversation

@AntoinePrv
Copy link
Contributor

This is a no-addition, non-breaking refactor of existing CPU id features as first class citizen as part of #1245.

  • Two individual and simple classes parsing for XCR0 and CPUID
  • The classes/header is safe on all platform, avoiding
  • supported_arch keeps the same structure and merges use of both class at the moment but both class could be combined a user-friendly x86_cpu_features.

Copy link
Contributor

@serge-sans-paille serge-sans-paille left a comment

Choose a reason for hiding this comment

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

Some early review, a few open questions but nothing looks bad here. Way to go!

{
inline void get_cpuid(int reg[4], int level, int count = 0) noexcept;

inline std::uint32_t get_xcr0_low() noexcept;
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be good to somehow ensure that this type is the same as ref_t

Copy link
Contributor

Choose a reason for hiding this comment

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

And this could be a private static method for better encapsulation right?

using reg_t = std::uint32_t;

/** Parse a XCR0 value into individual components. */
constexpr explicit x86_xcr0(reg_t low) noexcept
Copy link
Contributor

Choose a reason for hiding this comment

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

if read is the only way to build this class, this should be private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's useful to leave at least a default constructor, so that one can create it somewhere and only conditionally read the value etc.

constexpr bool fma4() const noexcept
{
return utils::bit_is_set<16>(m_regs.reg8[2]);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Open question: should we have a macro that makes the generation of those field cleaner to the eye?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Either way. I am personally not big on macros. I find it easier read this way (could also be made to fit on one line) and find&replace is quite enough a change is required.


namespace detail
{
inline void get_cpuid(int reg[4], int level, int count) noexcept
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here: could be private for better encapsulation.

Copy link
Contributor Author

@AntoinePrv AntoinePrv Jan 30, 2026

Choose a reason for hiding this comment

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

On the contrary, I was wondering whether to make it part of public API.
It's a well defined function, unlikely to change, and that could be useful for users to get features we do not expose (not sure we'll go to cover 100% of cpuid).

* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#include "../config/xsimd_inline.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It for header including what they use (otherwise I get nasty errors in my editor).
But this one did not belong here but in xsimd_register.hpp where XSIMD_INLINE is used.

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.

2 participants