SIMD narrowing and widening operations#2341
Merged
tlively merged 2 commits intoWebAssembly:masterfrom Sep 14, 2019
Merged
Conversation
kripken
approved these changes
Sep 13, 2019
| } | ||
| if (val < WideT(std::numeric_limits<T>::min())) { | ||
| return Literal(int32_t(std::numeric_limits<T>::min())); | ||
| } |
Member
There was a problem hiding this comment.
could this code be simpler as
if (val > ..) val = ..::max()
else if (val < ..) val = ..::min()
return Literal(int32_t(val));
?
aheejin
approved these changes
Sep 13, 2019
| 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]; |
Member
There was a problem hiding this comment.
Does this handle sign/zero extension separately?
Member
Author
There was a problem hiding this comment.
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.
|
|
||
| template<typename T> | ||
| Literal saturating_narrow( | ||
| typename TwiceWidth<typename std::make_signed<T>::type>::type val) { |
Member
There was a problem hiding this comment.
Does this handle when val is an unsigned number that exceeds its signed version's max?
Member
Author
There was a problem hiding this comment.
The narrowing operations always treat the input lanes as signed, so this can't happen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As specified at https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#integer-to-integer-narrowing.