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

WASM.SIMD BitSelect & Shuffle ops + Tests #3763

Merged
merged 5 commits into from
Sep 26, 2017

Conversation

Krovatkin
Copy link
Collaborator

@Krovatkin Krovatkin commented Sep 19, 2017

This PR adds

  • BitSelect + tests
  • Shuffle + tests

This change is Reviewable

shuffle decoding

new opcode?

shuffle working

get rid of unaligned, compress asmshuffle bytecode encoding, format fixes

code cleanup
@Krovatkin
Copy link
Collaborator Author

@Cellule could you please take a look when you have a mnt? Thanks!

@Cellule Cellule added this to the vNext milestone Sep 19, 2017
@Krovatkin
Copy link
Collaborator Author

ping @Cellule

@Krovatkin
Copy link
Collaborator Author

@Cellule ping.

@Cellule
Copy link
Contributor

Cellule commented Sep 25, 2017

Reviewed 23 of 23 files at r1.
Review status: all files reviewed at latest revision, 9 unresolved discussions.


lib/Backend/IRBuilderAsmJs.cpp, line 3986 at r1 (raw file):

IRBuilderAsmJs::BuildInt32x4_4(Js::OpCodeAsmJs newOpcode, uint32 offset, BUILD_SIMD_ARGS_REG4)
{
    ValueType valueType = GetSimdValueTypeFromIRType(TySimd128F4);

Shouldn't the IRType be TySimd128I4 in this function ?


lib/Backend/IRBuilderAsmJs.cpp, line 5843 at r1 (raw file):

    IR::RegOpnd * src2Opnd = BuildSrcOpnd(GetRegSlotFromSimd128Reg(layout->R2), TySimd128U16);

    IR::RegOpnd * src3Opnd =  (IR::RegOpnd*)IR::IntConstOpnd::New(layout->INDICES[0], TyInt32, this->m_func);

Could we make a loop for these and AddExtendedArg instead of copy/pasting 16 times


lib/Runtime/ByteCode/AsmJsByteCodeWriter.cpp, line 256 at r1 (raw file):

    bool AsmJsByteCodeWriter::TryWriteAsmShuffle(OpCodeAsmJs op, RegSlot R0, RegSlot R1, RegSlot R2, uint8 indices[])
    {
        const uint32 MAX_LANES = 16;

Can we use Wasm::Simd::MAX_LANES instead ?
Same on other places where we have an hardcoded 16


lib/Runtime/ByteCode/OpCodesSimd.h, line 432 at r1 (raw file):

V8

Shouldn't this be U8 ?


lib/Runtime/Language/InterpreterProcessOpCodeAsmJs.h, line 2187 at r1 (raw file):

// v8x16shuffle
#define PROCESS_SIMD_V8X16_2I16toV8X16_1_COMMON(name, func, suffix) \

This is very specific, could we just make this a CUSTOM process and use a helper instead.


lib/WasmReader/WasmBinaryReader.cpp, line 605 at r1 (raw file):

void WasmBinaryReader::ShuffleNode()
{
    for (uint32 i = 0; i < Simd::MAX_LANES; i++)

Add CheckBytesLeft(Simd::MAX_LANES);


lib/WasmReader/WasmByteCodeGenerator.cpp, line 1457 at r1 (raw file):

}

EmitInfo WasmBytecodeGenerator::EnregisterIntConst(uint constVal)

I don't see any other uses of this function, do we really need to extract this ?


lib/WasmReader/WasmByteCodeGenerator.cpp, line 1484 at r1 (raw file):

EmitInfo WasmBytecodeGenerator::EmitM128BitSelect()
{
    EmitInfo mask = PopEvalStack(WasmTypes::M128, _u("Argument should be of type M128"));

We can leave the default error message for type mismatch. This message shows less information than the default


lib/WasmReader/WasmByteCodeGenerator.cpp, line 1510 at r1 (raw file):

    }

    m_writer->AsmShuffle(Js::OpCodeAsmJs::Simd128_Shuffle_V8X16, resultReg, arg1Info.location, arg2Info.location, GetReader()->m_currentNode.shuffle.indices);

nit: just use indices here instead of using the reader again


Comments from Reviewable

@Krovatkin
Copy link
Collaborator Author

Review status: all files reviewed at latest revision, 9 unresolved discussions.


lib/Runtime/ByteCode/OpCodesSimd.h, line 432 at r1 (raw file):

Previously, Cellule (Michael Ferris) wrote…

V8

Shouldn't this be U8 ?

There's already Simd128_Shuffle_U16 which uses a different implementation to extract indices. I find Simd128_Shuffle_V8X16 to be a bit more consistent w/ the corresponding WASM opcode.


Comments from Reviewable

@Krovatkin
Copy link
Collaborator Author

tagging @arunetm

@Cellule
Copy link
Contributor

Cellule commented Sep 25, 2017

Reviewed 9 of 9 files at r2.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


lib/Runtime/Language/InterpreterStackFrame.h, line 264 at r2 (raw file):

        template <class T> void OP_SimdUint32x4FromFloat32x4(const unaligned T* playout);
        template <class T> void OP_WasmSimdConst(const unaligned T* playout);
        template <class T> inline void OP_SimdShuffleV8X16(const unaligned T* playout);

nit: inline is not necessary


lib/WasmReader/WasmBinaryReader.cpp, line 609 at r2 (raw file):

        m_currentNode.shuffle.indices[i] = ReadConst<uint8>();
    }
    CheckBytesLeft(Simd::MAX_LANES);

We should check before reading the byte as it could potentially trigger an A/V


Comments from Reviewable

@@ -51,6 +51,9 @@ namespace Js
IMP_IWASM void AsmReg9(OpCodeAsmJs op, RegSlot R0, RegSlot R1, RegSlot R2, RegSlot R3, RegSlot R4, RegSlot R5, RegSlot R6, RegSlot R7, RegSlot R8);
IMP_IWASM void AsmReg17(OpCodeAsmJs op, RegSlot R0, RegSlot R1, RegSlot R2, RegSlot R3, RegSlot R4, RegSlot R5, RegSlot R6, RegSlot R7, RegSlot R8,
RegSlot R9, RegSlot R10, RegSlot R11, RegSlot R12, RegSlot R13, RegSlot R14, RegSlot R15, RegSlot R16);
IMP_IWASM void AsmReg19(OpCodeAsmJs op, RegSlot R0, RegSlot R1, RegSlot R2, RegSlot R3, RegSlot R4, RegSlot R5, RegSlot R6, RegSlot R7, RegSlot R8,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the change with AsmReg19? Seems like this isn't being used in wasm?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch!

@Krovatkin
Copy link
Collaborator Author

@Cellule could you please give it another look?

@Krovatkin
Copy link
Collaborator Author

Review status: 22 of 25 files reviewed at latest revision, 3 unresolved discussions.


lib/WasmReader/WasmBinaryReader.cpp, line 609 at r2 (raw file):

Previously, Cellule (Michael Ferris) wrote…

We should check before reading the byte as it could potentially trigger an A/V

oh, my bad. I thought I'd put before the loop


Comments from Reviewable

@Cellule
Copy link
Contributor

Cellule commented Sep 25, 2017

:lgtm:


Reviewed 3 of 3 files at r3, 2 of 2 files at r4.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


Comments from Reviewable

@Cellule
Copy link
Contributor

Cellule commented Sep 25, 2017

@dotnet-bot test this please

@Krovatkin
Copy link
Collaborator Author

@dotnet-bot test Windows 7 ci_dev12_x64_debug please

@Krovatkin
Copy link
Collaborator Author

@Cellule did you do test this because Windows 7 ci_dev12_x64_debug got stuck or was it another error?

@Krovatkin
Copy link
Collaborator Author

@Cellule @MikeHolman guys could one of you please help me to merge this change?

@chakrabot chakrabot merged commit b1761af into chakra-core:wasm.simd Sep 26, 2017
chakrabot pushed a commit that referenced this pull request Sep 26, 2017
Merge pull request #3763 from Krovatkin:wasm.bitselect2

This PR adds
 * BitSelect + tests
 * Shuffle + tests
@Krovatkin
Copy link
Collaborator Author

@MikeHolman @Cellule , thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants