diff --git a/core/shared/platform/common/math/math.c b/core/shared/platform/common/math/math.c index a9fcf021..2ba9f4d2 100644 --- a/core/shared/platform/common/math/math.c +++ b/core/shared/platform/common/math/math.c @@ -449,8 +449,6 @@ ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */ ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/ ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/ -static double -freebsd_sqrt(double x); static double freebsd_floor(double x); static double @@ -622,6 +620,7 @@ freebsd_atan2(double y, double x) } } +#ifndef BH_HAS_SQRTF static float freebsd_sqrtf(float x) { @@ -689,7 +688,9 @@ freebsd_sqrtf(float x) SET_FLOAT_WORD(z, ix); return z; } +#endif /* end of BH_HAS_SQRTF */ +#ifndef BH_HAS_SQRT static double freebsd_sqrt(double x) /* wrapper sqrt */ { @@ -799,6 +800,7 @@ freebsd_sqrt(double x) /* wrapper sqrt */ return z; } +#endif /* end of BH_HAS_SQRT */ static double freebsd_floor(double x) @@ -1554,11 +1556,13 @@ atan2(double y, double x) return freebsd_atan2(y, x); } +#ifndef BH_HAS_SQRT double sqrt(double x) { return freebsd_sqrt(x); } +#endif double floor(double x) @@ -1656,11 +1660,13 @@ fmaxf(float x, float y) return freebsd_fmaxf(x, y); } +#ifndef BH_HAS_SQRTF float sqrtf(float x) { return freebsd_sqrtf(x); } +#endif double pow(double x, double y) diff --git a/core/shared/platform/include/platform_common.h b/core/shared/platform/include/platform_common.h index 9890202d..28001af7 100644 --- a/core/shared/platform/include/platform_common.h +++ b/core/shared/platform/include/platform_common.h @@ -193,6 +193,10 @@ typedef void *(*thread_start_routine_t)(void *); #define SCNxPTR __PRIPTR_PREFIX "x" #endif +#ifndef NAN +#define NAN (0.0 / 0.0) +#endif + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/zephyr/platform_internal.h b/core/shared/platform/zephyr/platform_internal.h index f4683d93..d2a94e4a 100644 --- a/core/shared/platform/zephyr/platform_internal.h +++ b/core/shared/platform/zephyr/platform_internal.h @@ -7,14 +7,21 @@ #define _PLATFORM_INTERNAL_H #include +#include + +#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */ #include #include -#include #if KERNEL_VERSION_NUMBER >= 0x020200 /* version 2.2.0 */ #include #else #include #endif +#else /* else of KERNEL_VERSION_NUMBER < 0x030200 */ +#include +#include +#endif /* end of KERNEL_VERSION_NUMBER < 0x030200 */ + #include #include #include @@ -24,9 +31,12 @@ #include #include #include + #ifndef CONFIG_NET_BUF_USER_DATA_SIZE #define CONFIG_NET_BUF_USER_DATA_SIZE 0 #endif + +#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */ #include #include #include @@ -36,6 +46,17 @@ #ifdef CONFIG_ARM_MPU #include #endif +#else /* else of KERNEL_VERSION_NUMBER < 0x030200 */ +#include +#include +#include +#include +#include + +#ifdef CONFIG_ARM_MPU +#include +#endif +#endif /* end of KERNEL_VERSION_NUMBER < 0x030200 */ #ifndef BH_PLATFORM_ZEPHYR #define BH_PLATFORM_ZEPHYR @@ -96,6 +117,11 @@ double strtod(const char *nptr, char **endptr); float strtof(const char *nptr, char **endptr); /* clang-format on */ +#if KERNEL_VERSION_NUMBER >= 0x030100 /* version 3.1.0 */ +#define BH_HAS_SQRT +#define BH_HAS_SQRTF +#endif + /** * @brief Allocate executable memroy * diff --git a/product-mini/platforms/zephyr/simple/CMakeLists.txt b/product-mini/platforms/zephyr/simple/CMakeLists.txt index 072ab943..8b2af15e 100644 --- a/product-mini/platforms/zephyr/simple/CMakeLists.txt +++ b/product-mini/platforms/zephyr/simple/CMakeLists.txt @@ -42,12 +42,12 @@ endif () # Override the global heap usage if (NOT DEFINED WAMR_BUILD_GLOBAL_HEAP_POOL) - add_definitions (-DWASM_ENABLE_GLOBAL_HEAP_POOL=1) + set (WAMR_BUILD_GLOBAL_HEAP_POOL 1) endif () # Override the global heap size for small devices if (NOT DEFINED WAMR_BUILD_GLOBAL_HEAP_SIZE) - add_definitions (-DWASM_GLOBAL_HEAP_SIZE=131072) # 128 kB + set (WAMR_BUILD_GLOBAL_HEAP_SIZE 131072) # 128 KB endif () set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) diff --git a/product-mini/platforms/zephyr/simple/src/main.c b/product-mini/platforms/zephyr/simple/src/main.c index 139475f6..8799e737 100644 --- a/product-mini/platforms/zephyr/simple/src/main.c +++ b/product-mini/platforms/zephyr/simple/src/main.c @@ -15,9 +15,6 @@ #include "test_wasm.h" #endif /* end of BUILD_TARGET_RISCV64_LP64 || BUILD_TARGET_RISCV32_ILP32 */ -#include -#include - #if defined(BUILD_TARGET_RISCV64_LP64) || defined(BUILD_TARGET_RISCV32_ILP32) #if defined(BUILD_TARGET_RISCV64_LP64) #define CONFIG_GLOBAL_HEAP_BUF_SIZE 4360