Skip to content

Reduce monomophic versions of bswap in DataView #1717

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

Merged
merged 2 commits into from
Mar 8, 2021
Merged

Reduce monomophic versions of bswap in DataView #1717

merged 2 commits into from
Mar 8, 2021

Conversation

MaxGraey
Copy link
Member

@MaxGraey MaxGraey commented Mar 6, 2021

  • I've read the contributing guidelines

@MaxGraey MaxGraey requested a review from dcodeIO March 6, 2021 19:27
} else if (sizeof<T>() == 4) {
return <T>(((value << 8) & <T>0xFF00) | ((value >> 8) & <T>0x00FF) | (value & <T>0xFFFF0000));
return <T>(((value << 8) & <T>0xFF00) | ((value >>> 8) & <T>0x00FF) | (value & <T>0xFFFF0000));
Copy link
Member

Choose a reason for hiding this comment

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

Wondering a bit about the usefulness of bswap16, since we are not using it anywhere. What are typical use cases for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

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, hmm. If I'm not mistaken, semantics there seem a little different tho in that high bits are discarded.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes. bswap16 preserve high part of value while bswap<u16> don't

Copy link
Member

@dcodeIO dcodeIO Mar 7, 2021

Choose a reason for hiding this comment

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

Do you think it would be possible to integrate it into bswap, as bswap<u16>, given the assumption that discarding high bits is fine? For i16, we'd then also sign extend after swapping I guess. (Doesn't need to be done in this PR)

Copy link
Member Author

@MaxGraey MaxGraey Mar 7, 2021

Choose a reason for hiding this comment

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

I think we could remove swap16 at least for now. I don't remind where it needed. Anyway this easily implement in user space if it really required in some project. wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I guess we could do this similar to other generic builtins. For instance, load and load16_s also become just a generic load<T>, and I'd expect bswap and bswap16 to become a single bswap<T> as well. On bswap<i16>, the input is already known to have garbage in the high bits, so doing either just a bswap16 on unsigned or a bswap16 + sign-extend on signed seems sufficient.

@dcodeIO dcodeIO merged commit b192a49 into AssemblyScript:master Mar 8, 2021
@MaxGraey MaxGraey deleted the backport-dataview-improvements branch March 8, 2021 11:07
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.

2 participants