From 29175eca35383349f3dbc46629ec014fb8409865 Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Fri, 7 Mar 2025 17:23:13 +0800 Subject: [PATCH 01/13] Remove indirect-load for constants on Xtensa Target to improve performance --- core/iwasm/compilation/aot_emit_const.c | 18 ++++++++++++++++-- core/iwasm/compilation/aot_emit_conversion.c | 16 ++++++++++++++++ core/iwasm/compilation/aot_emit_memory.c | 5 ++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/core/iwasm/compilation/aot_emit_const.c b/core/iwasm/compilation/aot_emit_const.c index 64fa3ded1a..6e1671f11b 100644 --- a/core/iwasm/compilation/aot_emit_const.c +++ b/core/iwasm/compilation/aot_emit_const.c @@ -12,6 +12,7 @@ aot_compile_op_i32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMValueRef value; +#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability(comp_ctx, "i32.const")) { WASMValue wasm_value; @@ -22,7 +23,9 @@ aot_compile_op_i32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } } - else { + else +#endif + { value = I32_CONST((uint32)i32_const); CHECK_LLVM_CONST(value); } @@ -40,6 +43,7 @@ aot_compile_op_i64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMValueRef value; +#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability(comp_ctx, "i64.const")) { WASMValue wasm_value; @@ -50,7 +54,9 @@ aot_compile_op_i64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } } - else { + else +#endif + { value = I64_CONST((uint64)i64_const); CHECK_LLVM_CONST(value); } @@ -68,6 +74,7 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMValueRef alloca, value; +#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability(comp_ctx, "f32.const")) { WASMValue wasm_value; @@ -80,6 +87,9 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, PUSH_F32(value); } else if (!isnan(f32_const)) { +#else + if (!isnan(f32_const)) { +#endif value = F32_CONST(f32_const); CHECK_LLVM_CONST(value); PUSH_F32(value); @@ -121,6 +131,7 @@ aot_compile_op_f64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMValueRef alloca, value; +#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability(comp_ctx, "f64.const")) { WASMValue wasm_value; @@ -133,6 +144,9 @@ aot_compile_op_f64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, PUSH_F64(value); } else if (!isnan(f64_const)) { +#else + if (!isnan(f64_const)) { +#endif value = F64_CONST(f64_const); CHECK_LLVM_CONST(value); PUSH_F64(value); diff --git a/core/iwasm/compilation/aot_emit_conversion.c b/core/iwasm/compilation/aot_emit_conversion.c index c3dfa6bf11..d694eefcab 100644 --- a/core/iwasm/compilation/aot_emit_conversion.c +++ b/core/iwasm/compilation/aot_emit_conversion.c @@ -347,7 +347,9 @@ aot_compile_op_i32_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F32(value); +#if !defined(BUILD_TARGET_XTENSA) if (!comp_ctx->is_indirect_mode) { +#endif if (sign) { min_value = F32_CONST(-2147483904.0f); max_value = F32_CONST(2147483648.0f); @@ -356,6 +358,7 @@ aot_compile_op_i32_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, min_value = F32_CONST(-1.0f); max_value = F32_CONST(4294967296.0f); } +#if !defined(BUILD_TARGET_XTENSA) } else { WASMValue wasm_value; @@ -376,6 +379,7 @@ aot_compile_op_i32_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32); } } +#endif CHECK_LLVM_CONST(min_value); CHECK_LLVM_CONST(max_value); @@ -400,7 +404,9 @@ aot_compile_op_i32_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F64(value); +#if !defined(BUILD_TARGET_XTENSA) if (!comp_ctx->is_indirect_mode) { +#endif if (sign) { min_value = F64_CONST(-2147483649.0); max_value = F64_CONST(2147483648.0); @@ -409,6 +415,7 @@ aot_compile_op_i32_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, min_value = F64_CONST(-1.0); max_value = F64_CONST(4294967296.0); } +#if !defined(BUILD_TARGET_XTENSA) } else { WASMValue wasm_value; @@ -429,6 +436,7 @@ aot_compile_op_i32_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64); } } +#endif CHECK_LLVM_CONST(min_value); CHECK_LLVM_CONST(max_value); @@ -554,7 +562,9 @@ aot_compile_op_i64_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F32(value); +#if !defined(BUILD_TARGET_XTENSA) if (!comp_ctx->is_indirect_mode) { +#endif if (sign) { min_value = F32_CONST(-9223373136366403584.0f); max_value = F32_CONST(9223372036854775808.0f); @@ -563,6 +573,7 @@ aot_compile_op_i64_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, min_value = F32_CONST(-1.0f); max_value = F32_CONST(18446744073709551616.0f); } +#if !defined(BUILD_TARGET_XTENSA) } else { WASMValue wasm_value; @@ -583,6 +594,7 @@ aot_compile_op_i64_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32); } } +#endif CHECK_LLVM_CONST(min_value); CHECK_LLVM_CONST(max_value); @@ -607,7 +619,9 @@ aot_compile_op_i64_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F64(value); +#if !defined(BUILD_TARGET_XTENSA) if (!comp_ctx->is_indirect_mode) { +#endif if (sign) { min_value = F64_CONST(-9223372036854777856.0); max_value = F64_CONST(9223372036854775808.0); @@ -616,6 +630,7 @@ aot_compile_op_i64_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, min_value = F64_CONST(-1.0); max_value = F64_CONST(18446744073709551616.0); } +#if !defined(BUILD_TARGET_XTENSA) } else { WASMValue wasm_value; @@ -636,6 +651,7 @@ aot_compile_op_i64_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64); } } +#endif CHECK_LLVM_CONST(min_value); CHECK_LLVM_CONST(max_value); diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index e685fccd92..0b4961225e 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -139,6 +139,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, is_target_64bit = (comp_ctx->pointer_size == sizeof(uint64)) ? true : false; +#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability( comp_ctx, MEMORY64_COND_VALUE("i64.const", "i32.const"))) { @@ -159,7 +160,9 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return NULL; } } - else { + else +#endif + { CHECK_LLVM_CONST(offset_const); } From bb089c232e3d9ef09cf824cedcc51ed7bb63429f Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Tue, 25 Mar 2025 10:31:04 +0800 Subject: [PATCH 02/13] Use clang-format-12 to format source file --- core/iwasm/compilation/aot_emit_const.c | 14 +++++------ core/iwasm/compilation/aot_emit_conversion.c | 26 ++++++++++---------- core/iwasm/compilation/aot_emit_memory.c | 6 ++--- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/core/iwasm/compilation/aot_emit_const.c b/core/iwasm/compilation/aot_emit_const.c index 6e1671f11b..b3b6b4f172 100644 --- a/core/iwasm/compilation/aot_emit_const.c +++ b/core/iwasm/compilation/aot_emit_const.c @@ -23,7 +23,7 @@ aot_compile_op_i32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } } - else + else #endif { value = I32_CONST((uint32)i32_const); @@ -54,8 +54,8 @@ aot_compile_op_i64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } } - else -#endif + else +#endif { value = I64_CONST((uint64)i64_const); CHECK_LLVM_CONST(value); @@ -74,7 +74,7 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMValueRef alloca, value; -#if !defined(BUILD_TARGET_XTENSA) +#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability(comp_ctx, "f32.const")) { WASMValue wasm_value; @@ -89,7 +89,7 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, else if (!isnan(f32_const)) { #else if (!isnan(f32_const)) { -#endif +#endif value = F32_CONST(f32_const); CHECK_LLVM_CONST(value); PUSH_F32(value); @@ -131,7 +131,7 @@ aot_compile_op_f64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMValueRef alloca, value; -#if !defined(BUILD_TARGET_XTENSA) +#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability(comp_ctx, "f64.const")) { WASMValue wasm_value; @@ -146,7 +146,7 @@ aot_compile_op_f64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, else if (!isnan(f64_const)) { #else if (!isnan(f64_const)) { -#endif +#endif value = F64_CONST(f64_const); CHECK_LLVM_CONST(value); PUSH_F64(value); diff --git a/core/iwasm/compilation/aot_emit_conversion.c b/core/iwasm/compilation/aot_emit_conversion.c index d694eefcab..d4372ad743 100644 --- a/core/iwasm/compilation/aot_emit_conversion.c +++ b/core/iwasm/compilation/aot_emit_conversion.c @@ -347,7 +347,7 @@ aot_compile_op_i32_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F32(value); -#if !defined(BUILD_TARGET_XTENSA) +#if !defined(BUILD_TARGET_XTENSA) if (!comp_ctx->is_indirect_mode) { #endif if (sign) { @@ -404,9 +404,9 @@ aot_compile_op_i32_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F64(value); -#if !defined(BUILD_TARGET_XTENSA) +#if !defined(BUILD_TARGET_XTENSA) if (!comp_ctx->is_indirect_mode) { -#endif +#endif if (sign) { min_value = F64_CONST(-2147483649.0); max_value = F64_CONST(2147483648.0); @@ -415,7 +415,7 @@ aot_compile_op_i32_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, min_value = F64_CONST(-1.0); max_value = F64_CONST(4294967296.0); } -#if !defined(BUILD_TARGET_XTENSA) +#if !defined(BUILD_TARGET_XTENSA) } else { WASMValue wasm_value; @@ -436,7 +436,7 @@ aot_compile_op_i32_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64); } } -#endif +#endif CHECK_LLVM_CONST(min_value); CHECK_LLVM_CONST(max_value); @@ -562,9 +562,9 @@ aot_compile_op_i64_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F32(value); -#if !defined(BUILD_TARGET_XTENSA) +#if !defined(BUILD_TARGET_XTENSA) if (!comp_ctx->is_indirect_mode) { -#endif +#endif if (sign) { min_value = F32_CONST(-9223373136366403584.0f); max_value = F32_CONST(9223372036854775808.0f); @@ -573,7 +573,7 @@ aot_compile_op_i64_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, min_value = F32_CONST(-1.0f); max_value = F32_CONST(18446744073709551616.0f); } -#if !defined(BUILD_TARGET_XTENSA) +#if !defined(BUILD_TARGET_XTENSA) } else { WASMValue wasm_value; @@ -594,7 +594,7 @@ aot_compile_op_i64_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32); } } -#endif +#endif CHECK_LLVM_CONST(min_value); CHECK_LLVM_CONST(max_value); @@ -619,9 +619,9 @@ aot_compile_op_i64_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F64(value); -#if !defined(BUILD_TARGET_XTENSA) +#if !defined(BUILD_TARGET_XTENSA) if (!comp_ctx->is_indirect_mode) { -#endif +#endif if (sign) { min_value = F64_CONST(-9223372036854777856.0); max_value = F64_CONST(9223372036854775808.0); @@ -630,7 +630,7 @@ aot_compile_op_i64_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, min_value = F64_CONST(-1.0); max_value = F64_CONST(18446744073709551616.0); } -#if !defined(BUILD_TARGET_XTENSA) +#if !defined(BUILD_TARGET_XTENSA) } else { WASMValue wasm_value; @@ -651,7 +651,7 @@ aot_compile_op_i64_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64); } } -#endif +#endif CHECK_LLVM_CONST(min_value); CHECK_LLVM_CONST(max_value); diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index 0b4961225e..b9d467dd59 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -139,7 +139,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, is_target_64bit = (comp_ctx->pointer_size == sizeof(uint64)) ? true : false; -#if !defined(BUILD_TARGET_XTENSA) +#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability( comp_ctx, MEMORY64_COND_VALUE("i64.const", "i32.const"))) { @@ -160,8 +160,8 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return NULL; } } - else -#endif + else +#endif { CHECK_LLVM_CONST(offset_const); } From ac5b33b31d54a1209b0dee5f5099b247c670fcae Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Tue, 25 Mar 2025 14:24:58 +0800 Subject: [PATCH 03/13] Remove const intrinsics flags for xtensa instead of adding too much #ifdef --- core/iwasm/aot/aot_intrinsic.c | 4 ---- core/iwasm/compilation/aot_emit_const.c | 12 ------------ core/iwasm/compilation/aot_emit_memory.c | 2 -- 3 files changed, 18 deletions(-) diff --git a/core/iwasm/aot/aot_intrinsic.c b/core/iwasm/aot/aot_intrinsic.c index 245c7a6515..25784a8d14 100644 --- a/core/iwasm/aot/aot_intrinsic.c +++ b/core/iwasm/aot/aot_intrinsic.c @@ -877,10 +877,6 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx) add_f64_common_intrinsics(comp_ctx); add_i64_common_intrinsics(comp_ctx); add_common_float_integer_conversion(comp_ctx); - add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CONST); - add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_CONST); - add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I32_CONST); - add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I64_CONST); } else { /* diff --git a/core/iwasm/compilation/aot_emit_const.c b/core/iwasm/compilation/aot_emit_const.c index b3b6b4f172..9d19547324 100644 --- a/core/iwasm/compilation/aot_emit_const.c +++ b/core/iwasm/compilation/aot_emit_const.c @@ -12,7 +12,6 @@ aot_compile_op_i32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMValueRef value; -#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability(comp_ctx, "i32.const")) { WASMValue wasm_value; @@ -24,7 +23,6 @@ aot_compile_op_i32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } } else -#endif { value = I32_CONST((uint32)i32_const); CHECK_LLVM_CONST(value); @@ -43,7 +41,6 @@ aot_compile_op_i64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMValueRef value; -#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability(comp_ctx, "i64.const")) { WASMValue wasm_value; @@ -55,7 +52,6 @@ aot_compile_op_i64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } } else -#endif { value = I64_CONST((uint64)i64_const); CHECK_LLVM_CONST(value); @@ -74,7 +70,6 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMValueRef alloca, value; -#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability(comp_ctx, "f32.const")) { WASMValue wasm_value; @@ -87,9 +82,6 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, PUSH_F32(value); } else if (!isnan(f32_const)) { -#else - if (!isnan(f32_const)) { -#endif value = F32_CONST(f32_const); CHECK_LLVM_CONST(value); PUSH_F32(value); @@ -131,7 +123,6 @@ aot_compile_op_f64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMValueRef alloca, value; -#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability(comp_ctx, "f64.const")) { WASMValue wasm_value; @@ -144,9 +135,6 @@ aot_compile_op_f64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, PUSH_F64(value); } else if (!isnan(f64_const)) { -#else - if (!isnan(f64_const)) { -#endif value = F64_CONST(f64_const); CHECK_LLVM_CONST(value); PUSH_F64(value); diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index b9d467dd59..979a2cb88b 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -139,7 +139,6 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, is_target_64bit = (comp_ctx->pointer_size == sizeof(uint64)) ? true : false; -#if !defined(BUILD_TARGET_XTENSA) if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability( comp_ctx, MEMORY64_COND_VALUE("i64.const", "i32.const"))) { @@ -149,7 +148,6 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, wasm_value.i64 = offset; } else -#endif { wasm_value.i32 = (int32)offset; } From 719a28486328e0bcd737e52fd1b0dbdf780ac662 Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Tue, 25 Mar 2025 14:27:04 +0800 Subject: [PATCH 04/13] Use clang-format-12 to format src file --- core/iwasm/compilation/aot_emit_const.c | 6 ++---- core/iwasm/compilation/aot_emit_memory.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/core/iwasm/compilation/aot_emit_const.c b/core/iwasm/compilation/aot_emit_const.c index 9d19547324..64fa3ded1a 100644 --- a/core/iwasm/compilation/aot_emit_const.c +++ b/core/iwasm/compilation/aot_emit_const.c @@ -22,8 +22,7 @@ aot_compile_op_i32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } } - else - { + else { value = I32_CONST((uint32)i32_const); CHECK_LLVM_CONST(value); } @@ -51,8 +50,7 @@ aot_compile_op_i64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } } - else - { + else { value = I64_CONST((uint64)i64_const); CHECK_LLVM_CONST(value); } diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index 979a2cb88b..002ed32aa8 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -147,8 +147,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, if (IS_MEMORY64) { wasm_value.i64 = offset; } - else - { + else { wasm_value.i32 = (int32)offset; } offset_const = aot_load_const_from_table( From a11d0000ff62dc7cbffceeb8eeaee812fbe2d6da Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Tue, 25 Mar 2025 14:31:45 +0800 Subject: [PATCH 05/13] fix wrong displacement for #endif --- core/iwasm/compilation/aot_emit_memory.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index 002ed32aa8..e685fccd92 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -147,7 +147,9 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, if (IS_MEMORY64) { wasm_value.i64 = offset; } - else { + else +#endif + { wasm_value.i32 = (int32)offset; } offset_const = aot_load_const_from_table( @@ -157,9 +159,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return NULL; } } - else -#endif - { + else { CHECK_LLVM_CONST(offset_const); } From d3d941e8dad259bee38465e1ff746ba08b4dfe87 Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Wed, 26 Mar 2025 17:47:43 +0800 Subject: [PATCH 06/13] Add more intrinsic flags for conversions --- core/iwasm/compilation/aot_emit_conversion.c | 108 +++++++++---------- 1 file changed, 48 insertions(+), 60 deletions(-) diff --git a/core/iwasm/compilation/aot_emit_conversion.c b/core/iwasm/compilation/aot_emit_conversion.c index d4372ad743..fa5c2ab955 100644 --- a/core/iwasm/compilation/aot_emit_conversion.c +++ b/core/iwasm/compilation/aot_emit_conversion.c @@ -347,20 +347,8 @@ aot_compile_op_i32_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F32(value); -#if !defined(BUILD_TARGET_XTENSA) - if (!comp_ctx->is_indirect_mode) { -#endif - if (sign) { - min_value = F32_CONST(-2147483904.0f); - max_value = F32_CONST(2147483648.0f); - } - else { - min_value = F32_CONST(-1.0f); - max_value = F32_CONST(4294967296.0f); - } -#if !defined(BUILD_TARGET_XTENSA) - } - else { + if (comp_ctx->is_indirect_mode + && aot_intrinsic_check_capability(comp_ctx, "f32.const")) { WASMValue wasm_value; if (sign) { wasm_value.f32 = -2147483904.0f; @@ -379,7 +367,16 @@ aot_compile_op_i32_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32); } } -#endif + else { + if (sign) { + min_value = F32_CONST(-2147483904.0f); + max_value = F32_CONST(2147483648.0f); + } + else { + min_value = F32_CONST(-1.0f); + max_value = F32_CONST(4294967296.0f); + } + } CHECK_LLVM_CONST(min_value); CHECK_LLVM_CONST(max_value); @@ -404,20 +401,8 @@ aot_compile_op_i32_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F64(value); -#if !defined(BUILD_TARGET_XTENSA) - if (!comp_ctx->is_indirect_mode) { -#endif - if (sign) { - min_value = F64_CONST(-2147483649.0); - max_value = F64_CONST(2147483648.0); - } - else { - min_value = F64_CONST(-1.0); - max_value = F64_CONST(4294967296.0); - } -#if !defined(BUILD_TARGET_XTENSA) - } - else { + if (comp_ctx->is_indirect_mode + && aot_intrinsic_check_capability(comp_ctx, "f64.const")) { WASMValue wasm_value; if (sign) { wasm_value.f64 = -2147483649.0; @@ -436,7 +421,16 @@ aot_compile_op_i32_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64); } } -#endif + else { + if (sign) { + min_value = F64_CONST(-2147483649.0); + max_value = F64_CONST(2147483648.0); + } + else { + min_value = F64_CONST(-1.0); + max_value = F64_CONST(4294967296.0); + } + } CHECK_LLVM_CONST(min_value); CHECK_LLVM_CONST(max_value); @@ -562,20 +556,8 @@ aot_compile_op_i64_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F32(value); -#if !defined(BUILD_TARGET_XTENSA) - if (!comp_ctx->is_indirect_mode) { -#endif - if (sign) { - min_value = F32_CONST(-9223373136366403584.0f); - max_value = F32_CONST(9223372036854775808.0f); - } - else { - min_value = F32_CONST(-1.0f); - max_value = F32_CONST(18446744073709551616.0f); - } -#if !defined(BUILD_TARGET_XTENSA) - } - else { + if (comp_ctx->is_indirect_mode + && aot_intrinsic_check_capability(comp_ctx, "f32.const")) { WASMValue wasm_value; if (sign) { wasm_value.f32 = -9223373136366403584.0f; @@ -594,7 +576,16 @@ aot_compile_op_i64_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32); } } -#endif + else { + if (sign) { + min_value = F32_CONST(-9223373136366403584.0f); + max_value = F32_CONST(9223372036854775808.0f); + } + else { + min_value = F32_CONST(-1.0f); + max_value = F32_CONST(18446744073709551616.0f); + } + } CHECK_LLVM_CONST(min_value); CHECK_LLVM_CONST(max_value); @@ -619,20 +610,8 @@ aot_compile_op_i64_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F64(value); -#if !defined(BUILD_TARGET_XTENSA) - if (!comp_ctx->is_indirect_mode) { -#endif - if (sign) { - min_value = F64_CONST(-9223372036854777856.0); - max_value = F64_CONST(9223372036854775808.0); - } - else { - min_value = F64_CONST(-1.0); - max_value = F64_CONST(18446744073709551616.0); - } -#if !defined(BUILD_TARGET_XTENSA) - } - else { + if (comp_ctx->is_indirect_mode + && aot_intrinsic_check_capability(comp_ctx, "f64.const")) { WASMValue wasm_value; if (sign) { wasm_value.f64 = -9223372036854777856.0; @@ -651,7 +630,16 @@ aot_compile_op_i64_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64); } } -#endif + else { + if (sign) { + min_value = F64_CONST(-9223372036854777856.0); + max_value = F64_CONST(9223372036854775808.0); + } + else { + min_value = F64_CONST(-1.0); + max_value = F64_CONST(18446744073709551616.0); + } + } CHECK_LLVM_CONST(min_value); CHECK_LLVM_CONST(max_value); From b024dd0eafc48b19360973816fe59814a0865ff2 Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Thu, 27 Mar 2025 17:42:14 +0800 Subject: [PATCH 07/13] Add constraints for f32/f64_compare --- core/iwasm/compilation/aot_emit_compare.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/iwasm/compilation/aot_emit_compare.c b/core/iwasm/compilation/aot_emit_compare.c index c57bdee402..23929e6d2e 100644 --- a/core/iwasm/compilation/aot_emit_compare.c +++ b/core/iwasm/compilation/aot_emit_compare.c @@ -159,6 +159,7 @@ aot_compile_op_f32_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F32(lhs); if (comp_ctx->disable_llvm_intrinsics + && aot_intrinsic_check_capability(comp_ctx, "f32.const") && aot_intrinsic_check_capability(comp_ctx, "f32_cmp")) { LLVMTypeRef param_types[3]; LLVMValueRef opcond = LLVMConstInt(I32_TYPE, cond, true); @@ -203,6 +204,7 @@ aot_compile_op_f64_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F64(lhs); if (comp_ctx->disable_llvm_intrinsics + && aot_intrinsic_check_capability(comp_ctx, "f64.const") && aot_intrinsic_check_capability(comp_ctx, "f64_cmp")) { LLVMTypeRef param_types[3]; LLVMValueRef opcond = LLVMConstInt(I32_TYPE, cond, true); From e0f56df76e2dd1c1c9b2dd9367ab9e347d24bfe3 Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Thu, 27 Mar 2025 17:44:01 +0800 Subject: [PATCH 08/13] Use clang-format to format aot_emit_compare.c --- core/iwasm/compilation/aot_emit_compare.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/compilation/aot_emit_compare.c b/core/iwasm/compilation/aot_emit_compare.c index 23929e6d2e..ee8d51b9a7 100644 --- a/core/iwasm/compilation/aot_emit_compare.c +++ b/core/iwasm/compilation/aot_emit_compare.c @@ -159,7 +159,7 @@ aot_compile_op_f32_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F32(lhs); if (comp_ctx->disable_llvm_intrinsics - && aot_intrinsic_check_capability(comp_ctx, "f32.const") + && aot_intrinsic_check_capability(comp_ctx, "f32.const") && aot_intrinsic_check_capability(comp_ctx, "f32_cmp")) { LLVMTypeRef param_types[3]; LLVMValueRef opcond = LLVMConstInt(I32_TYPE, cond, true); From a10ac13067accc34a2e1c5c4ba219bd9c8012722 Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Thu, 27 Mar 2025 18:08:39 +0800 Subject: [PATCH 09/13] Constraints for f32/f64_compare() only enabled when target is xtensa to avoid relocation --- core/iwasm/compilation/aot_emit_compare.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/iwasm/compilation/aot_emit_compare.c b/core/iwasm/compilation/aot_emit_compare.c index ee8d51b9a7..09250f5ca7 100644 --- a/core/iwasm/compilation/aot_emit_compare.c +++ b/core/iwasm/compilation/aot_emit_compare.c @@ -159,8 +159,8 @@ aot_compile_op_f32_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F32(lhs); if (comp_ctx->disable_llvm_intrinsics - && aot_intrinsic_check_capability(comp_ctx, "f32.const") - && aot_intrinsic_check_capability(comp_ctx, "f32_cmp")) { + && aot_intrinsic_check_capability(comp_ctx, "f32_cmp") + && strcmp(comp_ctx->target_arch, "xtensa")) { LLVMTypeRef param_types[3]; LLVMValueRef opcond = LLVMConstInt(I32_TYPE, cond, true); param_types[0] = I32_TYPE; @@ -204,8 +204,8 @@ aot_compile_op_f64_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F64(lhs); if (comp_ctx->disable_llvm_intrinsics - && aot_intrinsic_check_capability(comp_ctx, "f64.const") - && aot_intrinsic_check_capability(comp_ctx, "f64_cmp")) { + && aot_intrinsic_check_capability(comp_ctx, "f64_cmp") + && strcmp(comp_ctx->target_arch, "xtensa")) { LLVMTypeRef param_types[3]; LLVMValueRef opcond = LLVMConstInt(I32_TYPE, cond, true); param_types[0] = I32_TYPE; From 9458e9646640585b854aef6593f8bdacb87d21e5 Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Fri, 28 Mar 2025 10:35:36 +0800 Subject: [PATCH 10/13] Remove xtensa constraints for f64_cmp to avoid relocations --- core/iwasm/compilation/aot_emit_compare.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/compilation/aot_emit_compare.c b/core/iwasm/compilation/aot_emit_compare.c index 09250f5ca7..1db11b2067 100644 --- a/core/iwasm/compilation/aot_emit_compare.c +++ b/core/iwasm/compilation/aot_emit_compare.c @@ -205,7 +205,7 @@ aot_compile_op_f64_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, if (comp_ctx->disable_llvm_intrinsics && aot_intrinsic_check_capability(comp_ctx, "f64_cmp") - && strcmp(comp_ctx->target_arch, "xtensa")) { + ) { LLVMTypeRef param_types[3]; LLVMValueRef opcond = LLVMConstInt(I32_TYPE, cond, true); param_types[0] = I32_TYPE; From 866f55bb12a2e4622a1dfe89b1b8b0173d9022ff Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Fri, 28 Mar 2025 10:36:40 +0800 Subject: [PATCH 11/13] Use clang-format to format ../../core/iwasm/compilation/aot_emit_compare.c --- core/iwasm/compilation/aot_emit_compare.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/iwasm/compilation/aot_emit_compare.c b/core/iwasm/compilation/aot_emit_compare.c index 1db11b2067..782a2f1493 100644 --- a/core/iwasm/compilation/aot_emit_compare.c +++ b/core/iwasm/compilation/aot_emit_compare.c @@ -204,8 +204,7 @@ aot_compile_op_f64_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F64(lhs); if (comp_ctx->disable_llvm_intrinsics - && aot_intrinsic_check_capability(comp_ctx, "f64_cmp") - ) { + && aot_intrinsic_check_capability(comp_ctx, "f64_cmp")) { LLVMTypeRef param_types[3]; LLVMValueRef opcond = LLVMConstInt(I32_TYPE, cond, true); param_types[0] = I32_TYPE; From b01fc5b382f43b56ff997abcb5417ebc9767f24f Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Tue, 1 Apr 2025 15:59:58 +0800 Subject: [PATCH 12/13] Add AOT_INTRINSIC_FLAG_F32_CONST for xtensa frontend, because espressif xtensa llvm backend does not support float-point immediate for now --- core/iwasm/aot/aot_intrinsic.c | 1 + core/iwasm/compilation/aot_emit_compare.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/iwasm/aot/aot_intrinsic.c b/core/iwasm/aot/aot_intrinsic.c index 25784a8d14..88a7a52c0d 100644 --- a/core/iwasm/aot/aot_intrinsic.c +++ b/core/iwasm/aot/aot_intrinsic.c @@ -877,6 +877,7 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx) add_f64_common_intrinsics(comp_ctx); add_i64_common_intrinsics(comp_ctx); add_common_float_integer_conversion(comp_ctx); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CONST); } else { /* diff --git a/core/iwasm/compilation/aot_emit_compare.c b/core/iwasm/compilation/aot_emit_compare.c index 782a2f1493..c57bdee402 100644 --- a/core/iwasm/compilation/aot_emit_compare.c +++ b/core/iwasm/compilation/aot_emit_compare.c @@ -159,8 +159,7 @@ aot_compile_op_f32_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, POP_F32(lhs); if (comp_ctx->disable_llvm_intrinsics - && aot_intrinsic_check_capability(comp_ctx, "f32_cmp") - && strcmp(comp_ctx->target_arch, "xtensa")) { + && aot_intrinsic_check_capability(comp_ctx, "f32_cmp")) { LLVMTypeRef param_types[3]; LLVMValueRef opcond = LLVMConstInt(I32_TYPE, cond, true); param_types[0] = I32_TYPE; From aa1db1b8a6b518a5a7f6997f56bcc5656e44e4d4 Mon Sep 17 00:00:00 2001 From: zhanheng1 Date: Tue, 1 Apr 2025 16:03:15 +0800 Subject: [PATCH 13/13] Use clang-format-12 to format aot_intrinsic.c --- core/iwasm/aot/aot_intrinsic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/aot/aot_intrinsic.c b/core/iwasm/aot/aot_intrinsic.c index 88a7a52c0d..5f62abf24d 100644 --- a/core/iwasm/aot/aot_intrinsic.c +++ b/core/iwasm/aot/aot_intrinsic.c @@ -877,7 +877,7 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx) add_f64_common_intrinsics(comp_ctx); add_i64_common_intrinsics(comp_ctx); add_common_float_integer_conversion(comp_ctx); - add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CONST); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CONST); } else { /*