Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions core/iwasm/aot/aot_intrinsic.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ static const aot_intrinsic g_intrinsic_mapping[] = {
{ "f64_promote_f32", "aot_intrinsic_f32_to_f64", AOT_INTRINSIC_FLAG_F32_TO_F64 },
{ "f32_cmp", "aot_intrinsic_f32_cmp", AOT_INTRINSIC_FLAG_F32_CMP },
{ "f64_cmp", "aot_intrinsic_f64_cmp", AOT_INTRINSIC_FLAG_F64_CMP },
{ "f32.const", NULL, AOT_INTRINSIC_FLAG_F32_CONST},
{ "f64.const", NULL, AOT_INTRINSIC_FLAG_F64_CONST},
};
/* clang-format on */

Expand Down Expand Up @@ -617,6 +619,13 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx)
add_f64_common_intrinsics(comp_ctx);
add_common_float_integer_convertion(comp_ctx);
}
else {
/*
* Use constant value table by default
*/
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CONST);
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_CONST);
}
}

#endif /* WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0 */
2 changes: 2 additions & 0 deletions core/iwasm/aot/aot_intrinsic.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ extern "C" {
#define AOT_INTRINSIC_FLAG_F32_TO_U64 AOT_INTRINSIC_FLAG(0, 23)
#define AOT_INTRINSIC_FLAG_F32_TO_F64 AOT_INTRINSIC_FLAG(0, 24)
#define AOT_INTRINSIC_FLAG_F32_CMP AOT_INTRINSIC_FLAG(0, 25)
#define AOT_INTRINSIC_FLAG_F32_CONST AOT_INTRINSIC_FLAG(0, 26)

#define AOT_INTRINSIC_FLAG_F64_FADD AOT_INTRINSIC_FLAG(1, 0)
#define AOT_INTRINSIC_FLAG_F64_FSUB AOT_INTRINSIC_FLAG(1, 1)
Expand Down Expand Up @@ -84,6 +85,7 @@ extern "C" {
#define AOT_INTRINSIC_FLAG_F64_TO_U64 AOT_INTRINSIC_FLAG(1, 23)
#define AOT_INTRINSIC_FLAG_F64_TO_F32 AOT_INTRINSIC_FLAG(1, 24)
#define AOT_INTRINSIC_FLAG_F64_CMP AOT_INTRINSIC_FLAG(1, 25)
#define AOT_INTRINSIC_FLAG_F64_CONST AOT_INTRINSIC_FLAG(1, 26)
/* clang-format on */

float32
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/aot/arch/aot_reloc_riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
if (error_buf != NULL)
snprintf(error_buf, error_buf_size,
"Load relocation section failed: "
"invalid relocation type %d.",
"invalid relocation type %" PRIu32 ".",
reloc_type);
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions core/iwasm/common/wasm_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
char *endptr = NULL;
bh_assert(argv[i] != NULL);
if (argv[i][0] == '\0') {
snprintf(buf, sizeof(buf), "invalid input argument %d", i);
snprintf(buf, sizeof(buf), "invalid input argument %" PRId32, i);
wasm_runtime_set_exception(module_inst, buf);
goto fail;
}
Expand Down Expand Up @@ -554,8 +554,8 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
break;
}
if (endptr && *endptr != '\0' && *endptr != '_') {
snprintf(buf, sizeof(buf), "invalid input argument %d: %s", i,
argv[i]);
snprintf(buf, sizeof(buf), "invalid input argument %" PRId32 ": %s",
i, argv[i]);
wasm_runtime_set_exception(module_inst, buf);
goto fail;
}
Expand All @@ -573,7 +573,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
switch (type->types[type->param_count + j]) {
case VALUE_TYPE_I32:
{
os_printf("0x%x:i32", argv1[k]);
os_printf("0x%" PRIx32 ":i32", argv1[k]);
k++;
break;
}
Expand Down
27 changes: 15 additions & 12 deletions core/iwasm/compilation/aot_emit_const.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "aot_emit_const.h"
#include "aot_intrinsic.h"

bool
aot_compile_op_i32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
Expand Down Expand Up @@ -36,12 +37,8 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMValueRef alloca, value;

if (!isnan(f32_const)) {
if (!comp_ctx->is_indirect_mode) {
value = F32_CONST(f32_const);
CHECK_LLVM_CONST(value);
PUSH_F32(value);
}
else {
if (comp_ctx->is_indirect_mode
&& aot_intrinsic_check_capability(comp_ctx, "f32.const")) {
WASMValue wasm_value;
memcpy(&wasm_value.f32, &f32_const, sizeof(float32));
value = aot_load_const_from_table(comp_ctx, func_ctx->native_symbol,
Expand All @@ -51,6 +48,11 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
PUSH_F32(value);
}
else {
value = F32_CONST(f32_const);
CHECK_LLVM_CONST(value);
PUSH_F32(value);
}
}
else {
int32 i32_const;
Expand Down Expand Up @@ -89,12 +91,8 @@ aot_compile_op_f64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMValueRef alloca, value;

if (!isnan(f64_const)) {
if (!comp_ctx->is_indirect_mode) {
value = F64_CONST(f64_const);
CHECK_LLVM_CONST(value);
PUSH_F64(value);
}
else {
if (comp_ctx->is_indirect_mode
&& aot_intrinsic_check_capability(comp_ctx, "f64.const")) {
WASMValue wasm_value;
memcpy(&wasm_value.f64, &f64_const, sizeof(float64));
value = aot_load_const_from_table(comp_ctx, func_ctx->native_symbol,
Expand All @@ -104,6 +102,11 @@ aot_compile_op_f64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
PUSH_F64(value);
}
else {
value = F64_CONST(f64_const);
CHECK_LLVM_CONST(value);
PUSH_F64(value);
}
}
else {
int64 i64_const;
Expand Down
4 changes: 2 additions & 2 deletions core/iwasm/compilation/aot_llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2490,12 +2490,12 @@ aot_load_const_from_table(AOTCompContext *comp_ctx, LLVMValueRef base,
switch (value_type) {
case VALUE_TYPE_F32:
/* Store the raw int bits of f32 const as a hex string */
snprintf(buf, sizeof(buf), "f32#%08X", value->i32);
snprintf(buf, sizeof(buf), "f32#%08" PRIX32, value->i32);
const_ptr_type = F32_PTR_TYPE;
break;
case VALUE_TYPE_F64:
/* Store the raw int bits of f64 const as a hex string */
snprintf(buf, sizeof(buf), "f64#%016" PRIx64, value->i64);
snprintf(buf, sizeof(buf), "f64#%016" PRIX64, value->i64);
const_ptr_type = F64_PTR_TYPE;
break;
default:
Expand Down
5 changes: 3 additions & 2 deletions core/iwasm/interpreter/wasm_interp_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -3733,8 +3733,9 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
if (argc < function->param_cell_num) {
char buf[128];
snprintf(buf, sizeof(buf),
"invalid argument count %u, must be no smaller than %u", argc,
function->param_cell_num);
"invalid argument count %" PRIu32
", must be no smaller than %" PRIu32,
argc, (uint32)function->param_cell_num);
wasm_set_exception(module_inst, buf);
return;
}
Expand Down
8 changes: 4 additions & 4 deletions core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ exit_wrapper(wasm_exec_env_t exec_env, int32 status)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
char buf[32];
snprintf(buf, sizeof(buf), "env.exit(%i)", status);
snprintf(buf, sizeof(buf), "env.exit(%" PRId32 ")", status);
wasm_runtime_set_exception(module_inst, buf);
}

Expand Down Expand Up @@ -1012,7 +1012,7 @@ abort_wrapper(wasm_exec_env_t exec_env, int32 code)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
char buf[32];
snprintf(buf, sizeof(buf), "env.abort(%i)", code);
snprintf(buf, sizeof(buf), "env.abort(%" PRId32 ")", code);
wasm_runtime_set_exception(module_inst, buf);
}

Expand All @@ -1021,7 +1021,7 @@ abortStackOverflow_wrapper(wasm_exec_env_t exec_env, int32 code)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
char buf[32];
snprintf(buf, sizeof(buf), "env.abortStackOverflow(%i)", code);
snprintf(buf, sizeof(buf), "env.abortStackOverflow(%" PRId32 ")", code);
wasm_runtime_set_exception(module_inst, buf);
}

Expand All @@ -1030,7 +1030,7 @@ nullFunc_X_wrapper(wasm_exec_env_t exec_env, int32 code)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
char buf[32];
snprintf(buf, sizeof(buf), "env.nullFunc_X(%i)", code);
snprintf(buf, sizeof(buf), "env.nullFunc_X(%" PRId32 ")", code);
wasm_runtime_set_exception(module_inst, buf);
}

Expand Down
10 changes: 6 additions & 4 deletions core/shared/mem-alloc/ems/ems_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,8 @@ void
gc_dump_heap_stats(gc_heap_t *heap)
{
os_printf("heap: %p, heap start: %p\n", heap, heap->base_addr);
os_printf("total free: %u, current: %u, highmark: %u\n",
os_printf("total free: %" PRIu32 ", current: %" PRIu32
", highmark: %" PRIu32 "\n",
heap->total_free_size, heap->current_size, heap->highmark_size);
os_printf("g_total_malloc=%lu, g_total_free=%lu, occupied=%lu\n",
g_total_malloc, g_total_free, g_total_malloc - g_total_free);
Expand Down Expand Up @@ -765,9 +766,10 @@ gci_dump(gc_heap_t *heap)
return;
}

os_printf("#%d %08x %x %x %d %c %d\n", i,
(int32)((char *)cur - (char *)heap->base_addr), ut, p, mark,
inuse, (int32)hmu_obj_size(size));
os_printf("#%d %08" PRIx32 " %" PRIx32 " %d %d"
" %c %" PRId32 "\n",
i, (int32)((char *)cur - (char *)heap->base_addr), (int32)ut,
p, mark, inuse, (int32)hmu_obj_size(size));
#if BH_ENABLE_GC_VERIFY != 0
if (inuse == 'V') {
gc_object_prefix_t *prefix = (gc_object_prefix_t *)(cur + 1);
Expand Down
10 changes: 5 additions & 5 deletions core/shared/mem-alloc/ems/ems_kfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ gc_init_with_pool(char *buf, gc_size_t buf_size)
gc_size_t heap_max_size;

if (buf_size < APP_HEAP_SIZE_MIN) {
os_printf("[GC_ERROR]heap init buf size (%u) < %u\n", buf_size,
APP_HEAP_SIZE_MIN);
os_printf("[GC_ERROR]heap init buf size (%" PRIu32 ") < %" PRIu32 "\n",
buf_size, (uint32)APP_HEAP_SIZE_MIN);
return NULL;
}

Expand Down Expand Up @@ -93,7 +93,7 @@ gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
}

if (struct_buf_size < sizeof(gc_handle_t)) {
os_printf("[GC_ERROR]heap init struct buf size (%u) < %zu\n",
os_printf("[GC_ERROR]heap init struct buf size (%" PRIu32 ") < %zu\n",
struct_buf_size, sizeof(gc_handle_t));
return NULL;
}
Expand All @@ -104,8 +104,8 @@ gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
}

if (pool_buf_size < APP_HEAP_SIZE_MIN) {
os_printf("[GC_ERROR]heap init buf size (%u) < %u\n", pool_buf_size,
APP_HEAP_SIZE_MIN);
os_printf("[GC_ERROR]heap init buf size (%" PRIu32 ") < %u\n",
pool_buf_size, APP_HEAP_SIZE_MIN);
return NULL;
}

Expand Down
72 changes: 72 additions & 0 deletions core/shared/platform/esp-idf/espidf_malloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#include "platform_api_vmcore.h"
#include "platform_api_extension.h"

void *
os_malloc(unsigned size)
{
void *buf_origin;
void *buf_fixed;
uintptr_t *addr_field;

buf_origin = malloc(size + 8 + sizeof(uintptr_t));
buf_fixed = buf_origin + sizeof(void *);
if ((uintptr_t)buf_fixed & (uintptr_t)0x7) {
buf_fixed = (void *)((uintptr_t)(buf_fixed + 8) & (~(uintptr_t)7));
}

addr_field = buf_fixed - sizeof(uintptr_t);
*addr_field = (uintptr_t)buf_origin;

return buf_fixed;
}

void *
os_realloc(void *ptr, unsigned size)
{
void *mem_origin;
void *mem_new;
void *mem_new_fixed;
uintptr_t *addr_field;

if (!ptr) {
return NULL;
}

addr_field = ptr - sizeof(uintptr_t);
mem_origin = (void *)(*addr_field);
mem_new = realloc(mem_origin, size + 8 + sizeof(uintptr_t));

if (mem_origin != mem_new) {
mem_new_fixed = mem_new + sizeof(uintptr_t);
if ((uint32)mem_new_fixed & 0x7) {
mem_new_fixed =
(void *)((uintptr_t)(mem_new + 8) & (~(uintptr_t)7));
}

addr_field = mem_new_fixed - sizeof(uintptr_t);
*addr_field = (uintptr_t)mem_new;

return mem_new_fixed;
}

return ptr;
}

void
os_free(void *ptr)
{
void *mem_origin;
uintptr *addr_field;

if (ptr) {
addr_field = ptr - sizeof(uintptr_t);
mem_origin = (void *)(*addr_field);

free(mem_origin);
}
}
29 changes: 29 additions & 0 deletions core/shared/platform/esp-idf/espidf_memmap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#include "platform_api_vmcore.h"
#include "platform_api_extension.h"

void *
os_mmap(void *hint, size_t size, int prot, int flags)
{
return os_malloc((int)size);
}

void
os_munmap(void *addr, size_t size)
{
return os_free(addr);
}

int
os_mprotect(void *addr, size_t size, int prot)
{
return 0;
}

void
os_dcache_flush()
{}
Loading