lib/os/prf.c: let the compiler optimize _ldiv5() on 64-bit architectures

The compiler doesn't need help here.

For example, gcc creates this on Aarch64:

_ldiv5:
        ldr     x1, [x0]
        mov     x2, -3689348814741910324
        movk    x2, 0xcccd, lsl 0
        add     x1, x1, 2
        umulh   x1, x1, x2
        lsr     x1, x1, 2
        str     x1, [x0]
        ret

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2020-10-29 23:35:51 -04:00 committed by Andrew Boie
parent 822dfbd012
commit a5c53d255c

View file

@ -123,6 +123,22 @@ static void _rlrshift(uint64_t *v)
*v = (*v & 1) + (*v >> 1);
}
#ifdef CONFIG_64BIT
static void _ldiv5(uint64_t *v)
{
/*
* Usage in this file wants rounded behavior, not truncation. So add
* two to get the threshold right.
*/
*v += 2U;
/* The compiler can optimize this on its own on 64-bit architectures */
*v /= 5U;
}
#else
/*
* Tiny integer divide-by-five routine. The full 64 bit division
* implementations in libgcc are very large on some architectures, and
@ -182,6 +198,8 @@ static void _ldiv5(uint64_t *v)
*v = result;
}
#endif
static char _get_digit(uint64_t *fr, int *digit_count)
{
char rval;