Skip to content

Commit 4e50d21

Browse files
Remove indirect-load for constants on Xtensa Target to improve performance (#4162)
* Remove indirect-load for constants on Xtensa Target to improve performance * Remove const intrinsics flags for xtensa instead of adding too much #ifdef * Add AOT_INTRINSIC_FLAG_F32_CONST for xtensa frontend, because espressif xtensa llvm backend does not support float-point immediate for now --------- Co-authored-by: zhanheng1 <[email protected]>
1 parent 6424122 commit 4e50d21

File tree

2 files changed

+48
-47
lines changed

2 files changed

+48
-47
lines changed

core/iwasm/aot/aot_intrinsic.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,9 +878,6 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx)
878878
add_i64_common_intrinsics(comp_ctx);
879879
add_common_float_integer_conversion(comp_ctx);
880880
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CONST);
881-
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_CONST);
882-
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I32_CONST);
883-
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I64_CONST);
884881
}
885882
else {
886883
/*

core/iwasm/compilation/aot_emit_conversion.c

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,8 @@ aot_compile_op_i32_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
347347

348348
POP_F32(value);
349349

350-
if (!comp_ctx->is_indirect_mode) {
351-
if (sign) {
352-
min_value = F32_CONST(-2147483904.0f);
353-
max_value = F32_CONST(2147483648.0f);
354-
}
355-
else {
356-
min_value = F32_CONST(-1.0f);
357-
max_value = F32_CONST(4294967296.0f);
358-
}
359-
}
360-
else {
350+
if (comp_ctx->is_indirect_mode
351+
&& aot_intrinsic_check_capability(comp_ctx, "f32.const")) {
361352
WASMValue wasm_value;
362353
if (sign) {
363354
wasm_value.f32 = -2147483904.0f;
@@ -376,6 +367,16 @@ aot_compile_op_i32_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
376367
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32);
377368
}
378369
}
370+
else {
371+
if (sign) {
372+
min_value = F32_CONST(-2147483904.0f);
373+
max_value = F32_CONST(2147483648.0f);
374+
}
375+
else {
376+
min_value = F32_CONST(-1.0f);
377+
max_value = F32_CONST(4294967296.0f);
378+
}
379+
}
379380
CHECK_LLVM_CONST(min_value);
380381
CHECK_LLVM_CONST(max_value);
381382

@@ -400,17 +401,8 @@ aot_compile_op_i32_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
400401

401402
POP_F64(value);
402403

403-
if (!comp_ctx->is_indirect_mode) {
404-
if (sign) {
405-
min_value = F64_CONST(-2147483649.0);
406-
max_value = F64_CONST(2147483648.0);
407-
}
408-
else {
409-
min_value = F64_CONST(-1.0);
410-
max_value = F64_CONST(4294967296.0);
411-
}
412-
}
413-
else {
404+
if (comp_ctx->is_indirect_mode
405+
&& aot_intrinsic_check_capability(comp_ctx, "f64.const")) {
414406
WASMValue wasm_value;
415407
if (sign) {
416408
wasm_value.f64 = -2147483649.0;
@@ -429,6 +421,16 @@ aot_compile_op_i32_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
429421
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64);
430422
}
431423
}
424+
else {
425+
if (sign) {
426+
min_value = F64_CONST(-2147483649.0);
427+
max_value = F64_CONST(2147483648.0);
428+
}
429+
else {
430+
min_value = F64_CONST(-1.0);
431+
max_value = F64_CONST(4294967296.0);
432+
}
433+
}
432434
CHECK_LLVM_CONST(min_value);
433435
CHECK_LLVM_CONST(max_value);
434436

@@ -554,17 +556,8 @@ aot_compile_op_i64_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
554556

555557
POP_F32(value);
556558

557-
if (!comp_ctx->is_indirect_mode) {
558-
if (sign) {
559-
min_value = F32_CONST(-9223373136366403584.0f);
560-
max_value = F32_CONST(9223372036854775808.0f);
561-
}
562-
else {
563-
min_value = F32_CONST(-1.0f);
564-
max_value = F32_CONST(18446744073709551616.0f);
565-
}
566-
}
567-
else {
559+
if (comp_ctx->is_indirect_mode
560+
&& aot_intrinsic_check_capability(comp_ctx, "f32.const")) {
568561
WASMValue wasm_value;
569562
if (sign) {
570563
wasm_value.f32 = -9223373136366403584.0f;
@@ -583,6 +576,16 @@ aot_compile_op_i64_trunc_f32(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
583576
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32);
584577
}
585578
}
579+
else {
580+
if (sign) {
581+
min_value = F32_CONST(-9223373136366403584.0f);
582+
max_value = F32_CONST(9223372036854775808.0f);
583+
}
584+
else {
585+
min_value = F32_CONST(-1.0f);
586+
max_value = F32_CONST(18446744073709551616.0f);
587+
}
588+
}
586589
CHECK_LLVM_CONST(min_value);
587590
CHECK_LLVM_CONST(max_value);
588591

@@ -607,17 +610,8 @@ aot_compile_op_i64_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
607610

608611
POP_F64(value);
609612

610-
if (!comp_ctx->is_indirect_mode) {
611-
if (sign) {
612-
min_value = F64_CONST(-9223372036854777856.0);
613-
max_value = F64_CONST(9223372036854775808.0);
614-
}
615-
else {
616-
min_value = F64_CONST(-1.0);
617-
max_value = F64_CONST(18446744073709551616.0);
618-
}
619-
}
620-
else {
613+
if (comp_ctx->is_indirect_mode
614+
&& aot_intrinsic_check_capability(comp_ctx, "f64.const")) {
621615
WASMValue wasm_value;
622616
if (sign) {
623617
wasm_value.f64 = -9223372036854777856.0;
@@ -636,6 +630,16 @@ aot_compile_op_i64_trunc_f64(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
636630
comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64);
637631
}
638632
}
633+
else {
634+
if (sign) {
635+
min_value = F64_CONST(-9223372036854777856.0);
636+
max_value = F64_CONST(9223372036854775808.0);
637+
}
638+
else {
639+
min_value = F64_CONST(-1.0);
640+
max_value = F64_CONST(18446744073709551616.0);
641+
}
642+
}
639643
CHECK_LLVM_CONST(min_value);
640644
CHECK_LLVM_CONST(max_value);
641645

0 commit comments

Comments
 (0)