-
Notifications
You must be signed in to change notification settings - Fork 358
Math: Replace exp() function with more accurate and fast version #9786
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
Merged
lgirdwood
merged 1 commit into
thesofproject:main
from
singalsu:add_new_taylor_approx_exp
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| /* SPDX-License-Identifier: BSD-3-Clause | ||
| * | ||
| * Copyright(c) 2022 Intel Corporation. All rights reserved. | ||
| * Copyright(c) 2022-2025 Intel Corporation. | ||
| * | ||
| * Author: Shriram Shastry <[email protected]> | ||
| * Seppo Ingalsuo <[email protected]> | ||
| * | ||
| */ | ||
| #ifndef __SOFM_EXP_FCN_H__ | ||
|
|
@@ -26,40 +27,40 @@ | |
|
|
||
| #endif | ||
|
|
||
| /* TODO: Is there a MCPS difference */ | ||
| #define USING_QCONVERT 1 | ||
| /* Q5.27 int32(round(log((2^31 - 1)/2^20) * 2^27)) */ | ||
| #define SOFM_EXP_FIXED_INPUT_MAX 1023359037 | ||
|
|
||
| #if USING_QCONVERT | ||
| /* Q8.24 int32(round((log((2^31 - 1)/2^20) * 20 / log(10)) * 2^24)) */ | ||
| #define SOFM_DB2LIN_INPUT_MAX 1111097957 | ||
|
|
||
| #include <sof/audio/format.h> | ||
| #define SOFM_EXP_FIXED_INPUT_MIN Q_CONVERT_FLOAT(-11.5, 27) /* Q5.27 */ | ||
| #define SOFM_EXP_FIXED_INPUT_MAX Q_CONVERT_FLOAT(7.6245, 27) /* Q5.27 */ | ||
| #define SOFM_EXP_TWO_Q27 Q_CONVERT_FLOAT(2.0, 27) /* Q5.27 */ | ||
| #define SOFM_EXP_MINUS_TWO_Q27 Q_CONVERT_FLOAT(-2.0, 27) /* Q5.27 */ | ||
| #define SOFM_EXP_ONE_Q20 Q_CONVERT_FLOAT(1.0, 20) /* Q12.20 */ | ||
| #define SOFM_EXP_MINUS_100_Q24 Q_CONVERT_FLOAT(-100.0, 24) /* Q8.24 */ | ||
| #define SOFM_EXP_LOG10_DIV20_Q27 Q_CONVERT_FLOAT(0.1151292546, 27) /* Q5.27 */ | ||
|
|
||
| #else | ||
|
|
||
| #define SOFM_EXP_FIXED_INPUT_MIN -1543503872 /* Q_CONVERT_FLOAT(-11.5, 27) */ | ||
| #define SOFM_EXP_FIXED_INPUT_MAX 1023343067 /* Q_CONVERT_FLOAT(7.6245, 27) */ | ||
| #define SOFM_EXP_TWO_Q27 268435456 /* Q_CONVERT_FLOAT(2.0, 27) */ | ||
| #define SOFM_EXP_MINUS_TWO_Q27 -268435456 /* Q_CONVERT_FLOAT(-2.0, 27) */ | ||
| #define SOFM_EXP_ONE_Q20 1048576 /* Q_CONVERT_FLOAT(1.0, 20) */ | ||
| #define SOFM_EXP_MINUS_100_Q24 -1677721600 /* Q_CONVERT_FLOAT(-100.0, 24) */ | ||
| #define SOFM_EXP_LOG10_DIV20_Q27 15452387 /* Q_CONVERT_FLOAT(0.1151292546, 27) */ | ||
| /** | ||
| * Calculates exponent function exp(x) = e^x with accurate and efficient technique that | ||
| * includes range reduction operations, approximation with Taylor series, and reconstruction | ||
| * operations to compensate the range reductions. | ||
| * @param x The input argument as Q4.28 from -8 to +8 | ||
| * @return The calculated e^x value as Q13.19 from 3.3546e-04 to 2981.0 | ||
| */ | ||
| int32_t sofm_exp_approx(int32_t x); | ||
|
|
||
| #endif | ||
| /** | ||
| * Calculated exponent function exp(x) = e^x by using sofm_exp_approx(). The input range for | ||
| * large arguments is internally reduced to -8 to +8 with rule exp(x) = exp(x/2) * exp(x/2) | ||
| * and reconstructed back. This function is essentially a wrapper for compatibility with | ||
| * existing usage of exp() function and Q-format choice. Note that the return value saturates | ||
| * to INT32_MAX with input arguments larger than 7.6246. | ||
| * @param x The input argument as Q5.27 from -16 to +16 | ||
| * @return The calculated e^x value as Q12.20 | ||
| */ | ||
| int32_t sofm_exp_fixed(int32_t x); | ||
|
|
||
| #define SOFM_EXP_BIT_MASK_LOW_Q27P5 0x0000000008000000 | ||
| #define SOFM_EXP_BIT_MASK_Q62P2 0x4000000000000000LL | ||
| #define SOFM_EXP_QUOTIENT_SCALE 0x40000000 | ||
| #define SOFM_EXP_TERMS_Q23P9 0x800000 | ||
| #define SOFM_EXP_LSHIFT_BITS 0x2000 | ||
|
|
||
| int32_t sofm_exp_int32(int32_t x); | ||
| int32_t sofm_exp_fixed(int32_t x); | ||
| /** | ||
| * Converts a decibels value to liner amplitude lin = 10^(db/20) value with optimized | ||
| * equation exp(db * log(10)/20). Note that due to range limitation of sofm_exp_fixed() | ||
| * the output saturates to maximum with about +66 dB input. | ||
| * @param db Decibels value in Q8.24 format, from -128 to +66.226 | ||
| * @return Linear value in Q12.20 format, from 3.9811e-07 to 2048 | ||
| */ | ||
| int32_t sofm_db2lin_fixed(int32_t db); | ||
|
|
||
| #endif /* __SOFM_EXP_FCN_H__ */ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.