, , x86.
, , . , . , 2 ^ p + 2 ^ q +... 2 ^ r, x * 2 ^ p + x * 2 ^ q +.. x * 2 * r, p, q,... r. :
; x in EDX
; product to EAX
xor eax,eax
shl edx,r ; x*2^r
add eax,edx
shl edx,q-r ; x*2^q
add eax,edx
shl edx,p-q ; x*2^p
add eax,edx
, 4 ,
, .
10 , ,
.
9:
mov eax,edx ; same effect as xor eax,eax/shl edx 1/add eax,edx
shl edx,3 ; x*2^3
add eax,edx
; 2 .
, LEA (load effective address)
.
LEA, ,
CPU.
LEA " ".
t = 2 ^ k * x + y k = 1,2,3 (. Intel) t, x y
. x == y, 1,2,3,4,5,8,9 x,
x y ,
(, t), .
, 9 :
lea eax,[edx*8+edx] ; takes 1 clock
LEA , :
lea eax,[edx*4+edx] ; 5 * edx
lea eax,[eax*2+edx] ; 11 * edx
lea eax,[eax*4] ; 44 * edx
/,
1,2,3,4,5,8 9. , ,
3-4 .
(, SHL/SUB/NEG/MOV)
, LEA
. 31:
lea eax,[4*edx]
lea eax,[8*eax] ; 32*edx
sub eax,edx; 31*edx ; 3 clocks
LEA :
lea eax,[edx*4+edx]
lea eax,[edx*2+eax] ; eax*7
lea eax,[eax*2+edx] ; eax*15
lea eax,[eax*2+edx] ; eax*31 ; 4 clocks
, .
LEA, SHL, SUB, NEG, MOV -
case zero clocks, , exeuction . , .
, ,
( 5 ),
, , ( ).
PARLANSE, A [i ], . ,
, ; ,
, .
,
1 10000. 5-6 .
, PARLANSE
.