Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/compilation_on_android_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ env:
GC_TEST_OPTIONS: "-s spec -G -b -P"
MEMORY64_TEST_OPTIONS: "-s spec -W -b -P"
MULTI_MEMORY_TEST_OPTIONS: "-s spec -E -b -P"
EXTENDED_CONST_EXPR_TEST_OPTIONS: "-s spec -N -b -P"

permissions:
contents: read
Expand Down Expand Up @@ -164,6 +165,7 @@ jobs:
"-DWAMR_BUILD_MEMORY64=1",
"-DWAMR_BUILD_MULTI_MEMORY=1",
"-DWAMR_BUILD_SHARED=1",
"-DWAMR_BUILD_EXTENDED_CONST_EXPR=1",
]
os: [ubuntu-22.04]
platform: [android, linux]
Expand Down Expand Up @@ -609,6 +611,7 @@ jobs:
$GC_TEST_OPTIONS,
$MEMORY64_TEST_OPTIONS,
$MULTI_MEMORY_TEST_OPTIONS,
$EXTENDED_CONST_EXPR_TEST_OPTIONS,
]
include:
- os: ubuntu-22.04
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/compilation_on_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ jobs:
"-DWAMR_BUILD_SIMD=1",
"-DWAMR_BUILD_TAIL_CALL=1",
"-DWAMR_DISABLE_HW_BOUND_CHECK=1",
"-DWAMR_BUILD_EXTENDED_CONST_EXPR=1",
]
os: [macos-13]
platform: [darwin]
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/compilation_on_sgx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ jobs:
"-DWAMR_BUILD_MULTI_MODULE=1",
"-DWAMR_BUILD_PERF_PROFILING=1",
"-DWAMR_BUILD_REF_TYPES=1",
"-DWAMR_BUILD_EXTENDED_CONST_EXPR=1",
# doesn't support
"-DWAMR_BUILD_SIMD=0",
"-DWAMR_BUILD_TAIL_CALL=1",
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/nightly_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ env:
DEFAULT_TEST_OPTIONS: "-s spec -P"
MULTI_MODULES_TEST_OPTIONS: "-s spec -M -P"
SIMD_TEST_OPTIONS: "-s spec -S -P"
EXTENDED_CONST_EXPR_TEST_OPTIONS: "-s spec -N -P"
THREADS_TEST_OPTIONS: "-s spec -p -P"
X86_32_TARGET_TEST_OPTIONS: "-m x86_32 -P"
WASI_TEST_OPTIONS: "-s wasi_certification -w"
Expand Down Expand Up @@ -129,6 +130,7 @@ jobs:
"-DWAMR_BUILD_MEMORY64=1",
"-DWAMR_BUILD_MULTI_MEMORY=1",
"-DWAMR_BUILD_SHARED=1",
"-DWAMR_BUILD_EXTENDED_CONST_EXPR=1",
]
os: [ubuntu-22.04]
platform: [android, linux]
Expand Down Expand Up @@ -589,6 +591,7 @@ jobs:
$DEFAULT_TEST_OPTIONS,
$MULTI_MODULES_TEST_OPTIONS,
$SIMD_TEST_OPTIONS,
$EXTENDED_CONST_EXPR_TEST_OPTIONS,
$THREADS_TEST_OPTIONS,
$WASI_TEST_OPTIONS,
]
Expand Down
14 changes: 12 additions & 2 deletions build-scripts/config_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ if (NOT DEFINED WAMR_BUILD_TAIL_CALL)
set (WAMR_BUILD_TAIL_CALL 0)
endif ()

if (NOT DEFINED WAMR_BUILD_EXTENDED_CONST_EXPR)
set (WAMR_BUILD_EXTENDED_CONST_EXPR 0)
endif ()

########################################
# Compilation options to marco
########################################
Expand Down Expand Up @@ -675,7 +679,13 @@ if (WAMR_BUILD_INSTRUCTION_METERING EQUAL 1)
message (" Instruction metering enabled")
add_definitions (-DWASM_ENABLE_INSTRUCTION_METERING=1)
endif ()

if (WAMR_BUILD_EXTENDED_CONST_EXPR EQUAL 1)
message (" Extended constant expression enabled")
add_definitions(-DWASM_ENABLE_EXTENDED_CONST_EXPR=1)
else()
message (" Extended constant expression disabled")
add_definitions(-DWASM_ENABLE_EXTENDED_CONST_EXPR=0)
endif ()
########################################
# Show Phase4 Wasm proposals status.
########################################
Expand All @@ -699,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"
Comment thread
lum1n0us marked this conversation as resolved.
Outdated
" Unsupported (>= Phase4):\n"
" \"Branch Hinting\"\n"
" \"Custom Annotation Syntax in the Text Format\"\n"
" \"Exception handling\"\n"
" \"Extended Constant Expressions\"\n"
" \"Import/Export of Mutable Globals\"\n"
" \"JS String Builtins\"\n"
" \"Relaxed SIMD\"\n"
Expand Down
4 changes: 4 additions & 0 deletions core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,8 @@ unless used elsewhere */
#define WASM_ENABLE_INSTRUCTION_METERING 0
#endif

