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

Optimize has_cpuid for x86 targets with know support #497

Closed
gnzlbg opened this issue Jun 24, 2018 · 4 comments
Closed

Optimize has_cpuid for x86 targets with know support #497

gnzlbg opened this issue Jun 24, 2018 · 4 comments

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Jun 24, 2018

For example, we could check if the x86 target has mmx support and return true unconditionally if that's the case.

@stevecheckoway
Copy link

stevecheckoway commented Jun 24, 2018

I'm not sure mmx is the correct feature to check for. One can compile for, for example,

{
  "llvm-target": "i686-unknown-none",
  "features": "-mmx"
  ...
}

But its presence is certainly sufficient.

If I'm reading this correctly (and I'm just poking around for the first time now), there are a whole bunch of features that are available. I'm not sure which features are exposed, but perhaps one could check for the presence of at least one of a set of them that imply cpuid support.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Jun 25, 2018

I'd prefer to keep this simple, this is all best effort anyways.

IIRC Rust's i586 targets have sse enabled, and i686 targets have sse2 enabled. So if we just detect sse at compile-time for the x86 arch that gets us 99% there for most supported targets.

For all others... unless the user is calling has_cpuid manually (e.g. in a #[no_std] crate), the has_cpuid function is invoked as part of run-time feature detection (std::__detect) at most once per process (its result is cached)...

If #[no_std] crates really care about this I would be fine with just saying that they should cache the result, and any run-time feature detection library for #[no_std] crates should already be doing this anyways.

We should strongly encourage #[no_std] crates to not do run-time feature detection themselves but to choose a run-time feature detection libraries that suits their target domain.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Jun 26, 2018

So i've just sent a PR that just tests for SSE and returns true if that's enabled at compile-time. Should just work for all i586 rust targets and upwards, but for non Rust targets we can probably do better.

I am leaving this open and changing difficulty to hard because PRs that improve on this are welcomed, but getting it "really right" isn't trivial.

@gnzlbg gnzlbg added hard and removed easy labels Jun 26, 2018
gnzlbg added a commit that referenced this issue Jun 26, 2018
TheIronBorn pushed a commit to TheIronBorn/stdsimd that referenced this issue Jun 29, 2018
TheIronBorn pushed a commit to TheIronBorn/stdsimd that referenced this issue Jun 29, 2018
lu-zero pushed a commit to lu-zero/stdarch that referenced this issue Jul 10, 2018
@gnzlbg gnzlbg added the P-high label Apr 18, 2019
@gnzlbg
Copy link
Contributor Author

gnzlbg commented Apr 19, 2019

I'm closing this, improving this further is not worth tracking IMO, but if somebody sends PR I'll accept them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants