Skip to content

math: numbers: use const array arguments and add Doxygen comments - #11619

Open
tmleman wants to merge 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/math/numbers_const
Open

tmleman wants to merge 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/math/numbers_const

Conversation

@tmleman

@tmleman tmleman commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

find_equal_int16(), find_min_int16() and find_max_abs_int32() only read their input vector. Declare it const, so callers with constant data do not have to cast the qualifier away. Existing callers are not affected, the functions are currently only called from the unit tests.

Document gcd(), find_equal_int16(), find_min_int16(), find_max_abs_int32(), norm_int32() and crc32() with Doxygen comments in numbers.h, including what was not described before: the size idx[] needs and the meaning of a zero or negative max_results in find_equal_int16(), the minimum vector length of the find functions, the result of norm_int32() for -1 and the use of the base argument of crc32(). The comments in numbers.c now refer to the header.

The comment of find_max_abs_int32() said that the smallest negative value is saturated. That is not what the code does: the negation of INT32_MIN is done in 32 bits and overflows. Document the value as not supported instead of changing the function here.

Make the input vectors of the find_*() unit tests const, to build the tests against the new prototypes.

No functional change.

Closes #11590

Assisted-by: Copilot:claude-fable-5.2

Copilot AI balanced review requested due to automatic review settings December 4, 2026 15:19

Copilot AI 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.

🟡 Changes recommended

The documentation omits the gcd restriction on INT_MIN when both arguments are nonzero and the length limit required to keep output indices representable in int16_t.

2 open issues
What changed in this PR

Improves the math helpers’ const-correctness and API documentation, addressing #11590 without changing runtime logic.

Changes:

  • Makes the three vector-search inputs const.
  • Adds Doxygen documentation for six math helpers, including boundary conditions and CRC continuation.
  • Updates vector-search tests to use constant input arrays.
File Description
test/​ztest/​unit/​math/​basic/​arithmetic/​test_find_min_int16_ztest.c Uses constant minimum-search inputs.
test/​ztest/​unit/​math/​basic/​arithmetic/​test_find_max_abs_int32_ztest.c Uses constant absolute-maximum inputs.
test/​ztest/​unit/​math/​basic/​arithmetic/​test_find_equal_int16_ztest.c Uses constant equality-search inputs.
src/​math/​numbers.c Updates signatures and points comments to the header.
src/​include/​sof/​math/​numbers.h Adds const-qualified declarations and Doxygen contracts.

Review effort: Balanced

Comment on lines +58 to +59
* gcd(0, 0) returns 0. Otherwise the signs of the arguments are ignored and
* the result is positive.
* if max_results is zero or negative
* \param[in] vec vector to search from
* \param[in] n value to search for
* \param[in] vec_length number of values in vec
@intel-sofci

Copy link
Copy Markdown

PR 11619: test results

Run date: 2026-12-04 15:49 UTC

Tested commit: 82f109318065760f66c4f0bd5679f7dcdbfa0b40

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

find_equal_int16(), find_min_int16() and find_max_abs_int32() only
read their input vector. Declare it const, so callers with constant
data do not have to cast the qualifier away. Existing callers are not
affected, the functions are currently only called from the unit tests.

Document gcd(), find_equal_int16(), find_min_int16(),
find_max_abs_int32(), norm_int32() and crc32() with Doxygen comments
in numbers.h, including what was not described before: the size idx[]
needs and the meaning of a zero or negative max_results in
find_equal_int16(), the minimum vector length of the find functions,
the result of norm_int32() for -1 and the use of the base argument of
crc32(). The comments in numbers.c now refer to the header.

The comment of find_max_abs_int32() said that the smallest negative
value is saturated. That is not what the code does: the negation of
INT32_MIN is done in 32 bits and overflows. Document the value as not
supported instead of changing the function here.

Make the input vectors of the find_*() unit tests const, to build the
tests against the new prototypes.

No functional change.

Closes thesofproject#11590

Assisted-by: Copilot:claude-fable-5.2
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>

@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.

LGTM, @tmleman will need copilot resolved before merge. Thanks !

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.

math: numbers: use const array arguments and add Doxygen documentation

4 participants