Skip to content

Commit c1d337d

Browse files
maciej-w-rozyckitsbogend
authored andcommitted
MIPS: Avoid DIVU in `__div64_32' is result would be zero
We already check the high part of the divident against zero to avoid the costly DIVU instruction in that case, needed to reduce the high part of the divident, so we may well check against the divisor instead and set the high part of the quotient to zero right away. We need to treat the high part the divident in that case though as the remainder that would be calculated by the DIVU instruction we avoided. This has passed correctness verification with test_div64 and reduced the module's average execution time down to 1.0445s and 0.2619s from 1.0668s and 0.2629s respectively for an R3400 CPU @40MHz and a 5Kc CPU @160MHz. Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
1 parent c49f71f commit c1d337d

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

arch/mips/include/asm/div64.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@
6868
\
6969
__high = __div >> 32; \
7070
__low = __div; \
71-
__upper = __high; \
7271
\
73-
if (__high) { \
72+
if (__high < __radix) { \
73+
__upper = __high; \
74+
__high = 0; \
75+
} else { \
7476
__asm__("divu $0, %z1, %z2" \
7577
: "=x" (__modquot) \
7678
: "Jr" (__high), "Jr" (__radix)); \

0 commit comments

Comments
 (0)