Skip to content
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

Add design/#986 (non-trapping float-to-int) to agenda #3

Merged
merged 6 commits into from
May 19, 2017

Conversation

lukewagner
Copy link
Member

@lukewagner lukewagner commented May 17, 2017

(I'm not sure if this is the process for adding something to the agenda; let's see :)

This issue has been coming up a lot lately; this seems like a quick fix we could make that could yield immediate improvements in usability and performance.

(I'm not sure if this is the process for adding something to the agenda; let's see :)

This issue has been coming up a lot lately; this seems like a quick fix we could make that could have immediate improvements in usability and performance.
@lukewagner lukewagner changed the title Add #986 (non-trapping float-to-int) to agenda Add design/#986 (non-trapping float-to-int) to agenda May 17, 2017
@jfbastien
Copy link
Member

This would fit under performance, though having numbers and proposed semantics would be helpful.

Who's championing this?

Should we explore other non-trapping things, or just this one?

@sunfishcode
Copy link
Member

I propose these semantics:

  • i{32,64}.convert_{s,u}:sat/f{32,64}: positive overflow -> maximum integer, negative overflow -> minimum integer, NaN -> 0. Rationale: ARM, Java. NaN -> 0 is awkward, but other options are awkward too.

Key question: should the existing i{32,64}.convert_{s,u}/f{32,64} opcodes be used for this, or should new opcodes be added?

  • Changing in place: It's unlikely to break compatibility in the real world, and there aren't currently any major producers requiring the trapping behavior, and it saves opcodes.
  • New opcodes: Fully compatible, and it leaves the existing opcode in place which may have future uses, such as C# in a "checked" context, maybe Rust, C/C++ undefined-behavior checkers (eg. UBSan), or non-LLVM-based C/C++ compilers, could want the trapping opcode, especially if there's a trap handler feature in the future.

Float->int conversion is the only trapping operator that has gotten such attention at this point.

There aren't yet any observed performance problems. While there were reports about slowdowns, those were due to Emscripten using calls to imported JS functions. The code in Emscripten has since been changed, and I'm not aware of any reports since.

The main immediate concerns I'm aware of are:

  • LLVM defines float-to-int conversion to be non-trapping (even though float-to-int conversion has full-aardvark UB in C/C++), so the current semantics will require it to insert extra code for conversions, which presumably has overhead which is desirable to avoid (though it hasn't yet been measured).
  • Float-to-int conversion in the SIMD proposal would be the only trapping SIMD operation, and since it's common for hardware SIMD units to be non-trapping, it'd be nice to have wasm's base SIMD instruction set to be entirely non-trapping, to make it easier for hardware designers to implement it directly.

@sunfishcode
Copy link
Member

Hardware ISA survey:

  • ARM, and MIPS in NAN2008 mode, behave as proposed above.
  • x86, and MIPS in "legacy FPU" mode, return the minimum integer in all exceptional cases.
  • Power behaves as proposed above except NaN is converted to the minimum integer.
  • RISC-V behaves as as proposed above except NaN is converted to the maximum integer.

@rossberg
Copy link
Member

Relaxing the existing instructions sounds attractive. Especially since your hardware survey seems to imply that it would actually make them faster on some platforms, in which case I doubt that any producer would still want to use the trapping ones?

@lukewagner
Copy link
Member Author

in which case I doubt that any producer would still want to use the trapping ones?

That was my impression as well.

Renaming seems like a good idea in case later it makes sense, for some other instruction, to have both trapping/saturating variants of the same logical operation.

@lukewagner
Copy link
Member Author

So are we good to add this to the agenda (merge)?

@jfbastien
Copy link
Member

I'd still like to know who's championing it, and will present. At the meeting I'll ask for performance numbers, and which other operations should have the same treatment. I'm OK merging the topic in with the understanding that these questions should be answered in the presentation.

@lukewagner
Copy link
Member Author

I think @sunfishcode volunteered :)

@lukewagner
Copy link
Member Author

lukewagner commented May 18, 2017

On the topic of perf measurements: I think the high-order bit here is removing a source of unnecessary developer pain and for that we do have the "numbers" in the form of many independent people hitting this as Jukka was describing in design/#986. As long as it doesn't regress perf, we should do it; that it should improve perf by some indeterminate amount is just a cherry on top.

@jfbastien
Copy link
Member

This issue has been coming up a lot lately; this seems like a quick fix we could make that could yield immediate improvements in usability and performance.

Was the original pitch. So it's not a performance proposal? I'd rather keep the meeting focused on performance TBH. Do you think this needs to happen soon, or could we wait until the subsequent meeting? With only 2 days I'm confident we can get through threads but am not sure SIMD will be done.

@lukewagner
Copy link
Member Author

Yes, this should happen soon, especially if the conclusion is to change semantics. This is one of the few unnecessary problems many people seem to hit when switching from asm.js to wasm or using wasm for the first time. Also, there seems to already be some amount of consensus.

@lukewagner
Copy link
Member Author

So, can we add this to the agenda? I don't expect it will take much time and it doesn't seem necessary to restrict the meeting to exclusively performance issues.

@jfbastien
Copy link
Member

OK let's add this to the agenda. Can we timebox to 30 min or 1h between threads and SIMD? Can you update the PR accordingly?

@lukewagner
Copy link
Member Author

rgr, PTAL

@jfbastien jfbastien merged commit c4b2fd8 into master May 19, 2017
@jfbastien jfbastien deleted the add-non-trapping branch May 19, 2017 23:37
@rossberg
Copy link
Member

rossberg commented May 24, 2017 via email

@lukewagner
Copy link
Member Author

Would it break anyone in practice, though?

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.

4 participants