Code Library Of Others/sgtlaugh/Karatsuba Unrolled.cpp
int mul(int n, int *a, int m, int *b){
    int i, r, c = (n < m ? n : m), d = (n > m ? n : m), *res = buffer + ptr;
    r = 1 << (32 - __builtin_clz(d) - (__builtin_popcount(d) == 1));
    for (i = d; i < r; i++) a[i] = b[i] = 0;
    for (i = c; i < d && n < m; i++) a[i] = 0;
    for (i = c; i < d && m < n; i++) b[i] = 0;

    ptr += (r << 1), karatsuba(r, a, b, res), ptr -= (r << 1);
    for (i = 0; i < (r << 1); i++) a[i] = res[i];
    return (n + m - 1);
}
/// multiplies two polynomial a(degree n) and b(degree m) and returns the result modulo MOD in a
/// returns the degree of the multiplied polynomial
/// note that a and b are changed in the process
multiplies two polynomial a(degree n) and b(degree m) and returns the result modulo MOD in a
returns the degree of the multiplied polynomial
note that a and b are changed in the process
multiplies two polynomial a ( degree n ) and b ( degree m ) and returns the result modulo MOD in a returns the degree of the multiplied polynomial note that a and b are changed in the process
int mul(int n, int *a, int m, int *b){
    int i, r, c = (n < m ? n : m), d = (n > m ? n : m), *res = buffer + ptr;
    r = 1 << (32 - __builtin_clz(d) - (__builtin_popcount(d) == 1));
    for (i = d; i < r; i++) a[i] = b[i] = 0;
    for (i = c; i < d && n < m; i++) a[i] = 0;
    for (i = c; i < d && m < n; i++) b[i] = 0;
    ptr += (r << 1), karatsuba(r, a, b, res), ptr -= (r << 1);
    for (i = 0; i < (r << 1); i++) a[i] = res[i];
    return (n + m - 1);
}
int mul ( int n , int * a , int m , int * b ) { int i , r , c = ( n < m ? n : m ) , d = ( n > m ? n : m ) , * res = buffer + ptr ; r = 1 << ( 32 - __builtin_clz ( d ) - ( __builtin_popcount ( d ) == 1 ) ) ; for ( i = d ; i < r ; i ++ ) a [ i ] = b [ i ] = 0 ; for ( i = c ; i < d && n < m ; i ++ ) a [ i ] = 0 ; for ( i = c ; i < d && m < n ; i ++ ) b [ i ] = 0 ; ptr += ( r << 1 ) , karatsuba ( r , a , b , res ) , ptr -= ( r << 1 ) ; for ( i = 0 ; i < ( r << 1 ) ; i ++ ) a [ i ] = res [ i ] ; return ( n + m - 1 ) ; }
multiplies two polynomial a(degree n) and b(degree m) and returns the result modulo MOD in a
returns the degree of the multiplied polynomial
note that a and b are changed in the process
multiplies two polynomial a ( degree n ) and b ( degree m ) and returns the result modulo MOD in a returns the degree of the multiplied polynomial note that a and b are changed in the process