-
Notifications
You must be signed in to change notification settings - Fork 698
implement extended const expr #4318
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
base: dev/extended_const
Are you sure you want to change the base?
implement extended const expr #4318
Conversation
09367e2
to
019a93f
Compare
#if WASM_ENABLE_EXTENDED_CONST_EXPR != 0 | ||
case INIT_EXPR_TYPE_I32_ADD: | ||
case INIT_EXPR_TYPE_I32_SUB: | ||
case INIT_EXPR_TYPE_I32_MUL: |
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 guess you can share the logic between i32 and 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.
i guess you can share the logic between i32 and i64.
Resolved. thanks
core/iwasm/interpreter/wasm.h
Outdated
#if WASM_ENABLE_EXTENDED_CONST_EXPR != 0 | ||
struct InitializerExpression *l_expr; | ||
struct InitializerExpression *r_expr; | ||
#endif |
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 there any cases where you need both of value (u) and exprs (l_expr/r_expr)?
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 there any cases where you need both of value (u) and exprs (l_expr/r_expr)?
iiuc, for unary init expr, only value (u)
is needed, for binary init expr, exprs (l_expr/r_expr)
are needed to store sub-exprs in order to compute the expr
value at runtime.
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.
can they be a union then?
eg.
union {
struct {
WASMValue value;
} unary;
struct {
struct InitializerExpression *l_expr;
struct InitializerExpression *r_expr;
} binary;
} u;
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.
can they be a union then?
eg.
union { struct { WASMValue value; } unary; struct { struct InitializerExpression *l_expr; struct InitializerExpression *r_expr; } binary; } u;
I think this is ok, and will save more memories after enable extended const expr, I will update this after finish the aot part, thanks the suggestion.
i guess it's safer to have a small limit for the stack height in the loader. |
63c429b
to
669c1b8
Compare
I didn't see a limit value specified in spec. and in this discussion, there is a suggestion to limit global initializer go with the function body limit of 7654321 bytes WebAssembly/extended-const#15 (comment), do you have any suggestions? |
669c1b8
to
2233ff4
Compare
e8e5ba2
to
36a8996
Compare
36a8996
to
0f475a5
Compare
build-scripts/config_common.cmake
Outdated
@@ -695,11 +709,11 @@ message ( | |||
" \"Tail call\" via WAMR_BUILD_TAIL_CALL: ${WAMR_BUILD_TAIL_CALL}\n" | |||
" \"Threads\" via WAMR_BUILD_SHARED_MEMORY: ${WAMR_BUILD_SHARED_MEMORY}\n" | |||
" \"Typed Function References\" via WAMR_BUILD_GC: ${WAMR_BUILD_GC}\n" | |||
" \"Extended Constant Expressions\" via WAMR_BUILD_EXTENDED_CONST_EXPR: ${WAMR_BUILD_EXTENDED_CONST_EXPR}\n" |
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.
keep alphabeta order
core/iwasm/aot/aot_loader.c
Outdated
data_list[i]->offset.init_expr_type = (uint8)init_expr_type; | ||
data_list[i]->offset.u.i64 = (int64)init_expr_value; | ||
bh_memcpy_s(&data_list[i]->offset, sizeof(InitializerExpression), | ||
&offset_expr, sizeof(InitializerExpression)); |
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.
better be something like: xxx->offset = offset_expr
. Compiler will check the type.
else() | ||
add_definitions(-DWASM_ENABLE_EXTENDED_CONST_EXPR=0) | ||
endif() | ||
|
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.
we might tend to enable it by default in wamrc. Then, wamrc can use a command line option to switch features.
value_type = VALUE_TYPE_I64; | ||
} | ||
|
||
if (!(pop_const_expr_stack(&const_expr_ctx, &r_flag, value_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.
Please provide a quick introduction to the binary format of a constant expression. It will be helpful.
core/iwasm/aot/aot_loader.c
Outdated
#endif | ||
#if WASM_ENABLE_EXTENDED_CONST_EXPR != 0 | ||
if (is_expr_binary_op(data_list[i]->offset.init_expr_type)) { | ||
destroy_sub_init_expr(&data_list[i]->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.
Maybe it's a good idea to refactor the destroy_init_expr
and merge the code logic of destroy_sub_init_expr
into it.
core/iwasm/aot/aot_runtime.c
Outdated
|| offset_flag == INIT_EXPR_TYPE_FUNCREF_CONST | ||
|| offset_flag == INIT_EXPR_TYPE_REFNULL_CONST | ||
|| (tbl_inst->is_table64 | ||
? (offset_flag == INIT_EXPR_TYPE_I64_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.
Maybe we should add a function/macro for this check since it appears several times, and use macro to control it, for it is only valid when extended const proposal is on.
uint8 offset_flag = data_seg->base_offset.init_expr_type; | ||
bh_assert(offset_flag == INIT_EXPR_TYPE_GET_GLOBAL | ||
|| (memory->is_memory64 | ||
? (offset_flag == INIT_EXPR_TYPE_I64_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.
Same as aot_runtime.c
Maybe we should add a function/macro for this check since it appears several times, and use macro to control it, for it is only valid when extendedd const proposal is on.
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 as
aot_runtime.c
Maybe we should add a function/macro for this check since it appears several times, and use macro to control it, for it is only valid when extendedd const proposal is on.
resolved.
|
||
#if WASM_ENABLE_EXTENDED_CONST_EXPR != 0 | ||
void | ||
destroy_init_expr_recursive(InitializerExpression *expr) |
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.
Maybe it's a good idea that we extract the destroy_init_expr
in wasm_loader.c and unify them 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.
Maybe it's a good idea that we extract the
destroy_init_expr
in wasm_loader.c and unify them here
resolved.
core/iwasm/interpreter/wasm.h
Outdated
|
||
#if WASM_ENABLE_EXTENDED_CONST_EXPR != 0 | ||
void | ||
destroy_init_expr_recursive(InitializerExpression *expr); |
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 those two APIs are only used in the loader, better to put them in wasm_loader_common.h
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 those two APIs are only used in the loader, better to put them in wasm_loader_common.h
resolved. thanks
45c71ed
to
1f3d64e
Compare
1f3d64e
to
759d61d
Compare
Uh oh!
There was an error while loading. Please reload this page.