[2.0.x] Use 'float' instead of 'double' maths#11178
[2.0.x] Use 'float' instead of 'double' maths#11178thinkyhead merged 4 commits intoMarlinFirmware:bugfix-2.0.xfrom ejtagle:misc-fixes
Conversation
|
A quick perusal shows there are still a fair few double literals in areas you modified, there are a lot everywhere else in Marlin but I thought I'd mention it as you updated those parts, I had the choice between disabling double literals in the compiler or going through Marlin and changing them all... I disabled double literals. |
|
@p3p : I know there are still doubles. Specifically in the serial.print() routines. I didn´t remove them because that would break inheritance from the Stream class. But, those functions aren´t used, so i hope the linker is able to remove them. If there is consensus, i can also remove all those functions 👍 |
|
Sorry, I said constant I meant literal, there are many |
|
Yes, i agree. Codebase is full of |
Basically, and converting all the values to Some MCUs might actually prefer |
|
Some of these changes look like they'd be worthwhile for |
|
@thinkyhead : There is no embedded MPU supporting hardware double precision floating point (except STM CortexM7, but we don´t support those boards). The other exception would be Raspberry Pi or a PC There are options to force GCC to use floats for everything, What i am mostly interested in, is the optimizations to the Delta kinematics... Probably 10% faster o maybe more... |
Marlin/src/core/macros.h
Outdated
There was a problem hiding this comment.
Since M_PI is now defined with f on the end, casting it might be redundant.
There was a problem hiding this comment.
RECIPROCAL is safer, but also a little slower. If we know the parameter won't ever be 0.0 then it's better to just use 1.0 / x.
There was a problem hiding this comment.
You are right here. That is why a review is always welcome !! 👍
Marlin/src/gcode/calibrate/G33.cpp
Outdated
There was a problem hiding this comment.
Is LROUND actually better here, since the return type is float?
There was a problem hiding this comment.
On AVR is does not matter. On ARM, round would force a conversion from double->float, and the parameter of round() is double, so it also forces a conversion from float->double
Marlin/src/module/delta.cpp
Outdated
There was a problem hiding this comment.
Ah, I see. These would definitely be faster.
|
(btw: the compilation is failing because the |
|
Marlin loves me. |
Co-Authored-By: ejtagle <ejtagle@hotmail.com>
|
The delta optimizations seem good to me! I've heard that it's more optimal on AVR to use |
|
@thinkyhead : And they gave you good advice. On AVR pointers are 16bit, requiring 2 registers to be passed by reference. floats are 32bits, so passing them by reference uses 2 registers, and passing them by value uses 4 registers. So passing by reference is 2x faster... |
-normalize `env` and `board` to lowercase naming convention -make board `name` follow descriptive convention -implement `-fsingle-precision-constant` compile optimization per MarlinFirmware#11178 (comment) -fix typo in 5DPRINT entry
-normalize `env` and `board` to lowercase naming convention -make board `name` follow descriptive convention -implement `-fsingle-precision-constant` compile optimization per MarlinFirmware#11178 (comment) -fix typo in 5DPRINT entry
-normalize `env` and `board` to lowercase naming convention. -make board `name` follow descriptive convention. -implement `-fsingle-precision-constant` compile optimization per #11178 (comment) -fix typo in 5DPRINT entry.
float). On 32bit CPUs, they don't. The extra precisiondoublecosts more time, and is unnecessary. (On FPU enabled 32bit-boards,doubleis not accelerated butfloatis.)sqrtf(because it's implemented in assembler). The same profiling showed that if multiplication is 1x, division is 2x, square root is 4x, so it makes sense to replace them.sqrtby division.