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

Support SSE legacy instructions for the SInglepass compiler #2767

Closed
batconjurer opened this issue Jan 26, 2022 · 6 comments · Fixed by #2775
Closed

Support SSE legacy instructions for the SInglepass compiler #2767

batconjurer opened this issue Jan 26, 2022 · 6 comments · Fixed by #2775
Labels
🎉 enhancement New feature! priority-medium Medium priority issue

Comments

@batconjurer
Copy link
Contributor

batconjurer commented Jan 26, 2022

Motivation

I am trying to run a block chain node on my home server and the chain uses wasmer for its smart contracts. My server uses the legacy SSE 4.2 instructions so when trying to compile the wasm code using the singlepass compiler, I get an error because only the newer AVX instructions are supported.

We should support these legacy instructions as many machines out there still use them and new computers are still being sold with chips that use them.

Proposed solution

I looked at emitter_x64.rs and I see that the AVX instructions used mostly have an SSE counterpart. Non-destructive instructions were introduced in AVX. For SSE, to achieve the same behavior, requires two instructions: A move and then the destructive instruction.

Some ops such as blendvps only have support on SSE 4.1, so it will have to mimicked for older SSE versions if those are to be supported.

@batconjurer batconjurer added the 🎉 enhancement New feature! label Jan 26, 2022
@syrusakbary
Copy link
Member

syrusakbary commented Jan 26, 2022

It would be great to have a PR so we can take a look. We should emit the optimal AVX code when possible (if the CpuFeature::AVX is available on the host) and SSE 4.2 in case CpuFeature::SSE42 is present (and not AVX).

The target already contains the cpu_features, and the Target is provided to the compiler when compiling, so we can get the features from there.

https://docs.rs/wasmer/2.0.0/wasmer/struct.Target.html#method.cpu_features
https://docs.rs/wasmer/2.0.0/wasmer/enum.CpuFeature.html

@syrusakbary
Copy link
Member

Adding @ptitSeb to also confirm from our side that everything should be good with this strategy

@ptitSeb
Copy link
Contributor

ptitSeb commented Jan 26, 2022

Sounds good to me (and requiring AVX is a bit overkill, so I'm good with an SSE only option)

@batconjurer
Copy link
Contributor Author

I've hacked together a decent amount of the SSE code, so I will do a bit of clean up and can start a PR. If we go with SSE 4.2 only, this will be pretty easy I think. If we want to support older SSE, this will require more work and I haven't finished investigating how much.

@syrusakbary
Copy link
Member

I think SSE 4.2 should be fine for now (we can always add more support for older SSE apart)

@Amanieu Amanieu added the priority-medium Medium priority issue label Feb 9, 2022
bors bot added a commit that referenced this issue Feb 17, 2022
2775: Support SSE 4.2 for the Singlepass compiler r=ptitSeb a=batconjurer

Closes #2767 

# Description
This PR adds support for the SSE 4.2 instruction set in the singlepass compiler. Previously, only AVX was supported. This implementation may also work for SSE 4.1, but this should be double checked. It does use the `blendvps` instruction indroduced in SSE 4.1, so it cannot support any earlier SSE versions at present for sure. 

The following are the main changes:
 - The assembler has changed from a Vec<X64Relocation> to a struct containing this as well as the corresponding CPU feature (indicating AVX/SSE4.2/...)
 - A set of SSE function macros have been added. To handle non-destructive operations, additional moves may be made before executing the corresponding SSE instruction if `src1 != dst`
 - A minor change to the `EmitterX64` trait. It now has a function for returning a possible CPU feature.
 - The implementation of `EmitterX64` for the assembler has obviously changed. It chooses the emitted assembly based on the CPU feature.


Co-authored-by: R2D2 <[email protected]>
Co-authored-by: Jacob Turner <[email protected]>
@bors bors bot closed this as completed in fba8465 Feb 17, 2022
@hasselalcala
Copy link

Hello!

I new learning near and sandbox and I have the next problem Captura de pantalla 2024-04-24 a la(s) 11 57 39 a m

and I found this issue near/near-workspaces-rs#110

Im not sure how to proceed because I am having problems to test my contracts.

Any idea? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature! priority-medium Medium priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants