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

Fix #1111. #1112

Closed
wants to merge 2 commits into from
Closed

Fix #1111. #1112

wants to merge 2 commits into from

Conversation

ncruces
Copy link
Collaborator

@ncruces ncruces commented Feb 9, 2023

I know this can't go in because of the cpuid dependency, but maybe it helps.

I can confirm all tests pass on Windows+WSL on the affected machine, and on Windows+macOS+Linux on other machines.

Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
@ncruces ncruces mentioned this pull request Feb 9, 2023
@codefromthecrypt
Copy link
Contributor

thanks, @ncruces I think considering we wrote our own assembler, I think we can find a way to get similar code needed here (with unit tests). e.g. in our assembly we have compileXXX functions that could add instructions needed like https://github.com/aregm/cpuid/blob/master/cpuidlow_amd64.s

Thanks for making the change. To proceed I think ideally we can make the build fail first, then we can adapt in logic we need until it passes.

@ncruces
Copy link
Collaborator Author

ncruces commented Feb 9, 2023

A point I made on #1111 is that since this is AOT you can do the CPUID at compile time, because for this specific instruction, doing it at run-time might not make sense (querying the CPU might negate the performance benefit of using the instruction in the first place). I'm sure you wizards know this already.

But feel free to close the PR. The point of it was only to facilitate testing that it was indeed a CPU issue. I tested it on every HW/OS I have access to, and (now) also your CI.

@codefromthecrypt
Copy link
Contributor

@ncruces thanks again for the help.

Basically you are saying that since we don't compile for other archs (only the current one), detecting the host cpuid is going to be correct for all module compilation.

So, the idea is that we could have detection implemented as a _amd64 file, for example leveraging a .s file as the dep is doing. We could store that as a constant in amd64Compiler, though for unit tests maybe a field is fine also.

As you also mentioned, we could just generally avoid the problematic instructions, but I don't personally know the impact of that. It is possible that impact could be evaluated with benchmarks, also, especially if we allow toggle of this for testing, the test even where LZCNTL and TZCNTL are fine can try wasm that would compile down to using them, without using them.

I'm going to hand this off to @evacchi to noodle on. If I mis-restated anything above lemme know!

@ncruces
Copy link
Collaborator Author

ncruces commented Feb 9, 2023

It needs to be a field, not a const. Or, even, you run the check every single time.

Basically by compile-time I mean load-time, when you AOT compile the WASM binary into ASM. Then, at “WASM-runtime” you can use the instruction without checking since it's the same CPU.

This means you can freely use instructions where just making the check negates the benefit.

@mathetake
Copy link
Member

cool, let's implement cpuid.HasExtraFeature(cpuid.ABM) by ourselves. Assigning @evacchi

Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
@ncruces
Copy link
Collaborator Author

ncruces commented Feb 10, 2023

New implementation should, I expect, be easier to follow.
Again, feel free to close at your convenience.

@mathetake
Copy link
Member

with the CPUID, #580 this could also be resolved

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