Skip to content

math: Add logarithm base E and base 10 - #5074

Merged
cujomalainey merged 1 commit into
thesofproject:mainfrom
ShriramShastry:shastry_base_TE_log_dev
Feb 11, 2022
Merged

cujomalainey merged 1 commit into
thesofproject:mainfrom
ShriramShastry:shastry_base_TE_log_dev

Conversation

@ShriramShastry

@ShriramShastry ShriramShastry commented Dec 12, 2021 •

Copy link
Copy Markdown
Contributor

fixpoint math log() and log10() function. Logarithm
of x is the power to which e/10 would have to be raised
to equal x.

Implementation of log10(x) is a derivative of log2(x)/log2(10)
and loge(x) as log2(x)/log2(e)

Signed-off-by: Shriram Shastry malladi.sastry@intel.com

@ShriramShastry
ShriramShastry force-pushed the shastry_base_TE_log_dev branch 5 times, most recently from c4fd6b2 to aa9eeef Compare December 12, 2021 05:28
@ShriramShastry
ShriramShastry force-pushed the shastry_base_TE_log_dev branch 2 times, most recently from fce14c6 to 2f7e0ea Compare December 12, 2021 07:30

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@singalsu fyi

Comment thread src/math/log_10.c Outdated
Comment thread src/math/log_10.c Outdated
Comment thread test/cmocka/src/math/arithmetic/base_e_logarithm.c Outdated
Comment thread src/math/log_e.c Outdated

@cujomalainey cujomalainey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely getting cleaner :) still appears you have duplication issues

Comment thread test/cmocka/src/math/arithmetic/base_10_logarithm.c Outdated
Comment thread src/include/sof/math/log_10.h Outdated
Comment thread src/math/Kconfig Outdated
Comment thread src/math/Kconfig Outdated
Comment thread src/math/Kconfig Outdated
Comment thread src/math/log_10.c Outdated
Comment thread src/math/log_10.c Outdated
Comment thread src/math/log_e.c Outdated
Comment thread src/math/log_e.c Outdated
Comment thread test/cmocka/src/math/arithmetic/base_e_logarithm.c Outdated
Comment thread src/include/sof/math/log_10.h Outdated
Comment thread src/math/log_10.c Outdated
Comment thread src/math/log_10.c Outdated
Comment thread src/math/log_e.c Outdated
Comment thread src/math/log_10.c Outdated
Comment thread src/math/Kconfig Outdated
Comment thread src/math/Kconfig Outdated
Comment thread src/math/Kconfig Outdated
Comment thread src/math/log_10.c Outdated
Comment thread src/math/log_e.c Outdated
Comment thread src/math/log_e.c Outdated
Comment thread src/math/log_e.c Outdated
Comment thread test/cmocka/src/math/arithmetic/base_10_logarithm.c Outdated
Comment thread src/include/sof/math/log_10.h Outdated
Comment thread src/include/sof/math/log_e.h Outdated
Comment thread src/math/log_10.c Outdated
Comment thread src/math/log_10.c Outdated
Comment thread src/math/log_e.c Outdated
Comment thread src/math/log_10.c Outdated
@ShriramShastry
ShriramShastry requested a review from lyakh January 31, 2022 07:41
@ShriramShastry

Copy link
Copy Markdown
Contributor Author

@ShriramShastry can you check CI, looks like we could have a build failure. Also please update the review comments above and resolve all the comments that are done.

Done. Resolved CI and PR comments

@lgirdwood

Copy link
Copy Markdown
Member

@singalsu any comments.

@singalsu singalsu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments improvement needed.

Comment thread src/include/sof/math/log.h Outdated
Comment thread src/include/sof/math/log.h Outdated
Comment thread src/math/log_10.c Outdated
Comment thread src/math/log_e.c Outdated
Comment thread src/math/log_e.c Outdated
Comment thread test/cmocka/src/math/arithmetic/base_10_logarithm.c Outdated
Comment thread test/cmocka/src/math/arithmetic/base_10_logarithm.c Outdated
Comment thread test/cmocka/src/math/arithmetic/base_e_logarithm.c Outdated
Comment thread test/cmocka/src/math/arithmetic/base_e_logarithm.c Outdated
@ShriramShastry
ShriramShastry force-pushed the shastry_base_TE_log_dev branch 2 times, most recently from e50d4e2 to f78ecd0 Compare February 2, 2022 04:30
@lgirdwood lgirdwood added this to the v2.1 milestone Feb 2, 2022

