-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
zdsp: macros-based utilities #79457
zdsp: macros-based utilities #79457
Conversation
include/zephyr/sys/util.h
Outdated
* @param omin The minimum value of the output range. | ||
* @param omax The maximum value of the output range. | ||
*/ | ||
#define MAP_VALUE(i, imin, imax, omin, omax) \ |
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.
MAP may be a non optimal fit here, since maps map any input to any output, possibly in both directions, and even mapping 1 to many values :)
0 -> 100
3 -> 67
5 -> 45
7 -> (3, 5)
...
while scaling "linearly" maps an input to an output, you even hint at this in the brief :)
#define SCALE_VALUE(...)
would be better fitting IMO.
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.
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.
Please add a unit test to validate the macros :)
Since it is to be included right next to a CMSIS-based library, it makes sense that it gives the exact same results... I am still working on the |
This permits to make a computation in a larger range to gain precision: int32_t tmp_in = SCALE(in, -100, 100, INT32_MIN, INT32_MAX); Or convert between two unit systems: uint32_t fahrenheit = SCALE(celsius, 0, 100, 32, 212); Signed-off-by: Josuah Demangeon <[email protected]>
ecdb2bb
to
30b1107
Compare
Force-push:
|
6172d10
to
767d1ee
Compare
Saturation logic is supported, but not rounding. This helps as a support for inputting literal values: q15_t first = Q15f(0.23); This permits to store Q values in consts expressions: #define VAL(x) SUBq7(Q7f(1.0), Q7f(x / M_PI)) const q7_t table[] = { VAL(1.32), VAL(1.42), VAL(0.8) }; This permits to use fixed point arithmetics when a zdsp back-end is not available, such as light computation in drivers subitted upstream. Signed-off-by: Josuah Demangeon <[email protected]>
Force-push:
|
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
I still wish to build some C "fallback" back-end for ZDSP (i.e. for RISC-V) and other utilities, and would pick-up this PR again when having more time for it. |
This adds a macro implementation of basic fixed-point operations.
The short-term goal was to implement this:
This could be interesting for implementing drivers that feature some light computation on scalars, for which a DSP library would be an overkill, and which might not be available in all platforms the driver covers.
This also helps with the current DSP libraries by being usable in
const
expressions, i.e. initialize tables of data:Or be intervleaved with the current ZDSP library
Unsolved questions:
Q15_ADD
is more verbose.MAP_VALUE()
Todo: