diff --git a/core/c/jbigi/README b/core/c/jbigi/README index 56560a94f..b95ee78fe 100644 --- a/core/c/jbigi/README +++ b/core/c/jbigi/README @@ -9,9 +9,19 @@ TODO: Document generated folder structure TODO: Instructions for adding the libraries to a jar Linux-specific information: +=========================== Some linux distributions comes bundled with GMP. -There is currently no out-of-the-box support for this in the current build-scripts. +Try 'locate lib/libgmp.so' to see. +If so, install the the libgmp3-dev debian package to get the libgmp headers. +Then export I2P=/path/to/your/i2p/install. +Then do 'build.sh dynamic'. This will do a quick build using your installed libgmp library +and then test it and the jbigi in your I2P installation to see which is faster. + +If the new jbigi is slower, then run 'build.sh' (without the 'dynamic'), which will download +the 4.3.1 libgmp library, build, and test that. + Windows-specific information: +============================= The best way of building the jbigi dll's is to install Mingw {URL} and msys {URL}. The combination of these two should be able to run the included build-scripts without modifications. diff --git a/core/c/jbigi/jbigi/src/jbigi.c b/core/c/jbigi/jbigi/src/jbigi.c index b0d702310..f605c6a0e 100644 --- a/core/c/jbigi/jbigi/src/jbigi.c +++ b/core/c/jbigi/jbigi/src/jbigi.c @@ -57,33 +57,6 @@ JNIEXPORT jbyteArray JNICALL Java_net_i2p_util_NativeBigInteger_nativeModPow return jresult; } -/******** nativeDoubleValue() */ -/* - * Class: net_i2p_util_NativeBigInteger - * Method: nativeDoubleValue - * Signature: ([B)D - * - * From the Javadoc: - * - * Converts a BigInteger byte-array to a 'double' - * @param ba Big endian twos complement representation of the BigInteger to convert to a double - * @return The plain double-value represented by 'ba' - */ -JNIEXPORT jdouble JNICALL Java_net_i2p_util_NativeBigInteger_nativeDoubleValue -(JNIEnv * env, jclass cls, jbyteArray jba){ - /* 1) Convert the bytearray BigInteger value into the format libgmp understands - * 2) Call libgmp's mpz_get_d. - * 3) Convert libgmp's result into a big endian twos complement number. - */ - mpz_t mval; - jdouble retval; - convert_j2mp(env, jba, &mval); - - retval = mpz_get_d(mval); - mpz_clear(mval); - return retval; -} - /****************************** *****Conversion methods******* ******************************/ diff --git a/core/java/src/net/i2p/util/NativeBigInteger.java b/core/java/src/net/i2p/util/NativeBigInteger.java index 9e98c5855..8c41746f4 100644 --- a/core/java/src/net/i2p/util/NativeBigInteger.java +++ b/core/java/src/net/i2p/util/NativeBigInteger.java @@ -28,8 +28,7 @@ import net.i2p.I2PAppContext; /** *

BigInteger that takes advantage of the jbigi library for the modPow operation, * which accounts for a massive segment of the processing cost of asymmetric - * crypto. It also takes advantage of the jbigi library for converting a BigInteger - * value to a double. Sun's implementation of the 'doubleValue()' method is _very_ lousy. + * crypto. * * The jbigi library itself is basically just a JNI wrapper around the * GMP library - a collection of insanely efficient routines for dealing with @@ -64,7 +63,7 @@ import net.i2p.I2PAppContext; * "net/i2p/util/jbigi-windows-none.dll").

* *

Running this class by itself does a basic unit test and benchmarks the - * NativeBigInteger.modPow/doubleValue vs. the BigInteger.modPow/doubleValue by running a 2Kbit op 100 + * NativeBigInteger.modPow vs. the BigInteger.modPow by running a 2Kbit op 100 * times. At the end of each test, if the native implementation is loaded this will output * something like:

*
@@ -194,14 +193,6 @@ public class NativeBigInteger extends BigInteger {
      */
     public native static byte[] nativeModPow(byte base[], byte exponent[], byte modulus[]);
  
-    /**
-     * Converts a BigInteger byte-array to a 'double'
-     * @param ba Big endian twos complement representation of the BigInteger to convert to a double
-     * @return The plain double-value represented by 'ba'
-     * @deprecated unused
-     */
-    public native static double nativeDoubleValue(byte ba[]);
-
     private byte[] cachedBa;
 
     public NativeBigInteger(byte[] val) {
@@ -250,12 +241,9 @@ public class NativeBigInteger extends BigInteger {
         return cachedBa;
     }
     
-    /** @deprecated unused */
+    /** @deprecated unused, does not call native */
     @Override
     public double doubleValue() {
-        if (_nativeOk)
-            return nativeDoubleValue(toByteArray());
-        else
             return super.doubleValue();
     }
     /**
@@ -281,7 +269,7 @@ public class NativeBigInteger extends BigInteger {
     }
  
     /**
-     * 

Compare the BigInteger.modPow/doubleValue vs the NativeBigInteger.modPow/doubleValue of some + *

Compare the BigInteger.modPow vs the NativeBigInteger.modPow of some * really big (2Kbit) numbers 100 different times and benchmark the * performance (or shit a brick if they don't match).

* @@ -289,8 +277,6 @@ public class NativeBigInteger extends BigInteger { public static void main(String args[]) { _doLog = true; runModPowTest(100); - // i2p doesn't care about the double values - //runDoubleValueTest(100); } /* the sample numbers are elG generator/prime so we can test with reasonable numbers */ @@ -361,64 +347,6 @@ public class NativeBigInteger extends BigInteger { } } -/******** - private static void runDoubleValueTest(int numRuns) { - System.out.println("DEBUG: Warming up the random number generator..."); - SecureRandom rand = new SecureRandom(); - rand.nextBoolean(); - System.out.println("DEBUG: Random number generator warmed up"); - - BigInteger jg = new BigInteger(_sampleGenerator); - - long totalTime = 0; - long javaTime = 0; - - int MULTIPLICATOR = 50000; //Run the doubleValue() calls within a loop since they are pretty fast.. - int runsProcessed = 0; - for (runsProcessed = 0; runsProcessed < numRuns; runsProcessed++) { - NativeBigInteger g = new NativeBigInteger(_sampleGenerator); - long beforeDoubleValue = System.currentTimeMillis(); - double dNative=0; - for(int mult=0;multDo whatever we can to load up the native library backing this BigInteger's native methods. * If it can find a custom built jbigi.dll / libjbigi.so, it'll use that. Otherwise