From 10bcb3709bd7513b8909a67fe698351c0ad9d686 Mon Sep 17 00:00:00 2001 From: Danny Milosavljevic Date: Sun, 15 Nov 2020 14:36:10 +0100 Subject: [PATCH] ARM: Speed up __mesabi_uldiv for powers-of-two divisors. * lib/mes/div.c (__mesabi_uldiv): Speed up division for powers-of-two divisors. --- lib/mes/div.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/mes/div.c b/lib/mes/div.c index ce135a29..f7f118a4 100644 --- a/lib/mes/div.c +++ b/lib/mes/div.c @@ -50,11 +50,32 @@ __mesabi_uldiv (unsigned long a, unsigned long b, unsigned long* remainder) if (!remainder) remainder = &tmp; *remainder = 0; - if (b == 1) + switch (b) { + case 64UL: + *remainder = a & 63UL; + return a >> 6UL; + case 32UL: + *remainder = a & 31UL; + return a >> 5UL; + case 16UL: + *remainder = a & 15UL; + return a >> 4UL; + case 8UL: + *remainder = a & 7UL; + return a >> 3UL; + case 4UL: + *remainder = a & 3UL; + return a >> 2UL; + case 2UL: + *remainder = a & 1UL; + return a >> 1UL; + case 1UL: + *remainder = 0; return a; - else if (b == 0) + case 0UL: __mesabi_div0(); - else + return 0UL; + default: { unsigned long x; for (x = 0; a >= b; a -= b) @@ -62,6 +83,7 @@ __mesabi_uldiv (unsigned long a, unsigned long b, unsigned long* remainder) *remainder = a; return x; } + } } /* Note: Rounds towards zero.