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

Proposal: @cpuid builtin #3622

Closed
data-man opened this issue Nov 7, 2019 · 4 comments
Closed

Proposal: @cpuid builtin #3622

data-man opened this issue Nov 7, 2019 · 4 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@data-man
Copy link
Contributor

data-man commented Nov 7, 2019

Possible new builtin:

@cpuid(id: u32,    // == EAX
       subId: u32  // == ECX
       ) ?[4]u32

New module: cpuid.zig (I can take it)
Comptime: returns host's results
Runtime: returns target's results

Related: #215, #767, #1018

@tuket
Copy link

tuket commented Nov 7, 2019

https://en.wikipedia.org/wiki/CPUID
I like the idea

@andrewrk andrewrk added this to the 0.7.0 milestone Nov 14, 2019
@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Nov 14, 2019
@daurnimator
Copy link
Contributor

Comptime: returns host's results

There's nothing in zig (apart from @embedFile I guess) that exposes information about the host. Why would you want/need this?

@pixelherodev
Copy link
Contributor

I agree; there is no practical benefit to that functionality, so it would just increase the compiler's complexity without providing any real benefits.

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 27, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@ElementW
Copy link

This proposal has a couple issues in my opinion:

  • This signature is very x86-y:
    • inputs & outputs are 32-bit, but some targets have other lengths for their cpuid equivalent; e.g. RISC-V CSRs are of the core's native bit length (XLEN), and it's not just left-padding with zeroes
    • not all architectures have dynamically selectable feature registers; e.g. ARM's mrs instructions encode the selected register in its instruction directly
    • archs may have more or less than 2 parameter registers/inputs
  • It doesn't need to be a builtin really. Since how to get the CPU info and what you get back is very arch-specific you need to wrap that around code to discriminate the features you want, you'll need to either:
    • use said wrapper (possibly this could end up in the standard lib)
    • or roll your own, in which case having to call the target architecture's cpuid instruction equivalent by yourself will not make the task any harder
  • Returning the host/target's results depending on comptime is nothing short of a recipe for making mistakes; the difference of action is invisible to somebody reading the source without knowing of your proposal's idiosyncrasies. At best you'd need to split it into @hostCpuid and @targetCpuid.
  • As @daurnimator said, there's no reason to expose info about the host anyway, as you're producing code to be ran on a target, not the host. If you want the code to run on the host, then the target is the host.

@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

6 participants