py/dynruntime: Add support for float API to make/get floats.
We don't want to add a feature flag to .mpy files that indicate float support because it will get complex and difficult to use. Instead the .mpy is built using whatever precision it chooses (float or double) and the native glue API will convert between this choice and what the host runtime actually uses.
This commit is contained in:
parent
ff58961944
commit
abc642973d
@ -190,4 +190,20 @@ static inline void mp_raise_OSError_dyn(int er) {
|
|||||||
nlr_raise(mp_call_function_n_kw(mp_load_global(MP_QSTR_OSError), 1, 0, &args[0]));
|
nlr_raise(mp_call_function_n_kw(mp_load_global(MP_QSTR_OSError), 1, 0, &args[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
// Floating point
|
||||||
|
|
||||||
|
#define mp_obj_new_float_from_f(f) (mp_fun_table.obj_new_float_from_f((f)))
|
||||||
|
#define mp_obj_new_float_from_d(d) (mp_fun_table.obj_new_float_from_d((d)))
|
||||||
|
#define mp_obj_get_float_to_f(o) (mp_fun_table.obj_get_float_to_f((o)))
|
||||||
|
#define mp_obj_get_float_to_d(o) (mp_fun_table.obj_get_float_to_d((o)))
|
||||||
|
|
||||||
|
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
|
||||||
|
#define mp_obj_new_float(f) (mp_obj_new_float_from_f((f)))
|
||||||
|
#define mp_obj_get_float(o) (mp_obj_get_float_to_f((o)))
|
||||||
|
#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
|
||||||
|
#define mp_obj_new_float(f) (mp_obj_new_float_from_d((f)))
|
||||||
|
#define mp_obj_get_float(o) (mp_obj_get_float_to_d((o)))
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_PY_DYNRUNTIME_H
|
#endif // MICROPY_INCLUDED_PY_DYNRUNTIME_H
|
||||||
|
@ -46,6 +46,7 @@ ifeq ($(ARCH),x86)
|
|||||||
CROSS =
|
CROSS =
|
||||||
CFLAGS += -m32 -fno-stack-protector
|
CFLAGS += -m32 -fno-stack-protector
|
||||||
MPY_CROSS_FLAGS += -mcache-lookup-bc
|
MPY_CROSS_FLAGS += -mcache-lookup-bc
|
||||||
|
MICROPY_FLOAT_IMPL ?= double
|
||||||
|
|
||||||
else ifeq ($(ARCH),x64)
|
else ifeq ($(ARCH),x64)
|
||||||
|
|
||||||
@ -53,12 +54,14 @@ else ifeq ($(ARCH),x64)
|
|||||||
CROSS =
|
CROSS =
|
||||||
CFLAGS += -fno-stack-protector
|
CFLAGS += -fno-stack-protector
|
||||||
MPY_CROSS_FLAGS += -mcache-lookup-bc
|
MPY_CROSS_FLAGS += -mcache-lookup-bc
|
||||||
|
MICROPY_FLOAT_IMPL ?= double
|
||||||
|
|
||||||
else ifeq ($(ARCH),armv7m)
|
else ifeq ($(ARCH),armv7m)
|
||||||
|
|
||||||
# thumb
|
# thumb
|
||||||
CROSS = arm-none-eabi-
|
CROSS = arm-none-eabi-
|
||||||
CFLAGS += -mthumb -mcpu=cortex-m3
|
CFLAGS += -mthumb -mcpu=cortex-m3
|
||||||
|
MICROPY_FLOAT_IMPL ?= none
|
||||||
|
|
||||||
else ifeq ($(ARCH),armv7emsp)
|
else ifeq ($(ARCH),armv7emsp)
|
||||||
|
|
||||||
@ -66,6 +69,7 @@ else ifeq ($(ARCH),armv7emsp)
|
|||||||
CROSS = arm-none-eabi-
|
CROSS = arm-none-eabi-
|
||||||
CFLAGS += -mthumb -mcpu=cortex-m4
|
CFLAGS += -mthumb -mcpu=cortex-m4
|
||||||
CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
||||||
|
MICROPY_FLOAT_IMPL ?= float
|
||||||
|
|
||||||
else ifeq ($(ARCH),armv7emdp)
|
else ifeq ($(ARCH),armv7emdp)
|
||||||
|
|
||||||
@ -73,23 +77,29 @@ else ifeq ($(ARCH),armv7emdp)
|
|||||||
CROSS = arm-none-eabi-
|
CROSS = arm-none-eabi-
|
||||||
CFLAGS += -mthumb -mcpu=cortex-m7
|
CFLAGS += -mthumb -mcpu=cortex-m7
|
||||||
CFLAGS += -mfpu=fpv5-d16 -mfloat-abi=hard
|
CFLAGS += -mfpu=fpv5-d16 -mfloat-abi=hard
|
||||||
|
MICROPY_FLOAT_IMPL ?= double
|
||||||
|
|
||||||
else ifeq ($(ARCH),xtensa)
|
else ifeq ($(ARCH),xtensa)
|
||||||
|
|
||||||
# xtensa
|
# xtensa
|
||||||
CROSS = xtensa-lx106-elf-
|
CROSS = xtensa-lx106-elf-
|
||||||
CFLAGS += -mforce-l32
|
CFLAGS += -mforce-l32
|
||||||
|
MICROPY_FLOAT_IMPL ?= none
|
||||||
|
|
||||||
else ifeq ($(ARCH),xtensawin)
|
else ifeq ($(ARCH),xtensawin)
|
||||||
|
|
||||||
# xtensawin
|
# xtensawin
|
||||||
CROSS = xtensa-esp32-elf-
|
CROSS = xtensa-esp32-elf-
|
||||||
CFLAGS +=
|
CFLAGS +=
|
||||||
|
MICROPY_FLOAT_IMPL ?= float
|
||||||
|
|
||||||
else
|
else
|
||||||
$(error architecture '$(ARCH)' not supported)
|
$(error architecture '$(ARCH)' not supported)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
MICROPY_FLOAT_IMPL_UPPER = $(shell echo $(MICROPY_FLOAT_IMPL) | tr '[:lower:]' '[:upper:]')
|
||||||
|
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_$(MICROPY_FLOAT_IMPL_UPPER)
|
||||||
|
|
||||||
CFLAGS += $(CFLAGS_EXTRA)
|
CFLAGS += $(CFLAGS_EXTRA)
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -663,7 +663,7 @@ def link_objects(env, native_qstr_vals_len, native_qstr_objs_len):
|
|||||||
|
|
||||||
# Resolve unknown symbols
|
# Resolve unknown symbols
|
||||||
mp_fun_table_sec = Section('.external.mp_fun_table', b'', 0)
|
mp_fun_table_sec = Section('.external.mp_fun_table', b'', 0)
|
||||||
fun_table = {key: 63 + idx
|
fun_table = {key: 67 + idx
|
||||||
for idx, key in enumerate([
|
for idx, key in enumerate([
|
||||||
'mp_type_type',
|
'mp_type_type',
|
||||||
'mp_type_str',
|
'mp_type_str',
|
||||||
|
Loading…
Reference in New Issue
Block a user