-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Initial PR for Wasm.Simd. Includes build/extract and binary arithmetic ops. #2736
Conversation
running simple SIMD tests build ops generating signatures with macroses running simple tests for simd build ops bbrk fix multi-byte reader all opcodes enabling build and extract ops back separate op file, using flag i8x16, i16x8 fixes float fix & i8x16 boolean type fix aruns comments binary arithmetics fixes, review r2 more fixes fixed macros fixes build & extract tests removing the uneccessary part of fix 7c63df5 renaming wast files for consistency
@Cellule @MikeHolman Please take a look whenever you have a moment! Thanks! |
@LouisLaf review please. Thanks. |
I was wondering how are you generating the .wasm files ? |
@Cellule https://github.com/WebAssembly/wabt/compare/master...Krovatkin:simd?expand=1 |
@Cellule We had extended wabt to generate the multibyte simd opcodes. Agree that it make sense to maintain a fork with those changes and build on it as needed. Should we create a new fork for this, or clean up krovatkin's fork for the time being? |
@arunetm dotnet/dotnet-ci#626 is merged and it looks like the CI is online. |
I understand the current PR is to get up and running with a prototype, but I think we should go a different direction with the wasm design. I envision that we add a single new local type to wasm, e.g. Assuming we have: We can also have some SIMD type specific operations for creating a SIMD value using other local types popped from the stack, for example something like What do you think about this? |
Reviewed 11 of 39 files at r1, 4 of 8 files at r2. lib/Backend/LowerMDSharedSimd128.cpp, line 3030 at r2 (raw file):
Here you can do lib/Common/ConfigFlagsList.h, line 864 at r2 (raw file):
The lib/Runtime/Language/InterpreterStackFrame.cpp, line 2328 at r2 (raw file):
Since type is a template argument, you should make this a lib/Runtime/Language/InterpreterStackFrame.cpp, line 2329 at r2 (raw file):
I think we should add a function Also, good to note, we don't allow Comments from Reviewable |
@MikeHolman fyi @arunetm @Cellule Could you please help us to understand the main benefits you see of this new design?
let a = SIMD.Int32x4(1,1,1,1);
let b = SIMD.Int32x4(2,2,2,2);
let c = SIMD.Bool32x4.xor(a,b);
print (c); While there is more than one phase in which the type checks could be done, the bytecode generation seemed to be the most suitable.
|
@MikeHolman, Thanks for the feedback. @dilijev Thanks, it works. 👍 |
Is there any benefit for code generators to have strong typing for simd types? My understanding is that the simd ops are generally just reinterpretations of bytes in xmm registers? Wasm doesn't have differentiated signed and unsigned types, but different ops interpret them differently. My proposal would follow that model. Possibly other architectures' implementations of simd aren't as polymorphic as x86/x64, but I'm not sure. This just makes the point stronger that there should be a real design proposal. I think the other wasm committee members also would prefer 1 new local type for simd128 to 6+, but it is something that needs discussion. |
@arunetm @Krovatkin
As @MikeHolman said, I do believe we should have a formal proposal for simd in wasm. |
I guess, the "strongest" argument for strong typing has and always will be to reduce the number of logical errors.
I think we might need an initial "Chakra" implementation rather than a prototype because prototypes are usually decoupled from real-world scenarios. Implementing a feature in Chakra gives us a feel of what approaches could work, how feasible and complex they could get when implemented (in general and specifically in Chakra), so we could argue for a particular case and back it up w/ some evidence saying that "the implementation A is a way too complex or impractical in general." It also highlights the parts in Chakra where the coupling gets too tight meaning that one small change could ripple through the entire runtime, so we could try to isolate/decouple those cases. |
@Krovatkin What I meant is for you to prototype with chakra, just not in the Microsoft repository, by using a GitHub fork. That way you are free to test however you like and once it is to your liking/got some design approval we can merge it back into the Microsoft repository. |
Agree that we need to have a formal proposal in place and have these encoding/design discussions as part of the wasm spec involving the community. For now, we are relying on the following simd wasm draft proposal based on a portable subset of the SIMD.js spec - https://github.com/stoklund/portable-simd We are looking to have feedback on a Chakra implementation(code review and solution design) of the basic types and ops (which should not change significantly for wasm.simd) from the above draft. This can be handy during the actual proposal/design. This implementation is making some assumptions on the wasm.simd encoding which I think can be easily updated without much effort based on the final design. Will revisit the way to achieve this and update this PR. Thanks! |
Type safety can be managed at a higher level than the wasm level. Right now every instruction in wasm helps to generate code. Adding 32 reinterpret casts, which are just for type safety seems excessive. A wasm producer can emit warnings for implicit conversions if it wants, though it's a bit unclear to me how you would really get safety in any case, e.g. at the c++ level there is not a type for each of these, is there? It feels like we are adding an abstraction layer in wasm that doesn't even exist at the source level. In general, we should be making things lower level when translating to wasm, not higher. |
@Cellule @MikeHolman relaxed type checking. Since the rest of the compiler doesn't have one single type for m128, I'm using fyi @arunetm |
I think that's fine for initial prototype. |
There are a few places in interpreter where we check IsSimdjsEnabled. I think that we will need to add condition to check if WasmSimd is enabled for some of these cases (they generally relate to arguments/return value). |
Thanks, yes will fix the feature enabling checks as applicable. |
@MikeHolman can you please sign off this PR if all looks well. I should be able to merge this to the WASM.Simd feature branch once approved and signed. |
Sure, just want to give @Cellule gets a chance to sign off since he had some comments. |
I'll check. |
…ract and binary arithmetic ops. Merge pull request #2736 from Krovatkin:wasm-simd-collab This PR includes * A list of SIMD opcodes * Initial extensions to WasmBytecodeGenerator and WasmBinaryReader to support reading and generating bytecodes for `extract`, `build` and arithmetic binary operations. * Tests for these operations * A few fixes The fixes include: * https://github.com/Microsoft/ChakraCore/pull/2736/files#diff-b0ef4db6dba17fc268e8745b695badceL1117 * https://github.com/Microsoft/ChakraCore/pull/2736/files#diff-9d396b386e20933b7bfbec028a04e8c9R248 * https://github.com/Microsoft/ChakraCore/pull/2736/files#diff-314ffb76644084b820e66bdfe3f879d9R377 In this version, we decided to not group SIMD operations into one case arm since this way we could encapsulate all SIMD-related reading logic in `ReadOpCode`. We could always move all SIMD ops into a separate case arm later. I temp disabled short-signature comparisons since I didn't know what the best way would be to extend it to support SIMD types.
This PR includes
extract
,build
and arithmetic binary operations.The fixes include:
In this version, we decided to not group SIMD operations into one case arm since this way we could encapsulate all SIMD-related reading logic in
ReadOpCode
. We could always move all SIMD ops into a separate case arm later.I temp disabled short-signature comparisons since I didn't know what the best way would be to extend it to support SIMD types.