Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpu/arm7_common/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ FEATURES_PROVIDED += arch_32bit
FEATURES_PROVIDED += arch_arm
FEATURES_PROVIDED += arch_arm7
FEATURES_PROVIDED += cpp
FEATURES_PROVIDED += float_math
FEATURES_PROVIDED += libstdcpp
FEATURES_PROVIDED += newlib
FEATURES_PROVIDED += periph_pm
Expand Down
6 changes: 4 additions & 2 deletions cpu/atmega_common/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ include $(RIOTCPU)/avr8_common/Makefile.features
# common feature are defined in avr8_common/Makefile.features
# Only add Additional features

FEATURES_PROVIDED += cpu_core_atmega
FEATURES_PROVIDED += atmega_pcint0
FEATURES_PROVIDED += cpu_core_atmega
FEATURES_PROVIDED += float_math
FEATURES_PROVIDED += periph_eeprom
FEATURES_PROVIDED += periph_gpio periph_gpio_irq
FEATURES_PROVIDED += periph_gpio_ll
FEATURES_PROVIDED += periph_gpio_ll_input_pull_up
FEATURES_PROVIDED += periph_gpio_ll_irq
FEATURES_PROVIDED += periph_gpio_ll_irq_edge_triggered_both
FEATURES_PROVIDED += periph_gpio_ll_irq_level_triggered_low
FEATURES_PROVIDED += periph_gpio_ll_irq_unmask
FEATURES_PROVIDED += periph_gpio_ll_switch_dir
FEATURES_PROVIDED += periph_gpio
FEATURES_PROVIDED += periph_gpio_irq
FEATURES_PROVIDED += periph_pm
FEATURES_PROVIDED += periph_rtc_ms
FEATURES_PROVIDED += periph_rtt_overflow
Expand Down
1 change: 1 addition & 0 deletions cpu/cortexm_common/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FEATURES_PROVIDED += cpp
FEATURES_PROVIDED += cpu_check_address
FEATURES_PROVIDED += cpu_core_cortexm
FEATURES_PROVIDED += dbgpin
FEATURES_PROVIDED += float_math
FEATURES_PROVIDED += libstdcpp
FEATURES_PROVIDED += newlib
FEATURES_PROVIDED += periph_flashpage_aux
Expand Down
1 change: 1 addition & 0 deletions cpu/esp_common/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ FEATURES_PROVIDED += arch_32bit
FEATURES_PROVIDED += arch_esp
FEATURES_PROVIDED += cpp
FEATURES_PROVIDED += esp_spiffs
FEATURES_PROVIDED += float_math
FEATURES_PROVIDED += libstdcpp
FEATURES_PROVIDED += newlib
FEATURES_PROVIDED += periph_cpuid
Expand Down
6 changes: 3 additions & 3 deletions cpu/msp430/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ FEATURES_PROVIDED += arch_msp430
FEATURES_PROVIDED += bug_newlib_broken_stdio
FEATURES_PROVIDED += cpu_$(CPU_FAM)
FEATURES_PROVIDED += dbgpin
FEATURES_PROVIDED += float_math
FEATURES_PROVIDED += newlib
FEATURES_PROVIDED += periph_flashpage
FEATURES_PROVIDED += periph_flashpage_in_address_space
FEATURES_PROVIDED += periph_flashpage_pagewise
FEATURES_PROVIDED += periph_pm
FEATURES_PROVIDED += periph_timer_query_freqs

FEATURES_PROVIDED += periph_gpio_ll
FEATURES_PROVIDED += periph_gpio_ll_irq
FEATURES_PROVIDED += periph_gpio_ll_switch_dir
FEATURES_PROVIDED += periph_pm
FEATURES_PROVIDED += periph_timer_query_freqs
19 changes: 19 additions & 0 deletions cpu/native/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,22 @@ ifeq ($(USE_LIBUCONTEXT),1)
CFLAGS += $(pkg-config libucontext --cflags) -DUSE_LIBUCONTEXT=1
LINKFLAGS += $(shell pkg-config libucontext --libs)
endif

ifeq (x86_64,$(OS_ARCH))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we also need that on 32 bit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I wonder if someone actually still has an i585/i686 CPU in use these days.

It won't hurt to add the check, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more about testing the code on a 32 bit target which is what most of our targets are.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the output of uname -m would still be x86_64, even with BOARD=native32.

But I honestly don't really see a path forward here with including C++ headers resulting in compilation errors when SSE is disabled.

Copy link
Contributor

@benpicco benpicco Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I thought OS_ARCH was referring to RIOT 😅

