-
Notifications
You must be signed in to change notification settings - Fork 2k
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
sys: add common imath module mv isin() form test/driver_dac_dds #19378
Conversation
bcd87e1
to
12488c2
Compare
0f6d400
to
a51e84c
Compare
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.
I stared at this for too long:
bike-shed:
-
some pre- or postfix for the function names that indicate that it is not only special for its type but also less accurate i think
fast_isin()
would be nice (like fast_sqrt (just realised we don't have that quake algorithm :) ). -
Q Notation needs to be explained https://en.wikipedia.org/wiki/Q_%28number_format%29
-
I think there should no be two ways for writing fractional binary number with N-Bit fraction in one piece of documentation (Q14 vs 2^^15)
-
define PI
-
ISIN_PERIOD is wrong
https://godbolt.org/z/edqv4T6YM
this get us both fast_isin and fast_icos (icos being smaller)
iPI = 0x8000>>1
static inline __attribute__((always_inline))
int32_t ihelp(int32_t x){
int32_t y;
static const int32_t qN = 13,
qA = 12,
B = 19900,
C = 3516;
x = x << (31 - qN); /* Mask with PI */
x = x >> (31 - qN); /* Note: SIGNED shift! (to qN) */
x = x * x >> (2 * qN - 14); /* x=x^2 To Q14 */
y = B - (x * C >> 14); /* B - x^2*C */
y = (1 << qA) /* A - x^2*(B-x^2*C) */
- (x * y >> 16);
return y;
}
//static inline
int32_t isin(int32_t x){
static const int32_t qN = 13;
int32_t c = (x << (30 - qN));
int32_t y = ihelp(x - (1 << qN));
return c >= 0 ? y :-y ;
}
//static inline
int32_t icos(int32_t x){
static const int32_t qN = 13;
// vvv this is most probalbly not the optimal way to write that
// but the compiler gets it
int32_t c = ((x + iPI/2) << (30 - qN));
int32_t y = ihelp(x);
return c >= 0 ? y :-y ;
}
so |
i checked with a scaled libm sin() and got a difference of upto 13 (12 with some prescaling) (so ~3-4 Bits may be not accurate) |
@kfessel asked me to join the bike shedding to untie the knot. My two cents are:
But to be honest, I'm not much a fan of bike shedding. I'm usually happy with whatever name the person investing the time and effort in PR picked for naming. IMO time is better spent on the implementation than on the naming of functions or data types. |
I'd prefer |
Ok, I think it looks more ugly now, but there is now consistency with |
bors merge |
🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set. |
19378: sys: add common imath module mv isin() form test/driver_dac_dds r=kfessel a=benpicco 19693: sys/color: extend unittest and fix module r=kfessel a=kfessel ### Contribution description this extends the unittest for sys_color testing more colors ### Testing procedure ``` RIOT_tree/tests/unittests$ make tests-color test ``` will fail since our `rgb2hsv` implementation is wrong (or is using an other colorspace than hsv2rgb (without documenting)) the new `hsv2rgb` test will succeed ### Issues/PRs references #19614 was the reason i had a look at this #1315 added the rgb2hsv and hsv2rgb function #9940 added the test for black special case https://www.vagrearg.org/content/hsvrgb << some optimization for that function (avoiding float) Co-authored-by: Benjamin Valentin <[email protected]> Co-authored-by: Karl Fessel <[email protected]>
Build failed (retrying...): |
19378: sys: add common imath module mv isin() form test/driver_dac_dds r=kfessel a=benpicco Co-authored-by: Benjamin Valentin <[email protected]>
bors cancel |
Canceled. |
bors cancel |
bors merge |
19378: sys: add common imath module mv isin() form test/driver_dac_dds r=maribu a=benpicco 19693: sys/color: extend unittest and fix module r=kfessel a=kfessel ### Contribution description this extends the unittest for sys_color testing more colors ### Testing procedure ``` RIOT_tree/tests/unittests$ make tests-color test ``` will fail since our `rgb2hsv` implementation is wrong (or is using an other colorspace than hsv2rgb (without documenting)) the new `hsv2rgb` test will succeed ### Issues/PRs references #19614 was the reason i had a look at this #1315 added the rgb2hsv and hsv2rgb function #9940 added the test for black special case https://www.vagrearg.org/content/hsvrgb << some optimization for that function (avoiding float) Co-authored-by: Benjamin Valentin <[email protected]> Co-authored-by: Karl Fessel <[email protected]>
Build failed (retrying...): |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
Contribution description
An integer-only
sin()
function is generally useful, move it to a common placeimath
where more integer-only math functions can be added when needed.Testing procedure
This only moves code around.
Issues/PRs references