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

Implement float->int trunc instructions #447

Merged
merged 3 commits into from
Aug 8, 2020
Merged

Implement float->int trunc instructions #447

merged 3 commits into from
Aug 8, 2020

Conversation

chfast
Copy link
Collaborator

@chfast chfast commented Jul 31, 2020

The operator from the wasm spec is partial, i.e. it has some undefined results.
image
But, the execution spec requires to trap on operator's undefined result.
image

@codecov
Copy link

codecov bot commented Jul 31, 2020

Codecov Report

Merging #447 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           master     #447    +/-   ##
========================================
  Coverage   99.51%   99.51%            
========================================
  Files          54       54            
  Lines       15153    15349   +196     
========================================
+ Hits        15079    15275   +196     
  Misses         74       74            

@chfast chfast changed the title Implement iNN_trunc_fMM_sx Implement float->int conversion instructions Jul 31, 2020
@chfast chfast force-pushed the fp_trunc branch 3 times, most recently from 4255355 to e2cb827 Compare July 31, 2020 16:02
@chfast chfast marked this pull request as ready for review July 31, 2020 16:11
@chfast chfast requested review from axic and gumb0 July 31, 2020 16:11
@gumb0
Copy link
Collaborator

gumb0 commented Jul 31, 2020

Please rebase.

@axic

This comment has been minimized.

@chfast chfast force-pushed the fp_trunc branch 2 times, most recently from 95e605e to c71fe26 Compare July 31, 2020 19:32
@chfast chfast marked this pull request as draft July 31, 2020 20:54
@chfast chfast changed the base branch from master to test_result_signed_int August 4, 2020 09:05
@chfast chfast marked this pull request as ready for review August 4, 2020 09:27
@chfast chfast requested a review from gumb0 August 4, 2020 09:27
Base automatically changed from test_result_signed_int to master August 4, 2020 12:38
@chfast chfast force-pushed the fp_trunc branch 2 times, most recently from 5bcde1d to 1de5c68 Compare August 4, 2020 12:59
@chfast chfast changed the base branch from master to fp_utils August 4, 2020 12:59
@chfast chfast force-pushed the fp_trunc branch 3 times, most recently from db2c82e to c0d90b6 Compare August 4, 2020 14:03
@chfast chfast force-pushed the fp_utils branch 3 times, most recently from 707f100 to 167c41b Compare August 7, 2020 13:32
Base automatically changed from fp_utils to master August 7, 2020 13:51
circle.yml Outdated Show resolved Hide resolved
lib/fizzy/execute.cpp Outdated Show resolved Hide resolved
using boundaries = trunc_boundaries<SrcT, DstT>;

const auto input = stack.top().as<SrcT>();
if (std::isnan(input) || input <= boundaries::lower || input >= boundaries::upper)
Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't this need to check for inf/-inf?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because always: -inf <= boundaries::lower and inf >= boundaries::upper.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, actually, this can be optimized :/

Copy link
Member

@axic axic Aug 7, 2020

Choose a reason for hiding this comment

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

Even if that is true (seemingly it is because the tests pass), we should have a static_assert here for that, so that anyone reading the code understands the rules of wasm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure what assert you would like to have here.

Copy link
Member

Choose a reason for hiding this comment

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

-inf <= boundaries::lower
inf >= boundaries::lower

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, this does not make sense to me. Every value is >= -inf.

stack.top() = static_cast<DstT>(input);
return true;
}
return false;
Copy link
Member

Choose a reason for hiding this comment

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

After the optimisation I'd add assert(std::isnan(input) || input == inf || input == -inf); so that it matches the spec.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, added correct variants of these asserts.

Copy link
Member

Choose a reason for hiding this comment

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

Don't want to stretch this too much, but can we also have the static_assert for inf vs. boundaries? Obviously we cannot make the nan-check compile time :)

Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

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

Looks good to me otherwise.

@chfast
Copy link
Collaborator Author

chfast commented Aug 7, 2020

Looks good to me otherwise.

So what now?

@axic
Copy link
Member

axic commented Aug 7, 2020

So what now?

Dunno, merge?

@chfast chfast merged commit 84e6f81 into master Aug 8, 2020
@chfast chfast deleted the fp_trunc branch August 8, 2020 06:42
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.

3 participants