-
-
Notifications
You must be signed in to change notification settings - Fork 670
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
export function bswap<T extends number>(value: T): T { | ||
if (isInteger<T>()) { | ||
if (sizeof<T>() == 2) { | ||
return <T>((value << 8) | ((value >> 8) & <T>0x00FF)); | ||
return <T>((value << 8) | ((value >>> 8) & <T>0x00FF)); | ||
} | ||
if (sizeof<T>() == 4) { | ||
return <T>( | ||
rotl<u32>(<u32>value & 0xFF00FF00, 8) | | ||
rotr<u32>(<u32>value & 0x00FF00FF, 8) | ||
rotl<u32>(value & 0xFF00FF00, 8) | | ||
rotr<u32>(value & 0x00FF00FF, 8) | ||
); | ||
} | ||
if (sizeof<T>() == 8) { | ||
|
@@ -28,9 +28,9 @@ export function bswap<T extends number>(value: T): T { | |
export function bswap16<T extends number>(value: T): T { | ||
if (isInteger<T>() && sizeof<T>() <= 4) { | ||
if (sizeof<T>() == 2) { | ||
return <T>((value << 8) | ((value >> 8) & <T>0x00FF)); | ||
return <T>((value << 8) | ((value >>> 8) & <T>0x00FF)); | ||
} 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering a bit about the usefulness of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know but post-MVP suggest add it: https://github.com/WebAssembly/design/blob/master/FutureFeatures.md#additional-integer-operators There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it would be possible to integrate it into There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, |
||
} | ||
return value; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.