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 f{32,64}.nearest instructions #486

Merged
merged 4 commits into from
Aug 21, 2020
Merged

Implement f{32,64}.nearest instructions #486

merged 4 commits into from
Aug 21, 2020

Conversation

chfast
Copy link
Collaborator

@chfast chfast commented Aug 13, 2020

image

@codecov
Copy link

codecov bot commented Aug 14, 2020

Codecov Report

Merging #486 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #486      +/-   ##
==========================================
- Coverage   99.68%   99.67%   -0.01%     
==========================================
  Files          54       54              
  Lines       17218    17108     -110     
==========================================
- Hits        17163    17053     -110     
  Misses         55       55              

@@ -551,6 +552,18 @@ inline T ftrunc(T value) noexcept
return std::trunc(value);
}

template <typename T>
T fnearest(T a) noexcept
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem to enforce the same NaN rules as #481, yet the spec seems to be the same regarding it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have them tested. I was expecting this will fail and I will need if (isnan()) case, but seems not required. Will check against the C spec though.

Copy link
Member

Choose a reason for hiding this comment

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

Did you check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the same as in other related functions: for NaN input it returns unspecified NaN.

Copy link
Member

Choose a reason for hiding this comment

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

Are we making it deterministic for our case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we always return canonical NaN now as in other similar functions.

I also noticed that at least glibc is just setting the "quiet" bit in NaN to 1, leaving all others (including the sign) unchanged.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it is done.

@@ -829,223 +829,6 @@ TEST(execute, memory_copy_32bytes)
EXPECT_EQ(output, input);
}

TEST(execute, fp_instructions)
Copy link
Member

Choose a reason for hiding this comment

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

This is a landmark event!

auto instance = instantiate(parse(this->get_unop_code(Instr::f32_nearest)));
const auto exec = [&](auto arg) { return execute(*instance, 0, {arg}); };

for (const auto& [arg, expected_trunc] : this->positive_trunc_tests)
Copy link
Member

@axic axic Aug 14, 2020

Choose a reason for hiding this comment

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

Note to self:

fnearest(+-inf) = +-inf
fnearest(+-0) = +-0

are included in positive_trunc_tests.

Copy link
Member

Choose a reason for hiding this comment

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

Can you leave this here as a comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added the comment.

Copy link
Member

Choose a reason for hiding this comment

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

Please add this comment for clarity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good now?

@chfast chfast force-pushed the fp_ceil_floor_trunc branch 5 times, most recently from 08def8c to b3282b4 Compare August 19, 2020 15:24
Base automatically changed from fp_ceil_floor_trunc to master August 19, 2020 18:33
@chfast chfast force-pushed the fp_nearest branch 4 times, most recently from 778c3f2 to 4c85f0f Compare August 20, 2020 15:33
@chfast chfast force-pushed the fp_nearest branch 2 times, most recently from 4c862ed to bc2bfea Compare August 20, 2020 19:01
@chfast
Copy link
Collaborator Author

chfast commented Aug 20, 2020

This is a working version with volatile use "synchronize" calls. This is not great, but works at least for the tested compiler configurations.

We may spend another week to:

  • try to synchronize with atomics,
  • report compiler bugs.
    But I think we should go with this version for now.

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 okay bar the comment changes.

@axic axic merged commit a786c7b into master Aug 21, 2020
@axic axic deleted the fp_nearest branch August 21, 2020 22:15
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.

2 participants