#ifndef WASM_ENABLE_EXTENDED_CONST_EXPR
#define WASM_ENABLE_EXTENDED_CONST_EXPR 0
#endif

#endif /* end of _CONFIG_H_ */
100 changes: 76 additions & 24 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,11 @@ destroy_mem_init_data_list(AOTModule *module, AOTMemInitData **data_list,
/* If the module owns the binary data, free the bytes buffer */
if (module->is_binary_freeable && data_list[i]->bytes)
wasm_runtime_free(data_list[i]->bytes);
#if WASM_ENABLE_EXTENDED_CONST_EXPR != 0
Comment thread
lum1n0us marked this conversation as resolved.
if (is_expr_binary_op(data_list[i]->offset.init_expr_type)) {
destroy_sub_init_expr(&data_list[i]->offset);
}
#endif
/* Free the data segment structure itself */
wasm_runtime_free(data_list[i]);
}
Expand Down Expand Up @@ -1043,11 +1048,11 @@ load_mem_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
uint32 byte_count;
uint32 is_passive;
uint32 memory_index;
InitializerExpression init_value;
InitializerExpression offset_expr;

read_uint32(buf, buf_end, is_passive);
read_uint32(buf, buf_end, memory_index);
if (!load_init_expr(&buf, buf_end, module, &init_value, error_buf,
if (!load_init_expr(&buf, buf_end, module, &offset_expr, error_buf,
error_buf_size)) {
return false;
}
Expand All @@ -1062,8 +1067,8 @@ load_mem_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
data_list[i]->is_passive = (bool)is_passive;
data_list[i]->memory_index = memory_index;
#endif
data_list[i]->offset.init_expr_type = init_value.init_expr_type;
data_list[i]->offset.u = init_value.u;
bh_memcpy_s(&data_list[i]->offset, sizeof(InitializerExpression),
&offset_expr, sizeof(InitializerExpression));
data_list[i]->byte_count = byte_count;
data_list[i]->bytes = NULL;
/* If the module owns the binary data, clone the bytes buffer */
Expand Down Expand Up @@ -1155,7 +1160,7 @@ destroy_init_expr(InitializerExpression *expr)
if (expr->init_expr_type == INIT_EXPR_TYPE_STRUCT_NEW
|| expr->init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW
|| expr->init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW_FIXED) {
wasm_runtime_free(expr->u.data);
wasm_runtime_free(expr->u.unary.v.data);
}
}
#endif /* end of WASM_ENABLE_GC != 0 */
Expand Down Expand Up @@ -1183,6 +1188,11 @@ destroy_table_init_data_list(AOTTableInitData **data_list, uint32 count)
for (j = 0; j < data_list[i]->value_count; j++) {
destroy_init_expr(&data_list[i]->init_values[j]);
}
#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);
Comment thread
lum1n0us marked this conversation as resolved.
Outdated
}
#endif
wasm_runtime_free(data_list[i]);
}
Expand All @@ -1208,34 +1218,34 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
break;
case INIT_EXPR_TYPE_I32_CONST:
case INIT_EXPR_TYPE_F32_CONST:
read_uint32(buf, buf_end, expr->u.i32);
read_uint32(buf, buf_end, expr->u.unary.v.i32);
break;
case INIT_EXPR_TYPE_I64_CONST:
case INIT_EXPR_TYPE_F64_CONST:
read_uint64(buf, buf_end, expr->u.i64);
read_uint64(buf, buf_end, expr->u.unary.v.i64);
break;
case INIT_EXPR_TYPE_V128_CONST:
i64x2 = (uint64 *)expr->u.v128.i64x2;
i64x2 = (uint64 *)expr->u.unary.v.v128.i64x2;
CHECK_BUF(buf, buf_end, sizeof(uint64) * 2);
wasm_runtime_read_v128(buf, &i64x2[0], &i64x2[1]);
buf += sizeof(uint64) * 2;
break;
case INIT_EXPR_TYPE_GET_GLOBAL:
read_uint32(buf, buf_end, expr->u.global_index);
read_uint32(buf, buf_end, expr->u.unary.v.global_index);
break;
/* INIT_EXPR_TYPE_FUNCREF_CONST can be used when
both reference types and GC are disabled */
case INIT_EXPR_TYPE_FUNCREF_CONST:
read_uint32(buf, buf_end, expr->u.ref_index);
read_uint32(buf, buf_end, expr->u.unary.v.ref_index);
break;
#if WASM_ENABLE_GC != 0 || WASM_ENABLE_REF_TYPES != 0
case INIT_EXPR_TYPE_REFNULL_CONST:
read_uint32(buf, buf_end, expr->u.ref_index);
read_uint32(buf, buf_end, expr->u.unary.v.ref_index);
break;
#endif /* end of WASM_ENABLE_GC != 0 || WASM_ENABLE_REF_TYPES != 0 */
#if WASM_ENABLE_GC != 0
case INIT_EXPR_TYPE_I31_NEW:
read_uint32(buf, buf_end, expr->u.i32);
read_uint32(buf, buf_end, expr->u.unary.v.i32);
break;
case INIT_EXPR_TYPE_STRUCT_NEW:
{
Expand All @@ -1256,7 +1266,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
free_if_fail = true;
init_values->count = field_count;
init_values->type_idx = type_idx;
expr->u.data = init_values;
expr->u.unary.v.data = init_values;

if (type_idx >= module->type_count) {
set_error_buf(error_buf, error_buf_size,
Expand Down Expand Up @@ -1294,7 +1304,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
break;
}
case INIT_EXPR_TYPE_STRUCT_NEW_DEFAULT:
read_uint32(buf, buf_end, expr->u.type_index);
read_uint32(buf, buf_end, expr->u.unary.v.type_index);
break;
case INIT_EXPR_TYPE_ARRAY_NEW:
case INIT_EXPR_TYPE_ARRAY_NEW_DEFAULT:
Expand All @@ -1310,8 +1320,8 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
read_uint32(buf, buf_end, length);

if (init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW_DEFAULT) {
expr->u.array_new_default.type_index = type_idx;
expr->u.array_new_default.length = length;
expr->u.unary.v.array_new_default.type_index = type_idx;
expr->u.unary.v.array_new_default.length = length;
}
else {
uint32 i, elem_size, elem_data_count;
Expand All @@ -1322,7 +1332,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
return false;
}
free_if_fail = true;
expr->u.data = init_values;
expr->u.unary.v.data = init_values;

init_values->type_idx = type_idx;
init_values->length = length;
Expand Down Expand Up @@ -1350,6 +1360,34 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
break;
}
#endif /* end of WASM_ENABLE_GC != 0 */
#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:
case INIT_EXPR_TYPE_I64_ADD:
case INIT_EXPR_TYPE_I64_SUB:
case INIT_EXPR_TYPE_I64_MUL:
{
expr->u.binary.l_expr = expr->u.binary.r_expr = NULL;
if (!(expr->u.binary.l_expr =
loader_malloc(sizeof(InitializerExpression), error_buf,
error_buf_size))) {
goto fail;
}
if (!load_init_expr(&buf, buf_end, module, expr->u.binary.l_expr,
error_buf, error_buf_size))
goto fail;
if (!(expr->u.binary.r_expr =
loader_malloc(sizeof(InitializerExpression), error_buf,
error_buf_size))) {
goto fail;
}
if (!load_init_expr(&buf, buf_end, module, expr->u.binary.r_expr,
error_buf, error_buf_size))
goto fail;
break;
}
#endif /* end of WASM_ENABLE_EXTENDED_CONST_EXPR != 0 */
default:
set_error_buf(error_buf, error_buf_size, "invalid init expr type.");
return false;
Expand All @@ -1362,10 +1400,13 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
fail:
#if WASM_ENABLE_GC != 0
if (free_if_fail) {
wasm_runtime_free(expr->u.data);
wasm_runtime_free(expr->u.unary.v.data);
}
#else
(void)free_if_fail;
#endif
#if WASM_ENABLE_EXTENDED_CONST_EXPR != 0
destroy_sub_init_expr(expr);
#endif
return false;
}
Expand Down Expand Up @@ -1528,14 +1569,16 @@ load_table_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
/* Create each table data segment */
for (i = 0; i < module->table_init_data_count; i++) {
uint32 mode, elem_type;
uint32 table_index, init_expr_type, value_count;
uint64 init_expr_value, size1;
uint32 table_index, value_count;
uint64 size1;
InitializerExpression offset_expr;

read_uint32(buf, buf_end, mode);
read_uint32(buf, buf_end, elem_type);
read_uint32(buf, buf_end, table_index);
read_uint32(buf, buf_end, init_expr_type);
read_uint64(buf, buf_end, init_expr_value);
if (!load_init_expr(&buf, buf_end, module, &offset_expr, error_buf,
error_buf_size))
return false;
#if WASM_ENABLE_GC != 0
if (wasm_is_type_multi_byte_type(elem_type)) {
uint16 ref_type, nullable;
Expand Down Expand Up @@ -1581,8 +1624,8 @@ load_table_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
}
}
#endif
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));
Comment thread
lum1n0us marked this conversation as resolved.
Outdated
data_list[i]->value_count = value_count;
for (j = 0; j < data_list[i]->value_count; j++) {
if (!load_init_expr(&buf, buf_end, module,
Expand Down Expand Up @@ -4478,6 +4521,15 @@ aot_unload(AOTModule *module)
for (i = 0; i < module->global_count; i++) {
destroy_init_expr(&module->globals[i].init_expr);
}
#endif
#if WASM_ENABLE_EXTENDED_CONST_EXPR != 0
uint32 j;
for (j = 0; j < module->global_count; j++) {
if (is_expr_binary_op(
module->globals[j].init_expr.init_expr_type)) {
destroy_sub_init_expr(&module->globals[j].init_expr);
}
}
#endif
destroy_globals(module->globals);
}
Expand Down
Loading
Loading