Bignum division tune-up. Idea is to move multiplications in front of
[openssl.git] / crypto / bn / bn_asm.c
index 7f4c3ff3b2cdb366d2044697440aa5a834a4aafb..4d3da16a0c9ae173a07be3bb0eb2f1c6f6415df6 100644 (file)
@@ -264,18 +264,20 @@ BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
                else
                        q=h/dh;
 
+               th=q*dh;
+               tl=dl*q;
                for (;;)
                        {
-                       t=(h-q*dh);
+                       t=h-th;
                        if ((t&BN_MASK2h) ||
-                               ((dl*q) <= (
-                                       (t<<BN_BITS4)+
+                               ((tl) <= (
+                                       (t<<BN_BITS4)|
                                        ((l&BN_MASK2h)>>BN_BITS4))))
                                break;
                        q--;
+                       th-=dh;
+                       tl-=dl;
                        }
-               th=q*dh;
-               tl=q*dl;
                t=(tl>>BN_BITS4);
                tl=(tl<<BN_BITS4)&BN_MASK2h;
                th+=t;