[v1] sched: adds function to get 64 bits greatest common divisor

Message ID 20210915102610.83105-1-xuemingl@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v1] sched: adds function to get 64 bits greatest common divisor |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
ci/iol-x86_64-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing fail Testing issues
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Xueming Li Sept. 15, 2021, 10:26 a.m. UTC
  This patch adds new function that compute the greatest common
divisor of 64 bits, also changes the original 32 bits function to call
this new 64 bits version.

Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
v1: add 64 bits version and make 32 bits api call it

 lib/sched/rte_sched_common.h | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
  

Comments

Kevin Traynor Sept. 22, 2021, 5:09 p.m. UTC | #1
On 15/09/2021 11:26, Xueming Li wrote:
> This patch adds new function that compute the greatest common
> divisor of 64 bits, also changes the original 32 bits function to call
> this new 64 bits version.
> 

Can you say why it is needed? It's unused apart from being called for 
the original 32 bit version.

> Signed-off-by: Xueming Li <xuemingl@nvidia.com>
> ---
> v1: add 64 bits version and make 32 bits api call it
> 
>   lib/sched/rte_sched_common.h | 19 ++++++++++++++++---
>   1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/sched/rte_sched_common.h b/lib/sched/rte_sched_common.h
> index 96706df7bd..1056543a84 100644
> --- a/lib/sched/rte_sched_common.h
> +++ b/lib/sched/rte_sched_common.h
> @@ -51,10 +51,10 @@ rte_min_pos_4_u16(uint16_t *x)
>    *    gcd(a, b) = gcd(b, a mod b)
>    *
>    */
> -static inline uint32_t
> -rte_get_gcd(uint32_t a, uint32_t b)
> +static inline uint64_t
> +rte_get_gcd64(uint64_t a, uint64_t b)
>   {
> -	uint32_t c;
> +	uint64_t c;
>   
>   	if (a == 0)
>   		return b;
> @@ -76,6 +76,19 @@ rte_get_gcd(uint32_t a, uint32_t b)
>   	return a;
>   }
>   
> +/*
> + * Compute the Greatest Common Divisor (GCD) of two u32 numbers.
> + * This implementation uses Euclid's algorithm:
> + *    gcd(a, 0) = a
> + *    gcd(a, b) = gcd(b, a mod b)
> + *
> + */

I would probably not describe the algorithm here as it is not 
implemented in this function.

> +static inline uint32_t
> +rte_get_gcd(uint32_t a, uint32_t b)
> +{
> +	return rte_get_gcd64(a, b);
> +}
> +
>   /*
>    * Compute the Lowest Common Denominator (LCD) of two numbers.
>    * This implementation computes GCD first:
>
  
Xueming Li Sept. 23, 2021, 5:34 a.m. UTC | #2
On Wed, 2021-09-22 at 18:09 +0100, Kevin Traynor wrote:
> On 15/09/2021 11:26, Xueming Li wrote:
> > This patch adds new function that compute the greatest common
> > divisor of 64 bits, also changes the original 32 bits function to call
> > this new 64 bits version.
> > 
> 
> Can you say why it is needed? It's unused apart from being called for 
> the original 32 bit version.

mlx5 vdpa driver is expecting to use a 64 bit version.

> 
> > Signed-off-by: Xueming Li <xuemingl@nvidia.com>
> > ---
> > v1: add 64 bits version and make 32 bits api call it
> > 
> >   lib/sched/rte_sched_common.h | 19 ++++++++++++++++---
> >   1 file changed, 16 insertions(+), 3 deletions(-)
> > 
> > diff --git a/lib/sched/rte_sched_common.h b/lib/sched/rte_sched_common.h
> > index 96706df7bd..1056543a84 100644
> > --- a/lib/sched/rte_sched_common.h
> > +++ b/lib/sched/rte_sched_common.h
> > @@ -51,10 +51,10 @@ rte_min_pos_4_u16(uint16_t *x)
> >    *    gcd(a, b) = gcd(b, a mod b)
> >    *
> >    */
> > -static inline uint32_t
> > -rte_get_gcd(uint32_t a, uint32_t b)
> > +static inline uint64_t
> > +rte_get_gcd64(uint64_t a, uint64_t b)
> >   {
> > -	uint32_t c;
> > +	uint64_t c;
> >   
> >   	if (a == 0)
> >   		return b;
> > @@ -76,6 +76,19 @@ rte_get_gcd(uint32_t a, uint32_t b)
> >   	return a;
> >   }
> >   
> > +/*
> > + * Compute the Greatest Common Divisor (GCD) of two u32 numbers.
> > + * This implementation uses Euclid's algorithm:
> > + *    gcd(a, 0) = a
> > + *    gcd(a, b) = gcd(b, a mod b)
> > + *
> > + */
> 
> I would probably not describe the algorithm here as it is not 
> implemented in this function.

Thanks, I'll just mention that a 32 bit version of GCD.

> 
> > +static inline uint32_t
> > +rte_get_gcd(uint32_t a, uint32_t b)
> > +{
> > +	return rte_get_gcd64(a, b);
> > +}
> > +
> >   /*
> >    * Compute the Lowest Common Denominator (LCD) of two numbers.
> >    * This implementation computes GCD first:
> > 
>
  

Patch

diff --git a/lib/sched/rte_sched_common.h b/lib/sched/rte_sched_common.h
index 96706df7bd..1056543a84 100644
--- a/lib/sched/rte_sched_common.h
+++ b/lib/sched/rte_sched_common.h
@@ -51,10 +51,10 @@  rte_min_pos_4_u16(uint16_t *x)
  *    gcd(a, b) = gcd(b, a mod b)
  *
  */
-static inline uint32_t
-rte_get_gcd(uint32_t a, uint32_t b)
+static inline uint64_t
+rte_get_gcd64(uint64_t a, uint64_t b)
 {
-	uint32_t c;
+	uint64_t c;
 
 	if (a == 0)
 		return b;
@@ -76,6 +76,19 @@  rte_get_gcd(uint32_t a, uint32_t b)
 	return a;
 }
 
+/*
+ * Compute the Greatest Common Divisor (GCD) of two u32 numbers.
+ * This implementation uses Euclid's algorithm:
+ *    gcd(a, 0) = a
+ *    gcd(a, b) = gcd(b, a mod b)
+ *
+ */
+static inline uint32_t
+rte_get_gcd(uint32_t a, uint32_t b)
+{
+	return rte_get_gcd64(a, b);
+}
+
 /*
  * Compute the Lowest Common Denominator (LCD) of two numbers.
  * This implementation computes GCD first: