From a4e32b43eae351f50d534927b97c4c27a7657418 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 1 Nov 2015 12:12:41 +0100 Subject: [PATCH] libmp: optimize case x/0xffffffff in mpdigdiv() (helps arm) --- sys/src/libmp/port/mpdigdiv.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/src/libmp/port/mpdigdiv.c b/sys/src/libmp/port/mpdigdiv.c index 4a73bb3a4..32b166765 100644 --- a/sys/src/libmp/port/mpdigdiv.c +++ b/sys/src/libmp/port/mpdigdiv.c @@ -21,6 +21,19 @@ mpdigdiv(mpdigit *dividend, mpdigit divisor, mpdigit *quotient) return; } + // very common case + if(~divisor == 0){ + lo += hi; + if(lo < hi){ + hi++; + lo++; + } + if(lo+1 == 0) + hi++; + *quotient = hi; + return; + } + // at this point we know that hi < divisor // just shift and subtract till we're done q = 0;