-
Notifications
You must be signed in to change notification settings - Fork 54
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
Compile option to process floating point values in single-precision, internally #84
Comments
I don't quite understand what you mean by:
If doubles are still to be used, what does this suggestion save you? |
At any rate, if someone were to create a PR generalizing the internal floating-point-value handling to not necessarily use doubles, but some |
doubles would only be used for passing floating point values to The screenshot shows the added functions for a CM0+ microcontroller, this will be similar for any ARM microcontroller without dp-FPU.
I will try to come up with a PR. |
Changing For testing I changed all Exponential formatting without |
Naturally, you would need to adapt this code. I tried to make the existing code kind-of-generic, so you should not have to change too much - but some changes will be needed.
Perhaps you could split the uses of the |
Go ahead, changing the handling of the I measured the clock cycles on a CM0+ without FPU (measured with timer running at CPU frequency), all compiled with -O3:
Interesting results, I will repeat them for a CM4 with FPU. I expect that the last variant should get significantly faster then. Also interesting:
|
Did you enable LTO, when compiling and when linking? I've not done so in the |
These are interesting stats! But actually, what are the "gcc nano specs"? And - what is a CM4? At any rate, I've merged my significant change (and the next version number will be 6.0.0), so you're welcome to resume to resume the PR work. Your argument is compelling :-) |
"gcc nano specs" refers to linking the newlib-nano standard library, which is the de facto used standard library for small microcontrollers (you have to explicitly enable floating point support for printf). It might be that newlib (no nano) has a faster printf thatn newlib-nano.. CM0 and CM4 refers to cortex m0 and cortex m4 microcontrollers, respectively. In this case I used an STM32G071 nucleo board and a STM32F407 discovery board. |
Any news? We have quite a bunch of changes on the develop branch, so that a new release should occur soon. Have you made progress on the single-precision floating point processing? |
@jrahlf : ping. |
I have not forgotten about this, but only made little further progress. If you don't want to keep this open we can close and re-open when I come up with a PR. The current macro used in the tests is not suitable to work with a float variant. I would not want to duplicate all floating point tests, the test macro should rather cut off when the precision of float ends. |
If I understand it correctly, the current version does not even need the 64-bit processing, as long as #if PRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL <= 9
typedef int_fast32_t fp_component;
#else
typedef int_fast64_t fp_component;
#endif I pushed the first version to jrahlf@b7e1f52 . Tests for float processing are not added yet. Basically all I just wasted 30min trying to rebase this sh#t onto develop. Now it won't compile, I am done for today. |
@jrahlf : Sorry about the difficulty in rebasing. Like I'd said earlier, there have been some significant changes - not functionality-wise, but code-arrangement wise - over the past few weeks which make it difficult. I'll see what you've done and should probably be able to adapt it. However - I believe you're misinterpreting what |
... Yes, so, it's what I expected you would write. Indeed, there's not that much to change beyond the typedef replacing double. Hope to get around to this within the next couple of days. |
The integral value of formerly But I see now, the fractional part is a bit more complicated. |
* Can now choose between using `double` and `float` internally, for floating-point work, using the `PRINTF_USE_DOUBLE_INTERNALLY` definition and corresponding CMake option. * Adjusted test suite to support the different choice of floating-point type: * Tests relevant both to `float` and `double`, but with different precisions, are adjusted with an `#if #else #endif` * Tests and test cases relevant only for `double` precision are not compiled at all when `float` is used. * Lots of new explicit conversions :-(
Please have a look at #116 and possibly try out the branch. |
* Can now choose between using `double` and `float` internally, for floating-point work, using the `PRINTF_USE_DOUBLE_INTERNALLY` definition and corresponding CMake option. * Adjusted test suite to support the different choice of floating-point type: * Tests relevant both to `float` and `double`, but with different precisions, are adjusted with an `#if #else #endif` * Tests and test cases relevant only for `double` precision are not compiled at all when `float` is used. * Lots of new explicit conversions :-(
So, I've neglected to resolve this... were you ok with the brach with the fix integrated? If you were, I'll merge it into the develop branch. |
@jrahlf : ping. Will try to merge this soon if you don't respond. |
* Can now choose between using `double` and `float` internally, for floating-point work, using the `PRINTF_USE_DOUBLE_INTERNALLY` definition and corresponding CMake option. * Adjusted test suite to support the different choice of floating-point type: * Tests relevant both to `float` and `double`, but with different precisions, are adjusted with an `#if #else #endif` * Tests and test cases relevant only for `double` precision are not compiled at all when `float` is used. * Lots of new explicit conversions :-(
* Can now choose between using `double` and `float` internally, for floating-point work, using the `PRINTF_USE_DOUBLE_INTERNALLY` definition and corresponding CMake option. * Adjusted test suite to support the different choice of floating-point type: * Tests relevant both to `float` and `double`, but with different precisions, are adjusted with an `#if #else #endif` * Tests and test cases relevant only for `double` precision are not compiled at all when `float` is used. * Lots of new explicit conversions :-(
* Can now choose between using `double` and `float` internally, for floating-point work, using the `PRINTF_USE_DOUBLE_INTERNALLY` definition and corresponding CMake option. * Adjusted test suite to support the different choice of floating-point type: * Tests relevant both to `float` and `double`, but with different precisions, are adjusted with an `#if #else #endif` * Tests and test cases relevant only for `double` precision are not compiled at all when `float` is used. * Lots of new explicit conversions :-(
* Can now choose between using `double` and `float` internally, for floating-point work, using the `PRINTF_USE_DOUBLE_INTERNALLY` definition and corresponding CMake option. * Adjusted test suite to support the different choice of floating-point type: * Tests relevant both to `float` and `double`, but with different precisions, are adjusted with an `#if #else #endif` * Tests and test cases relevant only for `double` precision are not compiled at all when `float` is used. * Lots of new explicit conversions :-(
* Can now choose between using `double` and `float` internally, for floating-point work, using the `PRINTF_USE_DOUBLE_INTERNALLY` definition and corresponding CMake option. * Adjusted test suite to support the different choice of floating-point type: * Tests relevant both to `float` and `double`, but with different precisions, are adjusted with an `#if #else #endif` * Tests and test cases relevant only for `double` precision are not compiled at all when `float` is used. * Lots of new explicit conversions :-(
* Can now choose between using `double` and `float` internally, for floating-point work, using the `PRINTF_USE_DOUBLE_INTERNALLY` definition and corresponding CMake option. * Adjusted test suite to support the different choice of floating-point type: * Tests relevant both to `float` and `double`, but with different precisions, are adjusted with an `#if #else #endif` * Tests and test cases relevant only for `double` precision are not compiled at all when `float` is used. * Lots of new explicit conversions :-(
* Can now choose between using `double` and `float` internally, for floating-point work, using the `PRINTF_USE_DOUBLE_INTERNALLY` definition and corresponding CMake option. * Adjusted test suite to support the different choice of floating-point type: * Tests relevant both to `float` and `double`, but with different precisions, are adjusted with an `#if #else #endif` * Tests and test cases relevant only for `double` precision are not compiled at all when `float` is used. * Lots of new explicit conversions :-(
Well... the merging might have fixed the internal float handling, but - some test cases are broken now, so we need to fix that. |
* Can now choose between using `double` and `float` internally, for floating-point work, using the `PRINTF_USE_DOUBLE_INTERNALLY` definition and corresponding CMake option. * Adjusted test suite to support the different choice of floating-point type: * Tests relevant both to `float` and `double`, but with different precisions, are adjusted with an `#if #else #endif` * Tests and test cases relevant only for `double` precision are not compiled at all when `float` is used. * Lots of new explicit conversions :-(
* Can now choose between using `double` and `float` internally, for floating-point work, using the `PRINTF_USE_DOUBLE_INTERNALLY` definition and corresponding CMake option. * Adjusted test suite to support the different choice of floating-point type: * Tests relevant both to `float` and `double`, but with different precisions, are adjusted with an `#if #else #endif` * Tests and test cases relevant only for `double` precision are not compiled at all when `float` is used. * Lots of new explicit conversions :-(
I have a project where I use single precision floats, but no doubles.
Problem is, that printf processes all floating point values as doubles, even if the caller is content with single precision formatting. On devices without double-FPU, this pulls in
__aeabi_dsub
,__aeabi_dmul
and the likes, which are several kilobytes large.My suggestion is to add a compile option so that floating point values are formatted with single precision.
The value would still be passed as a double to
printf
, which would then be converted to float.Some of the required functionality seems to be already there, via the
#if DBL_MANT_DIG == 24
define.The text was updated successfully, but these errors were encountered: