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

Support floating point globals #446

Merged
merged 6 commits into from
Aug 7, 2020
Merged

Support floating point globals #446

merged 6 commits into from
Aug 7, 2020

Conversation

gumb0
Copy link
Collaborator

@gumb0 gumb0 commented Jul 31, 2020

Depends on #445

@gumb0 gumb0 force-pushed the float-globals branch 2 times, most recently from 4214d5a to e5a248d Compare July 31, 2020 13:36
@codecov
Copy link

codecov bot commented Jul 31, 2020

Codecov Report

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

@@            Coverage Diff             @@
##           master     #446      +/-   ##
==========================================
- Coverage   99.50%   99.50%   -0.01%     
==========================================
  Files          52       52              
  Lines       14813    14937     +124     
==========================================
+ Hits        14740    14863     +123     
- Misses         73       74       +1     

Base automatically changed from spectest-float to master July 31, 2020 16:48
@gumb0 gumb0 force-pushed the float-globals branch 2 times, most recently from b736b49 to 75d90f2 Compare August 3, 2020 10:48
@@ -33,6 +33,18 @@ inline parser_result<uint8_t> parse_byte(const uint8_t* pos, const uint8_t* end)

return {*pos, pos + 1};
}
template <typename T>

inline parser_result<T> read_float_const(const uint8_t* pos, const uint8_t* end)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should this be better named parse_float_const ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

read_constant()? read_constant_bytes()? But maybe keep the original name for now.

@gumb0 gumb0 force-pushed the float-globals branch 6 times, most recently from a966fb7 to 967799e Compare August 3, 2020 13:32
@gumb0 gumb0 force-pushed the float-globals branch 7 times, most recently from 9a536a0 to 287f1fa Compare August 3, 2020 15:51
@gumb0 gumb0 changed the base branch from master to result-matcher-float August 3, 2020 15:52
@gumb0 gumb0 marked this pull request as ready for review August 3, 2020 16:00
@gumb0 gumb0 requested review from chfast and axic August 3, 2020 16:07
Base automatically changed from result-matcher-float to master August 3, 2020 17:49
@@ -126,6 +126,18 @@ inline parser_result<GlobalType> parse_global_type(const uint8_t* pos, const uin
return {type, pos};
}

template <typename T>
inline parser_result<T> read_const(const uint8_t* pos, const uint8_t* end)
Copy link
Member

Choose a reason for hiding this comment

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

Is this read_const or just read/read_value/read_type?

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 considering parse_float_value/parse_float_const because it returns parse_result and is similar to other parse_* functions above and below.

Copy link
Member

Choose a reason for hiding this comment

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

Reading parse_float_const<uint32_t>(..) is extremely confusing, so I would suggest to go with parse_value<uint32_t> or parse_type<uint32_t>, especially as this should do byteswapping should we support big endian targets. Right?

Copy link
Member

Choose a reason for hiding this comment

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

If parse_float_const<float> and parse_float_const<double> works that is fine too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If parse_float_const<float> and parse_float_const<double> works that is fine too.

Not without a cast on a calling side.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That would work (but I would need to check assembly of that to be sure). But might be confusing as you can/will implement fN.const as iN.const: https://github.com/wasmx/fizzy/blob/master/lib/fizzy/execute.cpp#L1004-L1005.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed to parse_value

result.kind = ConstantExpression::Kind::Constant;
result.value.constant = 0;
pos = skip(8, pos, end);
std::tie(result.value.constant, pos) = read_const<uint64_t>(pos, end);
Copy link
Member

Choose a reason for hiding this comment

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

This first commit is titled "move read_const form header to parser.cpp", yet it also changes the implementation here.

constant_actual_type = ValType::f32;
break;
case Instr::f64_const:
// TODO: support this once floating points are implemented
result.kind = ConstantExpression::Kind::Constant;
result.value.constant = 0;
Copy link
Member

Choose a reason for hiding this comment

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

If this is removed for f32, should also be removed here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

@gumb0
Copy link
Collaborator Author

gumb0 commented Aug 3, 2020

Fixed the commits.

@gumb0 gumb0 requested a review from axic August 3, 2020 18:06
@@ -33,6 +33,18 @@ inline parser_result<uint8_t> parse_byte(const uint8_t* pos, const uint8_t* end)

return {*pos, pos + 1};
}
template <typename T>

inline parser_result<T> read_float_const(const uint8_t* pos, const uint8_t* end)
Copy link
Collaborator

Choose a reason for hiding this comment

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

read_constant()? read_constant_bytes()? But maybe keep the original name for now.

result.kind = ConstantExpression::Kind::Constant;
result.value.constant = 0;
pos = skip(4, pos, end);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The skip() function is probably unused now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed.

@@ -508,7 +508,8 @@ std::unique_ptr<Instance> instantiate(Module module,
datasec_offsets.reserve(module.datasec.size());
for (const auto& data : module.datasec)
{
const uint64_t offset = eval_constant_expression(data.offset, imported_globals, globals);
const uint64_t offset =
eval_constant_expression(data.offset, imported_globals, globals).i64;
Copy link
Member

Choose a reason for hiding this comment

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

Aren't these two validated to be uin32_t? And if so, the check below doesn't need to operate on 128-bit for overflow checks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's validated to be 32 bit, and this, together with validation of data.init vector length to be 32 bit, guarantees that offset + data.init.size() won't overflow 64 bit.

If we do here as<uint32_t>(), the check below will implicitly cast it back to 64-bit anyway, so I'm not sure it's worth it.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps adding a note that these are actually 32-bit could be useful?

Copy link
Collaborator Author

@gumb0 gumb0 Aug 7, 2020

Choose a reason for hiding this comment

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

Added comments here and for elem section.

@@ -521,7 +522,8 @@ std::unique_ptr<Instance> instantiate(Module module,
elementsec_offsets.reserve(module.elementsec.size());
for (const auto& element : module.elementsec)
{
const uint64_t offset = eval_constant_expression(element.offset, imported_globals, globals);
const uint64_t offset =
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@@ -34,6 +34,18 @@ inline parser_result<uint8_t> parse_byte(const uint8_t* pos, const uint8_t* end)
return {*pos, pos + 1};
}

template <typename T>
inline parser_result<T> parse_value(const uint8_t* pos, const uint8_t* end)
Copy link
Member

Choose a reason for hiding this comment

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

Since this needs to be rebased, you may want to update the commit message to read parse_value insead of read_const, but it is not important.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's "move and rename read_const" I would say

@gumb0 gumb0 merged commit 366aacf into master Aug 7, 2020
@gumb0 gumb0 deleted the float-globals branch August 7, 2020 10:12
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