Am Wed, May 18, 2022 at 12:49:21PM +0200 schrieb Steffen Nurpmeso:
> What surprised me was that the Apple code requires more calls, and
> that today divisions and multiplications still matter.  I think it
> was the Cyrix 166+ (or was it Athlon 1600+) where +,-,<<,>> was
> one cycle, * was ten cycles, and %,/ was fourty cycles.  But
> i think the Core i5 8th Gen that i have requires one cycle for all
> of them.

I dare you to find any CPU optimized for speed where division and modulo
are as fast as multiplication. What you have nowadays is a single cycle
for basic operations like additions and shifts, about three cycles for
multiplications (on x86 at least) and an order of magnitude more for
division. That's not really surprising either if you consider that
integer multiplication has a fast circuit implementation where as
division is often implemented as cascading conditional subtraction.
The difference matters enough turning the reminder operation in the ELF
hash into essentially (x - x * (1/size) * size) give a 2% speed up for a
large application like Firefox ten years ago.

Joerg

Reply via email to