# Disable use of FPU/SSE registers if FPU is not used. This prevents radom
# stack corruptions and floating point exceptions to not occur during
# context switching.
ifeq (,$(filter float_math,$(FEATURES_USED)))
# FPU/SSE registers are not reliably saved and restored in glibc's ucontext
# implementation (see https://github.com/RIOT-OS/RIOT/issues/495) and not at
# all in libucontext's (but there at least this is documented). So we force
# the compiler to only use registers known to be properly backed up and
# restored during context switching
CFLAGS += -mgeneral-regs-only

# Since we disabled the use of non-general registers (such as FPU registers),
# we need to use a soft FPU
CFLAGS += -msoft-float
LINKFLAGS += -msoft-float
endif
endif
1 change: 1 addition & 0 deletions cpu/riscv_common/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FEATURES_PROVIDED += arch_32bit
FEATURES_PROVIDED += arch_riscv
FEATURES_PROVIDED += bug_newlib_broken_stdio
FEATURES_PROVIDED += cpp
FEATURES_PROVIDED += float_math
FEATURES_PROVIDED += libstdcpp
FEATURES_PROVIDED += newlib
FEATURES_PROVIDED += periph_coretimer
Expand Down
1 change: 1 addition & 0 deletions drivers/adt7310/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
FEATURES_REQUIRED += float_math
FEATURES_REQUIRED += periph_spi
1 change: 1 addition & 0 deletions drivers/apds99xx/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FEATURES_REQUIRED += float_math
FEATURES_REQUIRED += periph_i2c

ifneq (,$(filter apds99%full,$(USEMODULE)))
Expand Down
4 changes: 3 additions & 1 deletion drivers/at30tse75x/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
USEMODULE += ztimer_usec
FEATURES_REQUIRED += float_math
FEATURES_REQUIRED += periph_i2c

USEMODULE += ztimer_usec
1 change: 1 addition & 0 deletions drivers/bme680/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FEATURES_REQUIRED += float_math
USEPKG += driver_bme680

ifneq (,$(filter saul%,$(USEMODULE)))
Expand Down
1 change: 1 addition & 0 deletions drivers/bmp180/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FEATURES_REQUIRED += float_math
FEATURES_REQUIRED += periph_i2c
USEMODULE += ztimer
USEMODULE += ztimer_msec
1 change: 1 addition & 0 deletions drivers/ccs811/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FEATURES_REQUIRED += float_math
FEATURES_REQUIRED += periph_gpio
FEATURES_REQUIRED += periph_i2c
USEMODULE += ztimer
Expand Down
4 changes: 3 additions & 1 deletion drivers/io1_xplained/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FEATURES_REQUIRED += periph_gpio
FEATURES_REQUIRED += float_math
FEATURES_REQUIRED += periph_adc
FEATURES_REQUIRED += periph_gpio

USEMODULE += at30tse75x
USEMODULE += sdcard_spi
1 change: 1 addition & 0 deletions drivers/isl29125/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
FEATURES_REQUIRED += float_math
FEATURES_REQUIRED += periph_gpio_irq
FEATURES_REQUIRED += periph_i2c
1 change: 1 addition & 0 deletions drivers/kw41zrf/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FEATURES_REQUIRED += float_math
USEMODULE += ieee802154
USEMODULE += netdev_ieee802154
USEMODULE += netdev_legacy_api
Expand Down
1 change: 1 addition & 0 deletions drivers/scd30/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FEATURES_REQUIRED += float_math
FEATURES_REQUIRED += periph_i2c
USEMODULE += checksum
USEMODULE += xtimer
1 change: 1 addition & 0 deletions drivers/sps30/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
FEATURES_REQUIRED += float_math
FEATURES_REQUIRED += periph_i2c
USEMODULE += checksum
1 change: 1 addition & 0 deletions drivers/sx127x/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FEATURES_REQUIRED += float_math
FEATURES_REQUIRED += periph_gpio
FEATURES_REQUIRED += periph_gpio_irq
FEATURES_REQUIRED += periph_spi
Expand Down
3 changes: 3 additions & 0 deletions drivers/sx1280/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
FEATURES_REQUIRED += float_math

USEPKG += lorabasics

USEMODULE += lorabasics_sx1280_driver
USEMODULE += netdev_legacy_api
1 change: 1 addition & 0 deletions drivers/tmp00x/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
FEATURES_REQUIRED += float_math
FEATURES_REQUIRED += periph_i2c
USEMODULE += xtimer
2 changes: 2 additions & 0 deletions examples/lang_support/official/riot_and_cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ DEVELHELP ?= 1
# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

USEMODULE += printf_float

# Features required
FEATURES_REQUIRED += cpp # basic C++ support
FEATURES_REQUIRED += libstdcpp # libstdc++ support (for #include <cstdio>)
Expand Down
3 changes: 3 additions & 0 deletions examples/networking/misc/spectrum-scanner/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ BOARD ?= samr21-xpro
# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../../../..

