-
Notifications
You must be signed in to change notification settings - Fork 38
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
Conversation
4214d5a
to
e5a248d
Compare
Codecov Report
@@ 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 |
b736b49
to
75d90f2
Compare
lib/fizzy/parser.hpp
Outdated
@@ -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) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
a966fb7
to
967799e
Compare
9a536a0
to
287f1fa
Compare
lib/fizzy/parser.cpp
Outdated
@@ -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) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
andparse_float_const<double>
works that is fine too.
Not without a cast on a calling side.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to parse_value
lib/fizzy/parser.cpp
Outdated
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); |
There was a problem hiding this comment.
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.
lib/fizzy/parser.cpp
Outdated
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
Fixed the commits. |
lib/fizzy/parser.hpp
Outdated
@@ -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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Depends on #445