210 likes | 330 Views
Fast Carry Algorithm. a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15. c0. Step 1: calculate pi’s, gi’s. p i = ai + bi gi = ai∙bi. a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15
E N D
Fast Carry Algorithm a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 c0
Step 1: calculate pi’s, gi’s pi = ai + bi gi = ai∙bi a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 c0
Step 2: Calculate global Pi’s, Gi’s P0 = p0∙p1∙p2∙p3 G0 = g3+(p3∙g2)+(p3∙p2∙g1)+(p3∙p2∙p1∙g0) P1 = p4∙p5∙p6∙p7 G1 = g7+(p7∙g6)+(p7∙p6∙g5)+(p7∙p6∙p5∙g4) P2 = p8∙p9∙p10∙p11 G2 = g11+(p11∙g10)+(p11∙p10∙g9)+(p11∙p10∙p9∙g8) P3 = p12∙p13∙p14∙p15 G3 = g15+(p15∙g14)+(p15∙p14∙g13)+(p15∙p14∙p13∙g12) P0 G0 P1 G1 P2 G2 P3 G3 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 c0
Step 3: Calculate global Ci’s C1 = G0+(P0∙c0) C2 = G1+(P1∙G0)+(P1∙P0∙c0) C3 = G2+(P2∙G1)+(P2∙P1∙G0)+(P2∙P1∙P0∙c0) C4 = G3+(P3∙G2)+(P3∙P2∙G1)+(P3∙P2∙P1∙G0)+(P3∙P2∙P1∙P0∙c0) P0 G0 P1 G1 P2 G2 P3 G3 C1 C2 C3 C4 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 c0
Step 4: Calculate ri’s in groups of 4 r0 = a0+b0+c0 r1 = a1+b1+g0+(p0∙c0) r2 = a2+b2+g1+(p1∙g0)+(p1∙p0∙c0) r3 = a3+b3+g2+(p2∙g1)+(p2∙p1∙g0)+(p2∙p1∙p0∙c0) P0 G0 P1 G1 P2 G2 P3 G3 C1 C2 C4 C3 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 c0 r0 r1 r2 r3
Step 4: Calculate ri’s in groups of 4 r4 = a4+b4+C1 r5 = a5+b5+g4+(p4∙C1) r6 = a6+b6+g5+(p5∙g4)+(p5∙p4∙C1) r7 = a7+b7+g6+(p6∙g5)+(p6∙p5∙g4)+(p6∙p5∙p4∙C1) P0 G0 P1 G1 P2 G2 P3 G3 C1 C2 C4 C3 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 c0 r0 r1 r2 r3 r4 r5 r6 r7
Step 4: Calculate ri’s in groups of 4 r8 = a8+b8+C2 r9 = a9+b9+g8+(p8∙C2) r10 = a10+b10+g9+(p9∙g8)+(p9∙p8∙C2) r11 = a11+b11+g10+(p10∙g9)+(p10∙p9∙g8)+(p10∙p9∙p8∙C2) P0 G0 P1 G1 P2 G2 P3 G3 C1 C2 C4 C3 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 c0 r0 r1 r2 r3 r8 r9 r10 r11 r4 r5 r6 r7
Step 4: Calculate ri’s in groups of 4 r12 = a12+b12+C3 r13 = a13+b13+g12+(p12∙C3) r14 = a14+b14+g13+(p13∙g12)+(p13∙p12∙C3) r15 = a15+b15+g14+(p14∙g13)+(p14∙p13∙g12)+(p14∙p13∙p12∙C3) P3 G3 P0 G0 P1 G1 P2 G2 C1 C2 C4 C3 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 c0 r0 r1 r2 r3 r12 r13 r14 r15 r4 r5 r6 r7 r8 r9 r10 r11
Example a = 31980 b = -16354 = 0111110011101100 = 1100000000011110 P0 G0 P1 G1 P2 G2 P3 G3 C1 C2 C4 C3 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 c0
Example a = 31980 b = -16354 = 0111110011101100 = 1100000000011110 P0 G0 P1 G1 P2 G2 P3 G3 C1 C2 C4 C3 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 0
Step 1: calculate pi’s, gi’s pi = ai + bi gi = ai∙bi P0 G0 P1 G1 P2 G2 P3 G3 C1 C2 C4 C3 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 0
Step 1: calculate pi’s, gi’s pi = ai + bi gi = ai∙bi P0 G0 P1 G1 P2 G2 P3 G3 C1 C2 C4 C3 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0
Step 2: Calculate global Pi’s, Gi’s P0 = p0∙p1∙p2∙p3 G0 = g3+(p3∙g2)+(p3∙p2∙g1)+(p3∙p2∙p1∙g0) P1 = p4∙p5∙p6∙p7 G1 = g7+(p7∙g6)+(p7∙p6∙g5)+(p7∙p6∙p5∙g4) P2 = p8∙p9∙p10∙p11 G2 = g11+(p11∙g10)+(p11∙p10∙g9)+(p11∙p10∙p9∙g8) P3 = p12∙p13∙p14∙p15 G3 = g15+(p15∙g14)+(p15∙p14∙g13)+(p15∙p14∙p13∙g12) P0 G0 P1 G1 P2 G2 P3 G3 C1 C2 C4 C3 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0
Step 2: Calculate global Pi’s, Gi’s P0 = p0∙p1∙p2∙p3 G0 = g3+(p3∙g2)+(p3∙p2∙g1)+(p3∙p2∙p1∙g0) P1 = p4∙p5∙p6∙p7 G1 = g7+(p7∙g6)+(p7∙p6∙g5)+(p7∙p6∙p5∙g4) P2 = p8∙p9∙p10∙p11 G2 = g11+(p11∙g10)+(p11∙p10∙g9)+(p11∙p10∙p9∙g8) P3 = p12∙p13∙p14∙p15 G3 = g15+(p15∙g14)+(p15∙p14∙g13)+(p15∙p14∙p13∙g12) 0 1 1 0 0 0 1 1 C1 C2 C4 C3 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0
Step 3: Calculate global Ci’s C1 = G0+(P0∙c0) C2 = G1+(P1∙G0)+(P1∙P0∙c0) C3 = G2+(P2∙G1)+(P2∙P1∙G0)+(P2∙P1∙P0∙c0) C4 = G3+(P3∙G2)+(P3∙P2∙G1)+(P3∙P2∙P1∙G0)+(P3∙P2∙P1∙P0∙c0) 0 1 1 0 0 0 1 1 C1 C2 C4 C3 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0
Step 3: Calculate global Ci’s C1 = G0+(P0∙c0) C2 = G1+(P1∙G0)+(P1∙P0∙c0) C3 = G2+(P2∙G1)+(P2∙P1∙G0)+(P2∙P1∙P0∙c0) C4 = G3+(P3∙G2)+(P3∙P2∙G1)+(P3∙P2∙P1∙G0)+(P3∙P2∙P1∙P0∙c0) 0 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0
Step 4: Calculate ri’s in groups of 4 r0 = a0+b0+c0 r1 = a1+b1+g0+(p0∙c0) r2 = a2+b2+g1+(p1∙g0)+(p1∙p0∙c0) r3 = a3+b3+g2+(p2∙g1)+(p2∙p1∙g0)+(p2∙p1∙p0∙c0) 0 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1
Step 4: Calculate ri’s in groups of 4 r4 = a4+b4+C1 r5 = a5+b5+g4+(p4∙C1) r6 = a6+b6+g5+(p5∙g4)+(p5∙p4∙C1) r7 = a7+b7+g6+(p6∙g5)+(p6∙p5∙g4)+(p6∙p5∙p4∙C1) 0 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0
Step 4: Calculate ri’s in groups of 4 r8 = a8+b8+C2 r9 = a9+b9+g8+(p8∙C2) r10 = a10+b10+g9+(p9∙g8)+(p9∙p8∙C2) r11 = a11+b11+g10+(p10∙g9)+(p10∙p9∙g8)+(p10∙p9∙p8∙C2) 0 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 1 0 1 1 0 0 0 0
Step 4: Calculate ri’s in groups of 4 r12 = a12+b12+C3 r13 = a13+b13+g12+(p12∙C3) r14 = a14+b14+g13+(p13∙g12)+(p13∙p12∙C3) r15 = a15+b15+g14+(p14∙g13)+(p14∙p13∙g12)+(p14∙p13∙p12∙C3) 0 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 1 1 0 0 0 0 0 0 1 0 1 1
Final Result a = 31980 b = -16354 = 0111110011101100 = 1100000000011110 0 1 1 0 0 0 1 1 r = 15626 = 0011110100001010 1 1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 1 0 1 1 1 1 0 0