Skip to content

Commit

Permalink
Fix XIP issue caused by rem_s on RISC-V (bytecodealliance#1619)
Browse files Browse the repository at this point in the history
  • Loading branch information
no1wudi authored Oct 19, 2022
1 parent 1c5034b commit 73809ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
#define WASM_ENABLE_UVWASI 0
#endif

#ifndef WASM_ENABLE_WASI_NN
#define WASM_ENABLE_WASI_NN 0
#endif

/* Default disable libc emcc */
#ifndef WASM_ENABLE_LIBC_EMCC
#define WASM_ENABLE_LIBC_EMCC 0
Expand Down
6 changes: 3 additions & 3 deletions core/iwasm/aot/aot_intrinsic.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,9 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx)
add_f32_common_intrinsics(comp_ctx);
add_f64_common_intrinsics(comp_ctx);
add_common_float_integer_convertion(comp_ctx);
}
else if (!strncmp(comp_ctx->target_arch, "riscv32", 7)) {
add_i64_common_intrinsics(comp_ctx);
if (!strncmp(comp_ctx->target_arch, "riscv32", 7)) {
add_i64_common_intrinsics(comp_ctx);
}
}
else if (!strncmp(comp_ctx->target_arch, "xtensa", 6)) {
/*
Expand Down
13 changes: 12 additions & 1 deletion core/iwasm/compilation/aot_emit_numberic.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ compile_rems(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
{
LLVMValueRef phi, no_overflow_value, zero = is_i32 ? I32_ZERO : I64_ZERO;
LLVMBasicBlockRef block_curr, no_overflow_block, rems_end_block;
LLVMTypeRef param_types[2];

param_types[1] = param_types[0] = is_i32 ? I32_TYPE : I64_TYPE;

block_curr = LLVMGetInsertBlock(comp_ctx->builder);

Expand All @@ -349,7 +352,15 @@ compile_rems(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMPositionBuilderAtEnd(comp_ctx->builder, no_overflow_block);

/* Calculate the rem value */
LLVM_BUILD_OP(SRem, left, right, no_overflow_value, "rem_s", false);
if (comp_ctx->disable_llvm_intrinsics && !is_i32
&& aot_intrinsic_check_capability(comp_ctx, "i64.rem_s")) {
no_overflow_value =
aot_call_llvm_intrinsic(comp_ctx, func_ctx, "rem_s", param_types[0],
param_types, 2, left, right);
}
else {
LLVM_BUILD_OP(SRem, left, right, no_overflow_value, "rem_s", false);
}

/* Jump to rems_end block */
if (!LLVMBuildBr(comp_ctx->builder, rems_end_block)) {
Expand Down

0 comments on commit 73809ef

Please sign in to comment.