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

Simd i8x16.extract_lane_s instruction implementation. #802

Merged

Conversation

lizhengxing
Copy link
Contributor

Including:

  1. All necessary code for SIMD lanes accessing.
  2. i8x16.extract_lane_s implementation.

@lizhengxing
Copy link
Contributor Author

@binji
SIMD i8x16.extract_lane_s implementation, PTAL!

SIMD Lane accessing instructions implementation is a little bit complex. It might take you much time to review it. Thanks!

@arunetm FYI!

src/interp.cc Outdated
// Simd instructions with Lane operand.
// a0: input v128 value. a1: lane index.
// typename T: lane data type.
template <typename R, typename V0, typename V1, typename T>
Copy link
Member

Choose a reason for hiding this comment

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

Is there a need to have differing lane index types? I think this can always be int (instead of using V1).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/interp.cc Outdated
// a0: input v128 value. a1: lane index.
// typename T: lane data type.
template <typename R, typename V0, typename V1, typename T>
ValueTypeRep<R> SimdExtractLane(V0 a0, V1 a1) {
Copy link
Member

Choose a reason for hiding this comment

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

Better name for a1? Perhaps lane or index.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -195,6 +195,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
wabt::Result OnTernaryExpr(wabt::Opcode opcode) override;
wabt::Result OnUnreachableExpr() override;
wabt::Result EndFunctionBody(Index index) override;
wabt::Result OnSimd1LaneImmExpr(wabt::Opcode opcode, Type type, uint32_t value) override;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this called Simd1LaneImm? I suppose it will be used for extract and replace lane, is that why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, extract and replace lane only have 1 lane immediate parameter. But v8x16.shuffle have 16 lane Immediate parameters.

@@ -353,6 +353,11 @@ Result BinaryReaderLogging::OnTryExpr(Index num_types, Type* sig_types) {
return reader_->OnTryExpr(num_types, sig_types);
}

Result BinaryReaderLogging::OnSimd1LaneImmExpr(Opcode opcode, Type type, uint32_t value) {
LOGF("OnSimdLaneExpr (lane: %d)\n", value);
Copy link
Member

Choose a reason for hiding this comment

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

Match function name here: OnSimd1LaneImmExpr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the omission. I will fix it, Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/interp.cc Outdated
@@ -2414,6 +2434,13 @@ Result Thread::Run(int num_instructions) {
break;
}

case Opcode::I8X16ExtractLaneS: {
v128 dLane = static_cast<v128>(Pop<v128>());
Copy link
Member

Choose a reason for hiding this comment

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

Better name than dLane here? Other examples in this file use value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/ir.h Outdated
@@ -266,6 +267,18 @@ typedef OpcodeExpr<ExprType::Convert> ConvertExpr;
typedef OpcodeExpr<ExprType::Unary> UnaryExpr;
typedef OpcodeExpr<ExprType::Ternary> TernaryExpr;

template <ExprType TypeEnum, typename T>
Copy link
Member

Choose a reason for hiding this comment

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

No need for template param T here, the lane index will always be < 16. Using int instead is sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider the future v8x16.shuffle implementation.

Copy link
Member

Choose a reason for hiding this comment

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

I see, though I'd say that v8x16.shuffle is different enough to warrant a diferrent Expr type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.
I will use a different Expr type for v8x16.shuffle.


switch (opcode) {
case Opcode::I8X16ExtractLaneS: {
if(const_->v128_bits.v[0] >= 16)
Copy link
Member

Choose a reason for hiding this comment

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

Better to do this check in the validator, so it can be shared when reading text or binary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I will move the check into validator.

Is it ok to omit such type of error in parsing stage?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think so. Any module parsed via text will have to be validated before it can be used in most cases anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Token token = Consume();
ErrorUnlessOpcodeEnabled(token);
Const const_;
CHECK_RESULT((ParseSimdConstWithCheck<uint32_t>(token.opcode(), Type::I32,
Copy link
Member

Choose a reason for hiding this comment

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

Why parse as SimdConst? This should just use ParseNat to parse a natural number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still Consider the future v8x16.shuffle implementation.

ParseNat can only parse 1 natural number. But ParseSimdConst can parse several natural numbers according to the input byte numbers.

Copy link
Member

Choose a reason for hiding this comment

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

OK, this seems a bit overly-generic to me, but I'm OK with this direction for now. We can always refactor later if necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.
use ParsrNat for simd extract/replace lane as v8x16.shuffle will be another Expr type.

Including:
1. All necessary code for SIMD lanes accessing.
2. i8x16.extract_lane_s implementation.
@lizhengxing lizhengxing force-pushed the simd-i8x16-extract-lane-impl-PR branch from 4f81159 to 8944fe9 Compare March 12, 2018 18:30
@lizhengxing
Copy link
Contributor Author

@binji
Updated the PR according to your suggestions, PTAL!
Thanks!

@arunetm FYI!

@lizhengxing lizhengxing force-pushed the simd-i8x16-extract-lane-impl-PR branch 2 times, most recently from e5c1db6 to d85e441 Compare March 12, 2018 21:09
Copy link
Member

@binji binji left a comment

Choose a reason for hiding this comment

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

lgtm, thank you!

@binji binji merged commit 0652fa7 into WebAssembly:master Mar 13, 2018
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.

2 participants