-
Notifications
You must be signed in to change notification settings - Fork 272
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
add support for querying cpuid #1118
Conversation
d013459
to
98decae
Compare
I tried this on the affected machine and I can report that it worked:
|
I am not 100% sure I am doing the right thing here 😬 in your PR you are and-ing 0x0400_0000, in this PR it's 0x20. For some reason on my (dusty old and excruciatingly slow) machine this still prints "100000000..." instead of "2.500..."; and it only works with 0x0400_0000. However, according to the spec the 5th bit on ECX should be 0x20 🤪 |
OK, then I need to recheck. Did the tests pass for me because of caching, or because I have both I did notice that. From the docs, I assumed it's the 5th bit from the left: I thing we need to figure it out from other implementations. |
I think, based on the Intel "sponsored" library ( Then compare So it seems you're right, and I messed up, but maybe your excruciatingly slow computer needs to check |
// lifted from github.com/intel-go/cpuid and src/internal/cpu/cpu_x86.s | ||
// func cpuid(arg1, arg2 uint32) (eax, ebx, ecx, edx uint32) | ||
TEXT ·cpuid(SB), NOSPLIT, $0-24 | ||
MOVL arg1+0(FP), AX | ||
MOVL arg2+4(FP), CX | ||
CPUID | ||
MOVL AX, eax+8(FP) | ||
MOVL BX, ebx+12(FP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need AX and BX register values? I think we could just delete them if you don't use.
// lifted from github.com/intel-go/cpuid and src/internal/cpu/cpu_x86.s | |
// func cpuid(arg1, arg2 uint32) (eax, ebx, ecx, edx uint32) | |
TEXT ·cpuid(SB), NOSPLIT, $0-24 | |
MOVL arg1+0(FP), AX | |
MOVL arg2+4(FP), CX | |
CPUID | |
MOVL AX, eax+8(FP) | |
MOVL BX, ebx+12(FP) | |
TEXT ·cpuid(SB), NOSPLIT, $0-16 | |
MOVL arg1+0(FP), AX | |
MOVL arg2+4(FP), CX | |
CPUID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other feature queries might use all 4 (e.g. BMI uses EBX
). This makes it the only assembly you'll ever need to feature test amd64
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, in theory (maybe not in practice) you should call cpuid(0, 0)
and inspect EAX
to figure out if you can trust cpuid(1, 0)
, and similarly call cpuid(0x8000_0000, 0)
before cpuid(0x8000_0001, 0)
.
https://www.amd.com/system/files/TechDocs/25481.pdf
The smallest function number of the standard function range is Fn0000_0000. The largest function number of the standard function range, for a particular implementation, is returned in CPUID
Fn0000_0000_EAX.
The smallest function number of the extended function range is Fn8000_0000. The largest function number of the extended function range, for a particular implementation, is returned in CPUID
Fn8000_0000_EAX.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, thanks for the info!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!👏
f90433b
to
fb4e973
Compare
Signed-off-by: Edoardo Vacchi <[email protected]>
fb4e973
to
8908546
Compare
OSS collaboration like this makes my day, thanks @ncruces @evacchi @mathetake! |
fixes #1111, adds setup for fixing #580
While I haven't tested this on a proper x86 machine (but I do have a dusty core duo laptop which may really be the thing I need, if I manage to turn it on :D) I have sketched a solution by putting together everyone's feedback (including @ncruces' 🚀). In the meantime I have also discovered that
GOARCH=amd64
has the ABM feature flag off on Rosetta2.cupid_amd64.{s,go}
because I felt it would pollute too muchimpl
andarch
didn't feel like the right place (that's for runtime)Values are kept in a struct that is local to the compiler instance. This is re-inited at for each
amd64Compiler
-- TBF it may be created once and then copied over when necessary. I wanted to keep it local to the compiler instance, instead of global, to make sure we can properly test it.Speaking of testing: the compiler test right now is kind of silly because it checks for the length of the generated byte array. The one reason is that I couldn't figure out how to decode or inspect the list of opcodes the right way. This is the main reason why this is draft.