# Needed for print_float()
FEATURES_REQUIRED += float_math

# Define modules that are used
USEMODULE += gnrc
USEMODULE += netdev_default
Expand Down
3 changes: 3 additions & 0 deletions features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ groups:
a mandatory requirement to build Rust code.
- name: emulator_renode
help: The platform is compatible with the Renode emulator.
- name: float_math
help: The use of float point math is possible. This requires either a
hardware FPU or a working software FPU.

- title: Peripheral Features
help: These features indicate presence of peripheral IP block, presence of
Expand Down
1 change: 1 addition & 0 deletions makefiles/features_existing.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ FEATURES_EXISTING := \
esp_wifi_ap \
esp_wifi_enterprise \
feather_shield \
float_math \
gecko_sdk_librail_fpu \
gecko_sdk_librail_nonfpu \
highlevel_stdio \
Expand Down
3 changes: 3 additions & 0 deletions makefiles/features_modules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ USEMODULE += $(filter vdd_lc_filter_%,$(FEATURES_USED))
# select arduino_pwm pseudomodule if the corresponding feature is used
USEMODULE += $(filter arduino_pwm, $(FEATURES_USED))

# select float_math pseudomodule when corresponding feature is used
USEMODULE += $(filter float_math, $(FEATURES_USED))

# always register a peripheral driver as a required feature when the corresponding
# module is requested
PERIPH_IGNORE_MODULES += periph_usbdev_clk periph_gpio_mock periph_gpio_linux periph_spidev_linux
Expand Down
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ PSEUDOMODULES += event_timeout_ztimer
PSEUDOMODULES += evtimer_mbox
PSEUDOMODULES += fatfs_vfs_format
PSEUDOMODULES += fdcan
PSEUDOMODULES += float_math
PSEUDOMODULES += fmt_%
PSEUDOMODULES += gcoap_forward_proxy
PSEUDOMODULES += gcoap_forward_proxy_thread
Expand Down
1 change: 1 addition & 0 deletions pkg/cayenne-lpp/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FEATURES_REQUIRED += float_math
2 changes: 2 additions & 0 deletions pkg/ccn-lite/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FEATURES_REQUIRED += float_math

USEMODULE += ccn-lite-utils
USEMODULE += gnrc_nettype_ccn
USEMODULE += evtimer
Expand Down
2 changes: 2 additions & 0 deletions pkg/cn-cbor/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FEATURES_REQUIRED += float_math

USEMODULE += posix_headers

# CN-CBOR is only supported by 32 bit architectures
Expand Down
2 changes: 2 additions & 0 deletions pkg/emlearn/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
FEATURES_REQUIRED += float_math

# emlearn is not compatible with MSP430
FEATURES_BLACKLIST += arch_msp430
2 changes: 2 additions & 0 deletions pkg/flatbuffers/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
FEATURES_REQUIRED += float_math

USEMODULE += cpp11-compat
2 changes: 2 additions & 0 deletions pkg/jerryscript/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FEATURES_REQUIRED += float_math

USEMODULE += jerryscript-port-default
USEMODULE += jerryscript-ext

Expand Down
2 changes: 2 additions & 0 deletions pkg/libfixmath/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FEATURES_REQUIRED += float_math

ifneq (,$(filter libfixmath-unittests,$(USEMODULE)))
# libfixmath unittests use shift operand incompatible with 8bit
# architecture int type.
Expand Down
2 changes: 2 additions & 0 deletions pkg/libschc/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FEATURES_REQUIRED += float_math

ifneq (,$(filter libschc_%,$(USEMODULE)))
USEPKG += libschc
endif
Expand Down
1 change: 1 addition & 0 deletions pkg/lora-serialization/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FEATURES_REQUIRED += float_math
2 changes: 2 additions & 0 deletions pkg/lvgl/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FEATURES_REQUIRED += float_math

USEMODULE += lvgl
USEMODULE += lvgl_core
USEMODULE += lvgl_draw
Expand Down
2 changes: 2 additions & 0 deletions pkg/micropython/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FEATURES_REQUIRED += float_math

USEMODULE += xtimer
USEMODULE += stdin

Expand Down
1 change: 1 addition & 0 deletions pkg/minmea/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FEATURES_REQUIRED += float_math
1 change: 1 addition & 0 deletions pkg/mjson/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FEATURES_REQUIRED += float_math
1 change: 1 addition & 0 deletions pkg/nanocbor/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FEATURES_OPTIONAL += float_math
5 changes: 5 additions & 0 deletions pkg/nanocbor/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
INCLUDES += -I$(RIOTPKG)/nanocbor/include
INCLUDES += -I$(PKGDIRBASE)/nanocbor/include

