architecture - Why are multiplication algorithms needed if hardware already does it? -
i learning karatsuba algorithm fast integer multiplication , wondered, since computers have dedicated hardware built cpus multiplication why algorithm necessary?
is large numbers hard multiply, algorithm breaks down simpler steps easier hardware handle, because hardware @ multiplying smaller numbers?
all cpu has fixed bit width alu/fpu.
for example on i80x86 (pc) alu limited to:
i8086+ 16 bit i80386+ 32 bit x64 arch 64 bit
allowing compute 16/32/64 bit numbers operands. i80x87 fpu use
80 bit
number representations converted from/to ieeefloat(32bit)/double(64bit)
limiting precision.if need compute numbers bigger bit width hw limit
then need break down chunks computable on alu/fpu (and handle them digits of number) , combine results final value. alu counting , why cpu's have
carry
flag , alu support adding , substracting carry. if doing simple+/-
add/subs digits lowest (lsw) highest (msw) propagating carry. see:the multiplication , division more complex , need use long algorithms (like computing on paper)
o(n^2)
.n
number of "digits". 1 digit8/16/32/64
bit number or biggest10^m
base number. while computing small numbers (up few 100x bits) there no gain more advanced algorithms because have overhead. bigger numbers situation turns in favor of them. see:computing big floating point numbers tricky , faster done on integer arithmetics alu instead in fpu in general. still in occasions can benefit fpu if break values more variables example enhance accuracy while summing/integrating see:
Comments
Post a Comment