Skip to content

Commit 0855423

Browse files
committed
math: numbers: only define SOF gcd() if not already defined
Zephyr commit ("sys: util: Add gcd and lcm utilities") added a version of gcd() to sys/util.h that now can conflict with SOF numbers.h definition of gcd(). Make the SOF definition conditional. The Zephyr default gcd() version takes unsigned numbers while SOF version took signed, but it seems SOF existing usage is fine to make this change. Link: #10428 Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 1fa4e22 commit 0855423

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/include/sof/math/numbers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
__a > 0 ? 1 : 0; \
3737
})
3838

39+
/* Zephyr added gcd() in 2025/Nov to sys/util.h */
40+
#ifndef gcd
41+
#define USE_SOF_GCD 1
3942
int gcd(int a, int b); /* Calculate greatest common divisor for a and b */
43+
#endif
4044

4145
/* This is a divide function that returns ceil of the quotient.
4246
* E.g. ceil_divide(9, 3) returns 3, ceil_divide(10, 3) returns 4.

src/math/numbers.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include <rtos/symbol.h>
1616
#include <stdint.h>
1717

18+
/* see numbers.h */
19+
#ifdef USE_SOF_GCD
20+
1821
/* This function returns the greatest common divisor of two numbers
1922
* If both parameters are 0, gcd(0, 0) returns 0
2023
* If first parameters is 0 or second parameter is 0, gcd(0, b) returns b
@@ -74,6 +77,7 @@ int gcd(int a, int b)
7477
return a << k;
7578
}
7679
EXPORT_SYMBOL(gcd);
80+
#endif /* USE_SOF_GCD */
7781

7882
#if CONFIG_NUMBERS_VECTOR_FIND
7983

0 commit comments

Comments
 (0)