# Disable float functions if no float support is available
ifneq (,$(filter float_math,$(FEATURES_USED)))
CFLAGS += -DNANOCBOR_ENABLE_FLOAT=0
endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
From e29136bb10b7d763d633341e213112759c6893a0 Mon Sep 17 00:00:00 2001
From: Marian Buschsieweke <marian.buschsieweke@ml-pa.com>
Date: Wed, 17 Sep 2025 21:36:01 +0200
Subject: [PATCH] config: Allow disabling of float arithmitc

This can be useful for toolchains that cannot compile with any float
arithmetic included. Otherwise with -ffunction-sections the linker would
garbage collect unused float support anyway.
---
examples/pretty-printer/main.c | 4 ++++
include/nanocbor/config.h | 7 +++++++
src/decoder.c | 2 ++
src/encoder.c | 3 +++
4 files changed, 16 insertions(+)

diff --git a/examples/pretty-printer/main.c b/examples/pretty-printer/main.c
index 9508ecf..1811f0a 100644
--- a/examples/pretty-printer/main.c
+++ b/examples/pretty-printer/main.c
@@ -144,6 +144,7 @@ static int _print_enter_array(nanocbor_value_t *value, unsigned indent)
return -1;
}

+#if NANOCBOR_ENABLE_FLOAT
static int _print_float(nanocbor_value_t *value)
{
bool test = false;
@@ -173,6 +174,7 @@ static int _print_float(nanocbor_value_t *value)
}
return 0;
}
+#endif /* NANOCBOR_ENABLE_FLOAT */

/* NOLINTNEXTLINE(misc-no-recursion, readability-function-cognitive-complexity) */
static int _parse_type(nanocbor_value_t *value, unsigned indent)
@@ -228,9 +230,11 @@ static int _parse_type(nanocbor_value_t *value, unsigned indent)
case NANOCBOR_TYPE_MAP: {
res = _print_enter_map(value, indent);
} break;
+#if NANOCBOR_ENABLE_FLOAT
case NANOCBOR_TYPE_FLOAT: {
res = _print_float(value);
} break;
+#endif /* NANOCBOR_ENABLE_FLOAT */
case NANOCBOR_TYPE_TAG: {
uint32_t tag = 0;
int res = nanocbor_get_tag(value, &tag);
diff --git a/include/nanocbor/config.h b/include/nanocbor/config.h
index a9e5463..bf4e135 100644
--- a/include/nanocbor/config.h
+++ b/include/nanocbor/config.h
@@ -79,6 +79,13 @@ extern "C" {
#endif
#endif

+/**
+ * @brief enable/disable support for float/double values
+ */
+#ifndef NANOCBOR_ENABLE_FLOAT
+#define NANOCBOR_ENABLE_FLOAT 1
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/src/decoder.c b/src/decoder.c
index 5820659..4a59e01 100644
--- a/src/decoder.c
+++ b/src/decoder.c
@@ -368,6 +368,7 @@ int nanocbor_get_simple(nanocbor_value_t *cvalue, uint8_t *value)
return res;
}

+#if NANOCBOR_ENABLE_FLOAT
/* float bit mask related defines */
#define FLOAT_EXP_OFFSET (127U)
#define FLOAT_SIZE (32U)
@@ -475,6 +476,7 @@ int nanocbor_get_double(nanocbor_value_t *cvalue, double *value)
}
return _decode_double(cvalue, value);
}
+#endif /* NANOCBOR_ENABLE_FLOAT */

static int _enter_container(const nanocbor_value_t *it,
nanocbor_value_t *container, uint8_t type)
diff --git a/src/encoder.c b/src/encoder.c
index ec0a4f6..c548fbd 100644
--- a/src/encoder.c
+++ b/src/encoder.c
@@ -230,6 +230,8 @@ int nanocbor_fmt_null(nanocbor_encoder_t *enc)
return _fmt_single(enc, NANOCBOR_MASK_FLOAT | NANOCBOR_SIMPLE_NULL);
}

+#if NANOCBOR_TYPE_FLOAT
+
/* Double bit mask related defines */
#define DOUBLE_EXP_OFFSET (1023U)
#define DOUBLE_SIZE (64U)
@@ -393,6 +395,7 @@ int nanocbor_fmt_double(nanocbor_encoder_t *enc, double num)
return res;
#endif
}
+#endif /* NANOCBOR_TYPE_FLOAT */

int nanocbor_fmt_decimal_frac(nanocbor_encoder_t *enc, int32_t e, int32_t m)
{
--
2.43.0

Loading
Loading