-
Notifications
You must be signed in to change notification settings - Fork 350
Math: Inline function sofm_lut_sin_fixed_16b() for performance #9798
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,53 @@ | |
|
|
||
| #include <stdint.h> | ||
|
|
||
| int16_t sofm_lut_sin_fixed_16b(int32_t w); /* Input is Q4.28, output is Q1.15 */ | ||
| #define SOFM_LUT_SINE_C_Q20 341782638 /* 2 * SINE_NQUART / pi in Q12.20 */ | ||
| #define SOFM_LUT_SINE_NQUART 512 /* Must be 2^N */ | ||
| #define SOFM_LUT_SINE_SIZE (SOFM_LUT_SINE_NQUART + 1) | ||
|
|
||
| extern const uint16_t sofm_lut_sine_table_s16[]; | ||
|
|
||
| /* Sine lookup table read */ | ||
| static inline int32_t sofm_sine_lookup_16b(int idx) | ||
| { | ||
| uint16_t s; | ||
| int i1; | ||
|
|
||
| i1 = idx & (2 * SOFM_LUT_SINE_NQUART - 1); | ||
| if (i1 > SOFM_LUT_SINE_NQUART) | ||
| i1 = 2 * SOFM_LUT_SINE_NQUART - i1; | ||
|
|
||
| s = sofm_lut_sine_table_s16[i1]; | ||
| if (idx > 2 * SOFM_LUT_SINE_NQUART) | ||
| return -((int32_t)s); | ||
|
|
||
| return (int32_t)s; | ||
| } | ||
|
|
||
| /** | ||
| * Compute fixed point sine with table lookup and interpolation | ||
| * @param w Input angle in radians Q4.28 | ||
| * @return Sine value Q1.15 | ||
| */ | ||
| static inline int16_t sofm_lut_sin_fixed_16b(int32_t w) | ||
| { | ||
| int64_t idx; | ||
| int32_t sine; | ||
| int32_t frac; | ||
| int32_t delta; | ||
| int32_t s0; | ||
| int32_t s1; | ||
| int64_t idx_tmp; | ||
|
|
||
| /* Q4.28 x Q12.20 -> Q16.48 --> Q16.31*/ | ||
| idx_tmp = ((int64_t)w * SOFM_LUT_SINE_C_Q20) >> 17; | ||
| idx = (idx_tmp >> 31); /* Shift to Q0 */ | ||
| frac = (int32_t)(idx_tmp - (idx << 31)); /* Get fraction Q1.31*/ | ||
| s0 = sofm_sine_lookup_16b(idx); /* Q1.16 */ | ||
| s1 = sofm_sine_lookup_16b(idx + 1); /* Q1.16 */ | ||
| delta = s1 - s0; /* Q1.16 */ | ||
| sine = s0 + q_mults_32x32(frac, delta, Q_SHIFT_BITS_64(31, 16, 16)); /* Q1.16 */ | ||
| return sat_int16((sine + 1) >> 1); /* Round to Q1.15 */ | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with this every call to |
||
|
|
||
| #endif /* __SOF_MATH_LUT_TRIG_H__ */ | ||
Uh oh!
There was an error while loading. Please reload this page.