From 87099b57314f37e19f6551b0d575b620e1d29323 Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Thu, 24 Jul 2025 15:28:48 +0200 Subject: [PATCH] qemu/Makefile: Allow overriding floating point mode by boards. This commit lets board use a different floating point mode rather than the usual soft-float that was the original default for all QEMU-based boards. The configuration options are the same available in the "stm32" port. Boards can set "MICROPY_FLOAT_IMPL" to either "float", "double", or "none" to indicate which floating point mode they want, and optionally "SUPPORTS_HARDWARE_FP_SINGLE" or "SUPPORTS_HARDWARE_FP_DOUBLE" can be set to 1 to further indicate the hardware capabilities of the hardware floating point unit, if present. Signed-off-by: Alessandro Gatti --- ports/qemu/Makefile | 37 +++++++++++++++++++++++++++++++++---- ports/qemu/mpconfigport.h | 1 - 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/ports/qemu/Makefile b/ports/qemu/Makefile index fc1e557974..7784a266c3 100644 --- a/ports/qemu/Makefile +++ b/ports/qemu/Makefile @@ -36,6 +36,8 @@ MICROPY_HEAP_SIZE ?= 143360 FROZEN_MANIFEST ?= "require('unittest'); freeze('test-frzmpy', ('frozen_asm_rv32.py', 'frozen_const.py', 'frozen_viper.py', 'native_frozen_align.py'))" endif +MICROPY_FLOAT_IMPL ?= float + # include py core make definitions include $(TOP)/py/py.mk include $(TOP)/extmod/extmod.mk @@ -44,6 +46,20 @@ GIT_SUBMODULES += lib/berkeley-db-1.xx CFLAGS += -DMICROPY_HEAP_SIZE=$(MICROPY_HEAP_SIZE) +ifeq ($(MICROPY_FLOAT_IMPL),double) +CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_DOUBLE +else ifeq ($(MICROPY_FLOAT_IMPL),float) +CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_FLOAT -fsingle-precision-constant +else +CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_NONE +endif + +ifeq ($(SUPPORTS_HARDWARE_FP_SINGLE),1) +CFLAGS += -DMICROPY_HW_FPU=1 +else ifeq ($(SUPPORTS_HARDWARE_FP_DOUBLE),1) +CFLAGS += -DMICROPY_HW_FPU=1 +endif + ################################################################################ # ARM specific settings @@ -156,16 +172,29 @@ SRC_C += \ shared/runtime/stdout_helpers.c \ shared/runtime/sys_stdio_mphal.c \ -LIB_SRC_C += $(SRC_LIB_LIBM_C) -LIB_SRC_C += $(SRC_LIB_LIBM_SQRT_SW_C) +ifeq ($(MICROPY_FLOAT_IMPL),double) +LIBM_SRC_C += $(SRC_LIB_LIBM_DBL_C) +ifeq ($(SUPPORTS_HARDWARE_FP_DOUBLE),1) +LIBM_SRC_C += $(SRC_LIB_LIBM_DBL_SQRT_HW_C) +else +LIBM_SRC_C += $(SRC_LIB_LIBM_DBL_SQRT_SW_C) +endif +else +LIBM_SRC_C += $(SRC_LIB_LIBM_C) +ifeq ($(SUPPORTS_HARDWARE_FP_SINGLE),1) +LIBM_SRC_C += $(SRC_LIB_LIBM_SQRT_HW_C) +else +LIBM_SRC_C += $(SRC_LIB_LIBM_SQRT_SW_C) +endif +endif OBJ += $(PY_O) OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_BOARD_O)) -OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(LIBM_SRC_C:.c=.o)) # List of sources for qstr extraction -SRC_QSTR += $(SRC_C) $(LIB_SRC_C) +SRC_QSTR += $(SRC_C) $(LIBM_SRC_C) ################################################################################ # Main targets diff --git a/ports/qemu/mpconfigport.h b/ports/qemu/mpconfigport.h index 9c879f55df..6c6dd68535 100644 --- a/ports/qemu/mpconfigport.h +++ b/ports/qemu/mpconfigport.h @@ -51,7 +51,6 @@ #define MICROPY_ENABLE_GC (1) #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) -#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) #define MICROPY_WARNINGS (1) #define MICROPY_PY_SYS_PLATFORM "qemu" #define MICROPY_PY_SYS_STDIO_BUFFER (0)