提交 e31c0d0d 编写于 作者: M Maciej W. Rozycki 提交者: Zheng Zengkai

MIPS: Avoid DIVU in `__div64_32' is result would be zero

stable inclusion
from stable-5.10.38
commit d17af8b19d99c400a484427c88f973e6b1f842aa
bugzilla: 51875
CVE: NA

--------------------------------

commit c1d337d4 upstream.

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: NMaciej W. Rozycki <macro@orcam.me.uk>
Signed-off-by: NThomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 670c6c39
...@@ -68,9 +68,11 @@ ...@@ -68,9 +68,11 @@
\ \
__high = __div >> 32; \ __high = __div >> 32; \
__low = __div; \ __low = __div; \
__upper = __high; \
\ \
if (__high) { \ if (__high < __radix) { \
__upper = __high; \
__high = 0; \
} else { \
__asm__("divu $0, %z1, %z2" \ __asm__("divu $0, %z1, %z2" \
: "=x" (__modquot) \ : "=x" (__modquot) \
: "Jr" (__high), "Jr" (__radix)); \ : "Jr" (__high), "Jr" (__radix)); \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册