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

test: Fix comparing of floating point results in spectest runner #460

Merged
merged 4 commits into from
Aug 7, 2020

Conversation

gumb0
Copy link
Collaborator

@gumb0 gumb0 commented Aug 5, 2020

No description provided.

@codecov
Copy link

codecov bot commented Aug 5, 2020

Codecov Report

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

@@           Coverage Diff           @@
##           master     #460   +/-   ##
=======================================
  Coverage   99.51%   99.51%           
=======================================
  Files          54       54           
  Lines       15120    15153   +33     
=======================================
+ Hits        15046    15079   +33     
  Misses         74       74           

@gumb0 gumb0 requested review from chfast and axic August 5, 2020 17:59
Copy link
Collaborator

@chfast chfast left a comment

Choose a reason for hiding this comment

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

Any smoketests additions?

bool float_values_equal(fizzy::Value value1, fizzy::Value value2) noexcept
{
if (std::isnan(value1.as<float>()))
return value1.as<uint32_t>() == value2.as<uint32_t>(); // compare binary representations
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is quite close to undefined behavior: only single union member may be active at any point in time and you are allowed to only access the active one. Here you are accessing two members is a row - one of the accesses must be wrong.

But also to simplify: you can always compare binary representation of floats. I would just leave return value1.as<uint32_t>() == value2.as<uint32_t>();.

Also: add the following check in value.hpp: static_assert(offsetof(Value, f32) == offsetof(Value, i32));.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(now I see why you needed to_uint64/from_uint64)

Well ok, then the current way here it will be UB only for NaN case, but if I do always as<uint32_t>() then always...

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's actually not true, because you always set i64 to active in read_value(). In theory, you are never allowed to access f32 nor f64. But I doubt this will cause issues in practice. However, I had issues with performing type punning using unions in GCC before (when the misuse is obvious, in the same function).

But my motivation to always use "binary" representation for comparison is to make sure this is a reliable method and there are no regressions in running spectests.

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 was replaced to comparison using FP utility from #454

@gumb0 gumb0 force-pushed the spectest-float-comparison branch from 35c33d6 to 70ca840 Compare August 5, 2020 18:39
@chfast
Copy link
Collaborator

chfast commented Aug 6, 2020

No spectests results change is expected here?

@gumb0
Copy link
Collaborator Author

gumb0 commented Aug 6, 2020

No spectests results change is expected here?

No, I guess because all NaN tests are skipped on master so far.

@chfast chfast changed the base branch from master to fp_utils August 6, 2020 11:03
@chfast chfast force-pushed the fp_utils branch 4 times, most recently from f1de6c7 to d8d44aa Compare August 6, 2020 11:49
@gumb0 gumb0 force-pushed the spectest-float-comparison branch 4 times, most recently from ca41f68 to d204758 Compare August 6, 2020 13:49
const uint64_t uint_value = std::stoull(v.at("value").get<std::string>());

if (type == "i32" || type == "i64")
return uint_value;
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 decided for now not to complicate it with checking if the value declared as 32-bit is really not wider. It won't result in UB if it happens.

Base automatically changed from fp_utils to master August 7, 2020 13:51
@gumb0 gumb0 force-pushed the spectest-float-comparison branch from ad1bee0 to 2ef71c1 Compare August 7, 2020 13:57
@@ -40,9 +40,15 @@
;; invalid result
(module
(func (export "foo.i32") (result i32) (i32.const 1))
(func (export "foo.i64") (result i64) (i64.const 1))
(func (export "foo.f32") (result f32) (f32.const 1))
(func (export "foo.f64") (result f64) (f64.const 1))
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to use actual floats for these, to be sure. Such as 1.234.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed

if (arg_type != "i32" && arg_type != "i64" && arg_type != "f32" && arg_type != "f64")
const auto type = v.at("type").get<std::string>();

// JSON tests have all values including floats serialized as 64-bit unsigned integers
Copy link
Member

Choose a reason for hiding this comment

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

Not that JSON supports the whole 64-bit 😉

Copy link
Collaborator

Choose a reason for hiding this comment

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

The format supports arbitrary long literals, in theory.

@gumb0 gumb0 force-pushed the spectest-float-comparison branch from 2ef71c1 to 6c48a0e Compare August 7, 2020 14:15
@gumb0 gumb0 merged commit 162c066 into master Aug 7, 2020
@gumb0 gumb0 deleted the spectest-float-comparison branch August 7, 2020 17:17
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