1 // SPDX-License-Identifier: BSD-3-Clause/
2 //
3 // Copyright(c) 2021 Intel Corporation. All rights reserved.
4 //
5 // Author: Shriram Shastry <malladi.sastry@linux.intel.com>
6 //
7 //
8 
9 #include <sof/math/log.h>
10 #include <sof/audio/format.h>
11 /**
12  * Base-10 logarithm  log10(x)
13  *
14  * loge = (u) computes the base-10 logarithm of
15  * u using lookup table.
16  * input u must be scalar/real number and positive
17  *
18  * +------------------+-----------------+--------+--------+
19  * | inpfxp	      |log10(returntype)| inpfxp |  loge  |
20  * +----+-----+-------+----+----+-------+--------+--------+
21  * |WLen| FLen|Signbit|WLen|FLen|Signbit| Qformat| Qformat|
22  * +----+-----+-------+----+----+-------+--------+--------+
23  * | 32 | 0   |	 0    | 32 | 28 | 0     | 32.0	 | 4.28   |
24  * +------------------+-----------------+--------+--------+
25  * Arguments	: uint32_t numerator [1 to 4294967295, Q32.0]
26  * Return Type	: uint32_t UQ4.28 [0 to 9.6329499409]
27  */
log10_int32(uint32_t numerator)28 uint32_t log10_int32(uint32_t numerator)
29 {
30 	return((uint32_t)Q_SHIFT_RND((int64_t)base2_logarithm(numerator) *
31 				     ONE_OVER_LOG2_10, 63, 32));
32 }
33