* [PATCH] Add udivmoddi4.
@ 2021-06-07 9:20 Christian Melki
2021-06-09 18:31 ` Tom Rini
0 siblings, 1 reply; 4+ messages in thread
From: Christian Melki @ 2021-06-07 9:20 UTC (permalink / raw)
To: u-boot; +Cc: christian.melki
A newer toolchain will emit udivmoddi4 for certain divide + modulo
operations instead of a separate divide and modulo operation.
AFAIU, this would be sufficient.
Signed-off-by: Christian Melki <christian.melki@t2data.com>
---
arch/x86/lib/div64.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/x86/lib/div64.c b/arch/x86/lib/div64.c
index 2bea205f60..a5b536fbc5 100644
--- a/arch/x86/lib/div64.c
+++ b/arch/x86/lib/div64.c
@@ -110,3 +110,8 @@ u64 __umoddi3(u64 num, u64 den)
_64bit_divide(num, den, &v);
return v;
}
+
+u64 __udivmoddi4(u64 num, u64 den, u64 *rem)
+{
+ return _64bit_divide(num, den, rem);
+}
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Add udivmoddi4.
2021-06-07 9:20 [PATCH] Add udivmoddi4 Christian Melki
@ 2021-06-09 18:31 ` Tom Rini
2021-06-09 19:20 ` Christian Melki
0 siblings, 1 reply; 4+ messages in thread
From: Tom Rini @ 2021-06-09 18:31 UTC (permalink / raw)
To: Christian Melki; +Cc: u-boot
[-- Attachment #1: Type: text/plain, Size: 857 bytes --]
On Mon, Jun 07, 2021 at 11:20:47AM +0200, Christian Melki wrote:
> A newer toolchain will emit udivmoddi4 for certain divide + modulo
> operations instead of a separate divide and modulo operation.
> AFAIU, this would be sufficient.
>
> Signed-off-by: Christian Melki <christian.melki@t2data.com>
> ---
> arch/x86/lib/div64.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/arch/x86/lib/div64.c b/arch/x86/lib/div64.c
> index 2bea205f60..a5b536fbc5 100644
> --- a/arch/x86/lib/div64.c
> +++ b/arch/x86/lib/div64.c
> @@ -110,3 +110,8 @@ u64 __umoddi3(u64 num, u64 den)
> _64bit_divide(num, den, &v);
> return v;
> }
> +
> +u64 __udivmoddi4(u64 num, u64 den, u64 *rem)
> +{
> + return _64bit_divide(num, den, rem);
> +}
How do you trigger this and should you not be using do_div(), etc,
instead?
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add udivmoddi4.
2021-06-09 18:31 ` Tom Rini
@ 2021-06-09 19:20 ` Christian Melki
2021-06-09 20:29 ` Tom Rini
0 siblings, 1 reply; 4+ messages in thread
From: Christian Melki @ 2021-06-09 19:20 UTC (permalink / raw)
To: Tom Rini; +Cc: u-boot
On 6/9/21 8:31 PM, Tom Rini wrote:
> On Mon, Jun 07, 2021 at 11:20:47AM +0200, Christian Melki wrote:
>
>> A newer toolchain will emit udivmoddi4 for certain divide + modulo
>> operations instead of a separate divide and modulo operation.
>> AFAIU, this would be sufficient.
>>
>> Signed-off-by: Christian Melki <christian.melki@t2data.com>
>> ---
>> arch/x86/lib/div64.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/arch/x86/lib/div64.c b/arch/x86/lib/div64.c
>> index 2bea205f60..a5b536fbc5 100644
>> --- a/arch/x86/lib/div64.c
>> +++ b/arch/x86/lib/div64.c
>> @@ -110,3 +110,8 @@ u64 __umoddi3(u64 num, u64 den)
>> _64bit_divide(num, den, &v);
>> return v;
>> }
>> +
>> +u64 __udivmoddi4(u64 num, u64 den, u64 *rem)
>> +{
>> + return _64bit_divide(num, den, rem);
>> +}
>
> How do you trigger this and should you not be using do_div(), etc,
> instead?
>
I probably should. Was trying to minimize various dependencies on u-boot
code (atleast with function separation) while trying to implement a
redundancy boot mechanism as a cmd. Triggered by using two consecutive
calls between the same variables for division and remainder as pure
operands with a gcc 9.3 x86 toolchain.
U-boot has no div_up afaik?
a = b / c;
if (b % c) {
a++;
}
b / c and b % c gets optimized / translated to udivmoddi4 as one operation.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add udivmoddi4.
2021-06-09 19:20 ` Christian Melki
@ 2021-06-09 20:29 ` Tom Rini
0 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2021-06-09 20:29 UTC (permalink / raw)
To: Christian Melki; +Cc: u-boot
[-- Attachment #1: Type: text/plain, Size: 1669 bytes --]
On Wed, Jun 09, 2021 at 09:20:20PM +0200, Christian Melki wrote:
> On 6/9/21 8:31 PM, Tom Rini wrote:
> > On Mon, Jun 07, 2021 at 11:20:47AM +0200, Christian Melki wrote:
> >
> >> A newer toolchain will emit udivmoddi4 for certain divide + modulo
> >> operations instead of a separate divide and modulo operation.
> >> AFAIU, this would be sufficient.
> >>
> >> Signed-off-by: Christian Melki <christian.melki@t2data.com>
> >> ---
> >> arch/x86/lib/div64.c | 5 +++++
> >> 1 file changed, 5 insertions(+)
> >>
> >> diff --git a/arch/x86/lib/div64.c b/arch/x86/lib/div64.c
> >> index 2bea205f60..a5b536fbc5 100644
> >> --- a/arch/x86/lib/div64.c
> >> +++ b/arch/x86/lib/div64.c
> >> @@ -110,3 +110,8 @@ u64 __umoddi3(u64 num, u64 den)
> >> _64bit_divide(num, den, &v);
> >> return v;
> >> }
> >> +
> >> +u64 __udivmoddi4(u64 num, u64 den, u64 *rem)
> >> +{
> >> + return _64bit_divide(num, den, rem);
> >> +}
> >
> > How do you trigger this and should you not be using do_div(), etc,
> > instead?
> >
>
> I probably should. Was trying to minimize various dependencies on u-boot
> code (atleast with function separation) while trying to implement a
> redundancy boot mechanism as a cmd. Triggered by using two consecutive
> calls between the same variables for division and remainder as pure
> operands with a gcc 9.3 x86 toolchain.
>
> U-boot has no div_up afaik?
>
> a = b / c;
> if (b % c) {
> a++;
> }
>
> b / c and b % c gets optimized / translated to udivmoddi4 as one operation.
I think you should look at include/div64.h and see if what you want is
handled by something there already.
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-06-09 20:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-07 9:20 [PATCH] Add udivmoddi4 Christian Melki
2021-06-09 18:31 ` Tom Rini
2021-06-09 19:20 ` Christian Melki
2021-06-09 20:29 ` Tom Rini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox