-
Notifications
You must be signed in to change notification settings - Fork 695
subnormal_mode #243
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
subnormal_mode #243
Conversation
* `standard`: standard semantics are followed | ||
* `dont_care`: Subnormal values may or may not be interpreted as zero of the | ||
same sign. Subnormal result values may or may not be replaced by any | ||
subnormal value of the same sign, or zero of the same sign. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's "standard"? Wouldn't "IEEE754" be a better name?
I thought that we'd settled on "fastest" instead of "dont_care"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Standard" means the IEEE-754 standard, and also the WebAssembly standard, since it's the behavior we'll otherwise specify. Is there another standard which is remotely as authoritative in this regard?
In my opinion, "fastest" is implied. We always want the fastest performance permitted under the chosen semantics. "dont_care" makes it explicit that the programmer is choosing not to care about what happens, rather than blindly hoping that something named "fastest" will make their program faster without understanding what it means.
I'm still not sure that I like using a block as you propose, versus tagging each individual instruction. We haven't really discussed what happens when there's a call inside of such a block. Do it affect the callee? |
The advantage of a scoped construct is that it eliminates the need for an implementation to run a code placement algorithm to emit reasonably-well optimized mode switching code. By the phrase "lexical extent", I mean that it doesn't apply to callees. One of the main goals here is to make it possible (and easy) to statically determine the mode for every operation. |
The checked/unchecked mechanism in C# is a relevant example here: https://msdn.microsoft.com/en-us/library/74b4xzyw.aspx they recognized that there are multiple levels at which you want to control checking, so they let you decorate a single expression |
Thanks for the reference @kg. That covers integer overflow checking which has some similar usage patterns as subnormal handling, though a few differences as well. Block-level: that's what I'm proposing :-). Module-level: We can achieve similar functionality by just wrapping every function body in a subnormal_mode block. This is also easier for WebAssembly to do than it is for C# because WebAssembly is primarily a compiler target. The user interface can still be to just set a compiler option, and compilers can just make the right thing happen everywhere. Also, module-level flags complicate dynamic linking, so we'd like to avoid them when we can. Per-operation: Unlike integer-overflow checking, subnormal flushing is typically implemented in hardware by setting a control register, and there is a cost each time the mode is changed. Since the point of the mode is to make code go faster, one typically doesn't wish to take on extra costs by changing modes frequently. Consequently, it's much more common and meaningful to just set it once for an entire block of code. |
I support block-level declaration, though IIUC a conforming implementation On Mon, Jul 6, 2015 at 7:51 PM, Dan Gohman [email protected] wrote:
|
Yes. The attribute choices proposed here are "standard" and "dont_care", so using standard mode for everything is fully conforming. |
Please hold on this PR, @davidsehr and I are discussing a different / wider solution. |
450891b
to
28d049d
Compare
After discussing this with people more, I'm ok closing this for now. While a flag to disable subnormals is worth considering, the real-world experience of asm.js tells us that it ultimately isn't necessary for an MVP. |
This PR proposes a subnormal_mode AST node, as a possible resolution to #148.