Skip to contentSkip to conversation

Add udivmoddi4.

PATCH In review Christian Melki 2 participants 4 messages Jun 7, 2021 – Jun 9, 2021 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add udivmoddi4.

A newer toolchain will emit udivmoddi4 for certain divide + modulo operations instead of a separate divide and modulo operation. AFAIU, this would be sufficient.

---
 arch/x86/lib/div64.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/x86/lib/div64.c +5 -0
index 2bea205f60..a5b536fbc5 100644
@@ -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);
+}
Signature · 1 line
2.31.1
#1 lore raw
Quoted 14 lines · 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.

---
 arch/x86/lib/div64.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/x86/lib/div64.c +0 -0
index 2bea205f60..a5b536fbc5 100644

arch/x86/lib/div64.c u64 __umoddi3(u64 num, u64 den) · line 117

Quoted 8 lines
arch/x86/lib/div64.c +5 -0
@@ -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?

Signature · 1 line
Tom
#2 lore raw
Quoted 11 lines · Tom Rini
Quoted 9 lines · 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.

---
 arch/x86/lib/div64.c | 5 +++++
 1 file changed, 5 insertions(+)
Quoted 17 lines

arch/x86/lib/div64.c u64 __umoddi3(u64 num, u64 den) · line 117

Quoted 13 lines
arch/x86/lib/div64.c +5 -0
index 2bea205f60..a5b536fbc5 100644
@@ -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.

#3 lore raw
Quoted 36 lines · Christian Melki
Quoted 11 lines · Tom Rini
Quoted 9 lines · 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.

---
 arch/x86/lib/div64.c | 5 +++++
 1 file changed, 5 insertions(+)
Quoted 17 lines

arch/x86/lib/div64.c u64 __umoddi3(u64 num, u64 den) · line 117

Quoted 13 lines
arch/x86/lib/div64.c +5 -0
index 2bea205f60..a5b536fbc5 100644
@@ -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.

Quoted 8 lines

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.

Signature · 1 line
Tom