@singalsu singalsu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, only a minor change proposed, easier two macros names and move Q-format note to comment.

Comment thread src/include/sof/math/log.h Outdated
Comment thread src/include/sof/math/log.h Outdated
@ShriramShastry
ShriramShastry force-pushed the shastry_base_TE_log_dev branch from f78ecd0 to a2da01e Compare February 2, 2022 23:17
Comment thread src/include/sof/math/log.h Outdated
Comment thread src/math/Kconfig Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marc is correct, we should not be discussing implementation here

Comment thread src/math/Kconfig Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/below/above

Comment thread src/math/log_e.c Outdated
Comment thread src/math/log_10.c Outdated
Comment thread src/math/log_10.c Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need to add the inline keyword to get the optimization

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I compared gcc and clang outputs a number of times and I've never seen inline making any difference, at least never with -On where n > 0. The optimizer always thinks it knows better. That's why there is non-portable stuff like ALWAYS_INLINE.

(static inline is still useful in .h files to silence some warnings)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given we know xcc isnt the smartest sometimes i think it is still wise to have the hints for it

@ShriramShastry ShriramShastry Feb 9, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I change to inline ln_int32() and inline log10_int32(), I could see below error

No codespell typos will be found - file '/usr/share/codespell/dictionary.txt': No such file or directory
ERROR: inline keyword should sit between storage class and type
#10: FILE: src/math/log_10.c:28:
+uint32_t inline log10_int32(uint32_t numerator)

ERROR: inline keyword should sit between storage class and type
#23: FILE: src/math/log_e.c:29:
+uint32_t inline ln_int32(uint32_t numerator)

In case I make changes in log.h like below

static inline uint32_t ln_int32(uint32_t numerator)
{
	return((uint32_t)Q_SHIFT_RND((int64_t)base2_logarithm(numerator) *
				     ONE_OVER_LOG2_E, 64, 32));
}
static inline uint32_t log10_int32(uint32_t numerator)
{
		return((uint32_t)Q_SHIFT_RND((int64_t)base2_logarithm(numerator) *
				     ONE_OVER_LOG2_10, 63, 32));
}

then log10_int32(uint32_t numerator) and ln_int32(uint32_t numerator) in log_10.c and log_e.c will be redundant, the impact of removing log_10.c and log_e.c will result in error in cmocka compilation. cmocka CmakeList.txt is using of log_10.c and log_e.c files.

cmocka_test(base_10_logarithm
	base_10_logarithm.c
	${PROJECT_SOURCE_DIR}/src/math/log_10.c
	${PROJECT_SOURCE_DIR}/src/math/base2log.c
)

cmocka_test(base_e_logarithm
	base_e_logarithm.c
	${PROJECT_SOURCE_DIR}/src/math/log_e.c
	${PROJECT_SOURCE_DIR}/src/math/base2log.c
)

Comment thread src/math/log_e.c Outdated
Comment thread src/include/sof/math/log.h Outdated
@ShriramShastry
ShriramShastry force-pushed the shastry_base_TE_log_dev branch from 3b7da86 to 3226157 Compare February 3, 2022 11:09
@lgirdwood

Copy link
Copy Markdown
Member

@ShriramShastry do you think you can fix review comment in the next week or two ? I will need to start preparing for v2.1 tag soon.

@ShriramShastry
ShriramShastry force-pushed the shastry_base_TE_log_dev branch 3 times, most recently from 48a37fe to 1b9684d Compare February 9, 2022 12:37
@ShriramShastry
ShriramShastry force-pushed the shastry_base_TE_log_dev branch from 1b9684d to 7c89322 Compare February 9, 2022 12:50
fixpoint math log() and log10() function.  logarithm of a
number is the power or exponent by which another value
must be raised to produce an equivalent value of the given number
fix point  log10(x) is a derivative of log2(x)/log2(10)
and loge(x) is log2(x)/log2(e)

Signed-off-by: Shriram Shastry <malladi.sastry@intel.com>
@ShriramShastry
ShriramShastry force-pushed the shastry_base_TE_log_dev branch from 7c89322 to 3db35fb Compare February 9, 2022 12:55
@ShriramShastry

Copy link
Copy Markdown
Contributor Author

@ShriramShastry do you think you can fix review comment in the next week or two ? I will need to start preparing for v2.1 tag soon.

Yes, I think so.

@lgirdwood

Copy link
Copy Markdown
Member

@cujomalainey good for you ?

@cujomalainey
cujomalainey merged commit 10b4c56 into thesofproject:main Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants