Skip to content

Commit cfcaca3

Browse files
authored
Refine build script of zephyr product-mini, enable aot soft-float support (#188)
1 parent be69c51 commit cfcaca3

File tree

10 files changed

+170
-29
lines changed

10 files changed

+170
-29
lines changed

core/iwasm/aot/arch/aot_reloc_arm.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ void __aeabi_idivmod();
4444
void __aeabi_uidivmod();
4545
void __aeabi_ldivmod();
4646
void __aeabi_uldivmod();
47+
void __aeabi_i2d();
48+
void __aeabi_dadd();
49+
void __aeabi_ddiv();
50+
void __aeabi_dcmplt();
51+
void __aeabi_dcmpun();
52+
void __aeabi_dcmple();
53+
void __aeabi_dcmpge();
54+
void __aeabi_d2iz();
55+
void __aeabi_fcmplt();
56+
void __aeabi_fcmpun();
57+
void __aeabi_fcmple();
58+
void __aeabi_fcmpge();
59+
void __aeabi_f2iz();
60+
void __aeabi_f2d();
4761

4862
static SymbolMap target_sym_map[] = {
4963
REG_COMMON_SYMBOLS,
@@ -77,7 +91,21 @@ static SymbolMap target_sym_map[] = {
7791
REG_SYM(__aeabi_idivmod),
7892
REG_SYM(__aeabi_uidivmod),
7993
REG_SYM(__aeabi_ldivmod),
80-
REG_SYM(__aeabi_uldivmod)
94+
REG_SYM(__aeabi_uldivmod),
95+
REG_SYM(__aeabi_i2d),
96+
REG_SYM(__aeabi_dadd),
97+
REG_SYM(__aeabi_ddiv),
98+
REG_SYM(__aeabi_dcmplt),
99+
REG_SYM(__aeabi_dcmpun),
100+
REG_SYM(__aeabi_dcmple),
101+
REG_SYM(__aeabi_dcmpge),
102+
REG_SYM(__aeabi_d2iz),
103+
REG_SYM(__aeabi_fcmplt),
104+
REG_SYM(__aeabi_fcmpun),
105+
REG_SYM(__aeabi_fcmple),
106+
REG_SYM(__aeabi_fcmpge),
107+
REG_SYM(__aeabi_f2iz),
108+
REG_SYM(__aeabi_f2d),
81109
};
82110

83111
static void

core/iwasm/aot/arch/aot_reloc_thumb.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ void __aeabi_idivmod();
4343
void __aeabi_uidivmod();
4444
void __aeabi_ldivmod();
4545
void __aeabi_uldivmod();
46+
void __aeabi_i2d();
47+
void __aeabi_dadd();
48+
void __aeabi_ddiv();
49+
void __aeabi_dcmplt();
50+
void __aeabi_dcmpun();
51+
void __aeabi_dcmple();
52+
void __aeabi_dcmpge();
53+
void __aeabi_d2iz();
54+
void __aeabi_fcmplt();
55+
void __aeabi_fcmpun();
56+
void __aeabi_fcmple();
57+
void __aeabi_fcmpge();
58+
void __aeabi_f2iz();
59+
void __aeabi_f2d();
4660

4761
static SymbolMap target_sym_map[] = {
4862
REG_COMMON_SYMBOLS,
@@ -76,7 +90,21 @@ static SymbolMap target_sym_map[] = {
7690
REG_SYM(__aeabi_idivmod),
7791
REG_SYM(__aeabi_uidivmod),
7892
REG_SYM(__aeabi_ldivmod),
79-
REG_SYM(__aeabi_uldivmod)
93+
REG_SYM(__aeabi_uldivmod),
94+
REG_SYM(__aeabi_i2d),
95+
REG_SYM(__aeabi_dadd),
96+
REG_SYM(__aeabi_ddiv),
97+
REG_SYM(__aeabi_dcmplt),
98+
REG_SYM(__aeabi_dcmpun),
99+
REG_SYM(__aeabi_dcmple),
100+
REG_SYM(__aeabi_dcmpge),
101+
REG_SYM(__aeabi_d2iz),
102+
REG_SYM(__aeabi_fcmplt),
103+
REG_SYM(__aeabi_fcmpun),
104+
REG_SYM(__aeabi_fcmple),
105+
REG_SYM(__aeabi_fcmpge),
106+
REG_SYM(__aeabi_f2iz),
107+
REG_SYM(__aeabi_f2d),
80108
};
81109

82110
static void

core/iwasm/compilation/aot_emit_numberic.c

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -857,13 +857,34 @@ compile_op_int_shift(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
857857
return false;
858858
}
859859

860+
static bool
861+
is_targeting_soft_float(LLVMTargetMachineRef target_machine)
862+
{
863+
bool ret = false;
864+
char *feature_string;
865+
866+
if (!(feature_string =
867+
LLVMGetTargetMachineFeatureString(target_machine))) {
868+
aot_set_last_error("llvm get target machine feature string fail.");
869+
return false;
870+
}
871+
872+
ret = strstr(feature_string, "+soft-float") ? true : false;
873+
LLVMDisposeMessage(feature_string);
874+
return ret;
875+
}
876+
860877
static bool
861878
compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
862879
FloatArithmetic arith_op, bool is_f32)
863880
{
864881
switch (arith_op) {
865882
case FLOAT_ADD:
866-
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic(
883+
if (is_targeting_soft_float(comp_ctx->target_machine))
884+
DEF_FP_BINARY_OP(LLVMBuildFAdd(comp_ctx->builder, left, right, "fadd"),
885+
"llvm build fadd fail.");
886+
else
887+
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic(
867888
comp_ctx,
868889
(is_f32
869890
? "llvm.experimental.constrained.fadd.f32"
@@ -873,10 +894,14 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
873894
right,
874895
comp_ctx->fp_rounding_mode,
875896
comp_ctx->fp_exception_behavior),
876-
NULL);
897+
NULL);
877898
return true;
878899
case FLOAT_SUB:
879-
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic(
900+
if (is_targeting_soft_float(comp_ctx->target_machine))
901+
DEF_FP_BINARY_OP(LLVMBuildFSub(comp_ctx->builder, left, right, "fsub"),
902+
"llvm build fsub fail.");
903+
else
904+
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic(
880905
comp_ctx,
881906
(is_f32
882907
? "llvm.experimental.constrained.fsub.f32"
@@ -886,10 +911,14 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
886911
right,
887912
comp_ctx->fp_rounding_mode,
888913
comp_ctx->fp_exception_behavior),
889-
NULL);
914+
NULL);
890915
return true;
891916
case FLOAT_MUL:
892-
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic(
917+
if (is_targeting_soft_float(comp_ctx->target_machine))
918+
DEF_FP_BINARY_OP(LLVMBuildFMul(comp_ctx->builder, left, right, "fmul"),
919+
"llvm build fmul fail.");
920+
else
921+
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic(
893922
comp_ctx,
894923
(is_f32
895924
? "llvm.experimental.constrained.fmul.f32"
@@ -899,10 +928,14 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
899928
right,
900929
comp_ctx->fp_rounding_mode,
901930
comp_ctx->fp_exception_behavior),
902-
NULL);
931+
NULL);
903932
return true;
904933
case FLOAT_DIV:
905-
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic(
934+
if (is_targeting_soft_float(comp_ctx->target_machine))
935+
DEF_FP_BINARY_OP(LLVMBuildFDiv(comp_ctx->builder, left, right, "fdiv"),
936+
"llvm build fdiv fail.");
937+
else
938+
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic(
906939
comp_ctx,
907940
(is_f32
908941
? "llvm.experimental.constrained.fdiv.f32"
@@ -912,7 +945,7 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
912945
right,
913946
comp_ctx->fp_rounding_mode,
914947
comp_ctx->fp_exception_behavior),
915-
NULL);
948+
NULL);
916949
return true;
917950
case FLOAT_MIN:
918951
DEF_FP_BINARY_OP(compile_op_float_min_max(comp_ctx,
@@ -1017,7 +1050,15 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
10171050
NULL);
10181051
return true;
10191052
case FLOAT_SQRT:
1020-
DEF_FP_UNARY_OP(call_llvm_libm_expermental_constrained_intrinsic(
1053+
if (is_targeting_soft_float(comp_ctx->target_machine))
1054+
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
1055+
is_f32 ? "llvm.sqrt.f32" :
1056+
"llvm.sqrt.f64",
1057+
is_f32,
1058+
operand),
1059+
NULL);
1060+
else
1061+
DEF_FP_UNARY_OP(call_llvm_libm_expermental_constrained_intrinsic(
10211062
comp_ctx,
10221063
(is_f32
10231064
? "llvm.experimental.constrained.sqrt.f32"
@@ -1026,7 +1067,7 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
10261067
operand,
10271068
comp_ctx->fp_rounding_mode,
10281069
comp_ctx->fp_exception_behavior),
1029-
NULL);
1070+
NULL);
10301071
return true;
10311072
default:
10321073
bh_assert(0);

doc/build_wamr.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,19 @@ cd zephyr/samples/
155155
cp -a <wamr_root_dir>/product-mini/platforms/zephyr/simple .
156156
cd simple
157157
ln -s <wamr_root_dir> wamr
158-
mkdir build && cd build
159-
source ../../../zephyr-env.sh
158+
source ../../zephyr-env.sh
160159
161-
1. build for x86
162-
cmake -GNinja -DBOARD=qemu_x86_nommu ..
163-
ninja
164-
2. build for ARM
165-
modify ../prj.conf, modify the commented line "# CONFIG_ARM_MPU is not set" to "CONFIG_ARM_MPU=y"
166-
cmake -GNinja -DBOARD=nucleo_f767zi -DWAMR_BUILD_TARGET=THUMBV7 ..
167-
ninja
160+
```
168161
162+
1. build for x86 (qemu_x86_nommu)
163+
``` Bash
164+
./build.sh x86
169165
```
166+
2. build for ARM (nucleo_f767zi)
167+
``` Bash
168+
./build.sh stm32
169+
```
170+
170171
Note:
171172
WAMR provides some features which can be easily configured by passing options to cmake, please see [Linux platform](./build_wamr.md#linux) for details. Currently in Zephyr, interpreter, AoT and builtin libc are enabled by default.
172173

product-mini/platforms/linux/build_llvm.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/bin/sh
22

3-
# Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
# Copyright (C) 2020 Intel Corporation. All rights reserved.
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

66
DEPS_DIR=${PWD}/../../../core/deps
77

88
cd ${DEPS_DIR}
99
if [ ! -d "llvm" ]; then
1010
echo "Clone llvm to core/deps/ .."
11-
git clone https://github.com/llvm-mirror/llvm.git
11+
git clone --depth 1 https://github.com/llvm-mirror/llvm.git
1212
fi
1313

1414
cd llvm
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
X86_TARGET="x86"
7+
STM32_TARGET="stm32"
8+
9+
if [ $# != 1 ] ; then
10+
echo "USAGE:"
11+
echo "$0 $X86_TARGET|$STM32_TARGET"
12+
echo "Example:"
13+
echo " $0 $X86_TARGET"
14+
echo " $0 $STM32_TARGET"
15+
exit 1
16+
fi
17+
18+
TARGET=$1
19+
20+
if [ "$TARGET" = "$X86_TARGET" ] ; then
21+
cp prj_qemu_x86_nommu.conf prj.conf
22+
rm -fr build && mkdir build && cd build
23+
cmake -GNinja -DBOARD=qemu_x86_nommu -DWAMR_BUILD_TARGET=X86_32 ..
24+
ninja
25+
ninja run
26+
elif [ "$TARGET" = "$STM32_TARGET" ] ; then
27+
cp prj_nucleo767zi.conf prj.conf
28+
rm -fr build && mkdir build && cd build
29+
cmake -GNinja -DBOARD=nucleo_f767zi -DWAMR_BUILD_TARGET=THUMBV7 ..
30+
ninja
31+
ninja flash
32+
else
33+
echo "unsupported target: $TARGET"
34+
exit 1
35+
fi

product-mini/platforms/zephyr/simple/prj.conf

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
CONFIG_ARM_MPU=y
5+
CONFIG_STACK_SENTINEL=y
6+
CONFIG_PRINTK=y
7+
CONFIG_LOG=y
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
CONFIG_STACK_SENTINEL=y
5+
CONFIG_PRINTK=y
6+
CONFIG_LOG=y

samples/gui/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,4 @@ First, connect PC and STM32 with UART. Then install to use host_tool.</br>
117117

118118
The graphic user interface demo photo:
119119

120-
![WAMR samples diagram](../../doc/pics/vgl_demo.png "WAMR samples diagram")
120+
![WAMR samples diagram](../../doc/pics/vgl_demo.png "WAMR samples diagram")

0 commit comments

Comments
 (0)