Skip to content

SIMD narrowing and widening operations#2341

Merged
tlively merged 2 commits intoWebAssembly:masterfrom
tlively:narrowing-widening
Sep 14, 2019
Merged

SIMD narrowing and widening operations#2341
tlively merged 2 commits intoWebAssembly:masterfrom
tlively:narrowing-widening

Conversation

@tlively
Copy link
Copy Markdown
Member

@tlively tlively commented Sep 13, 2019

@tlively tlively requested review from aheejin and kripken September 13, 2019 21:15
Comment thread src/wasm/literal.cpp
}
if (val < WideT(std::numeric_limits<T>::min())) {
return Literal(int32_t(std::numeric_limits<T>::min()));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could this code be simpler as

if (val > ..) val = ..::max()
else if (val < ..) val = ..::min()
return Literal(int32_t(val));

?

Comment thread src/wasm/literal.cpp
LaneArray<Lanes* 2> lanes = (vec.*IntoLanes)();
LaneArray<Lanes> result;
for (size_t i = 0; i < Lanes; ++i) {
result[i] = lanes[(Side == LaneOrder::Low) ? i : i + Lanes];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this handle sign/zero extension separately?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The extension is handled by the IntoLanes template parameter. For example, when IntoLanes is getLanesSI8x16 the lanes are sign extended but when it is getLanesUI8x16 they are zero extended.

Comment thread src/wasm/literal.cpp

template<typename T>
Literal saturating_narrow(
typename TwiceWidth<typename std::make_signed<T>::type>::type val) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this handle when val is an unsigned number that exceeds its signed version's max?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The narrowing operations always treat the input lanes as signed, so this can't happen.

@tlively tlively merged commit 844998f into WebAssembly:master Sep 14, 2019
@tlively tlively deleted the narrowing-widening branch April 24, 2020 23:19
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