-
Notifications
You must be signed in to change notification settings - Fork 2.1k
build system: add float_math feature to indicate support of floating point arithmetic #21727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
maribu
wants to merge
8
commits into
RIOT-OS:master
Choose a base branch
from
maribu:features-float
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
16e2506
build system: Add float_math feature
maribu 1a9a192
drivers: require float_math feature where needed
maribu 4b12599
sys: require float_math feature where needed
maribu fc3a860
tests: require float_math where needed
maribu b5d904e
sys/phydat: avoid use of pow()
maribu 73f4160
pkg: require float_math where needed
maribu f2efe72
examples: require float_math where needed
maribu 56be5ab
cpu/native: fix FPU/SSE register related context switching issues
maribu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
FEATURES_REQUIRED += float_math | ||
FEATURES_REQUIRED += periph_spi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
FEATURES_REQUIRED += float_math | ||
FEATURES_REQUIRED += periph_i2c | ||
USEMODULE += checksum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
FEATURES_REQUIRED += float_math | ||
FEATURES_REQUIRED += periph_i2c | ||
USEMODULE += xtimer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FEATURES_REQUIRED += float_math |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
FEATURES_REQUIRED += float_math | ||
|
||
USEMODULE += cpp11-compat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FEATURES_REQUIRED += float_math |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
FEATURES_REQUIRED += float_math | ||
|
||
USEMODULE += xtimer | ||
USEMODULE += stdin | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FEATURES_REQUIRED += float_math |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FEATURES_REQUIRED += float_math |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FEATURES_OPTIONAL += float_math |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
109 changes: 109 additions & 0 deletions
109
pkg/nanocbor/patches/0001-config-Allow-disabling-of-float-arithmitc.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 bex86_64
, even withBOARD=native32
.But I honestly don't really see a path forward here with including C++ headers resulting in compilation errors when SSE is disabled.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 😅