Changeset 08d24b0


Ignore:
Timestamp:
Jan 18, 2011 2:05:26 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
ff520b7
Parents:
18119890
Message:

remove nativeDoubleValue(), update jbigi README

Location:
core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • core/c/jbigi/README

    r18119890 r08d24b0  
    1010
    1111Linux-specific information:
     12===========================
    1213Some linux distributions comes bundled with GMP.
    13 There is currently no out-of-the-box support for this in the current build-scripts.
     14Try 'locate lib/libgmp.so' to see.
     15If so, install the the libgmp3-dev debian package to get the libgmp headers.
     16Then export I2P=/path/to/your/i2p/install.
     17Then do 'build.sh dynamic'. This will do a quick build using your installed libgmp library
     18and then test it and the jbigi in your I2P installation to see which is faster.
     19
     20If the new jbigi is slower, then run 'build.sh' (without the 'dynamic'), which will download
     21the 4.3.1 libgmp library, build, and test that.
     22
    1423
    1524Windows-specific information:
     25=============================
    1626The best way of building the jbigi dll's is to install Mingw {URL} and msys {URL}.
    1727The combination of these two should be able to run the included build-scripts without modifications.
  • core/c/jbigi/jbigi/src/jbigi.c

    r18119890 r08d24b0  
    5656
    5757        return jresult;
    58 }
    59 
    60 /******** nativeDoubleValue() */
    61 /*
    62  * Class:     net_i2p_util_NativeBigInteger
    63  * Method:    nativeDoubleValue
    64  * Signature: ([B)D
    65  *
    66  * From the Javadoc:
    67  *
    68  * Converts a BigInteger byte-array to a 'double'
    69  * @param ba Big endian twos complement representation of the BigInteger to convert to a double
    70  * @return The plain double-value represented by 'ba'
    71  */
    72 JNIEXPORT jdouble JNICALL Java_net_i2p_util_NativeBigInteger_nativeDoubleValue
    73 (JNIEnv * env, jclass cls, jbyteArray jba){
    74             /* 1) Convert the bytearray BigInteger value into the format libgmp understands
    75          * 2) Call libgmp's mpz_get_d.
    76          * 3) Convert libgmp's result into a big endian twos complement number.
    77          */
    78         mpz_t mval;
    79                 jdouble retval;
    80         convert_j2mp(env, jba, &mval);
    81 
    82                 retval = mpz_get_d(mval);
    83                 mpz_clear(mval);
    84                 return retval;
    8558}
    8659
  • core/java/src/net/i2p/util/NativeBigInteger.java

    r18119890 r08d24b0  
    2929 * <p>BigInteger that takes advantage of the jbigi library for the modPow operation,
    3030 * which accounts for a massive segment of the processing cost of asymmetric
    31  * crypto. It also takes advantage of the jbigi library for converting a BigInteger
    32  * value to a double. Sun's implementation of the 'doubleValue()' method is _very_ lousy.
     31 * crypto.
    3332 *
    3433 * The jbigi library itself is basically just a JNI wrapper around the
     
    6564 *
    6665 * <p>Running this class by itself does a basic unit test and benchmarks the
    67  * NativeBigInteger.modPow/doubleValue vs. the BigInteger.modPow/doubleValue by running a 2Kbit op 100
     66 * NativeBigInteger.modPow vs. the BigInteger.modPow by running a 2Kbit op 100
    6867 * times.  At the end of each test, if the native implementation is loaded this will output
    6968 * something like:</p>
     
    195194    public native static byte[] nativeModPow(byte base[], byte exponent[], byte modulus[]);
    196195 
    197     /**
    198      * Converts a BigInteger byte-array to a 'double'
    199      * @param ba Big endian twos complement representation of the BigInteger to convert to a double
    200      * @return The plain double-value represented by 'ba'
    201      * @deprecated unused
    202      */
    203     public native static double nativeDoubleValue(byte ba[]);
    204 
    205196    private byte[] cachedBa;
    206197
     
    251242    }
    252243   
    253     /** @deprecated unused */
     244    /** @deprecated unused, does not call native */
    254245    @Override
    255246    public double doubleValue() {
    256         if (_nativeOk)
    257             return nativeDoubleValue(toByteArray());
    258         else
    259247            return super.doubleValue();
    260248    }
     
    282270 
    283271    /**
    284      * <p>Compare the BigInteger.modPow/doubleValue vs the NativeBigInteger.modPow/doubleValue of some
     272     * <p>Compare the BigInteger.modPow vs the NativeBigInteger.modPow of some
    285273     * really big (2Kbit) numbers 100 different times and benchmark the
    286274     * performance (or shit a brick if they don't match).  </p>
     
    290278        _doLog = true;
    291279        runModPowTest(100);
    292         // i2p doesn't care about the double values
    293         //runDoubleValueTest(100);
    294280    }
    295281
     
    362348    }
    363349   
    364 /********
    365     private static void runDoubleValueTest(int numRuns) {
    366         System.out.println("DEBUG: Warming up the random number generator...");
    367         SecureRandom rand = new SecureRandom();
    368         rand.nextBoolean();
    369         System.out.println("DEBUG: Random number generator warmed up");
    370 
    371         BigInteger jg = new BigInteger(_sampleGenerator);
    372 
    373         long totalTime = 0;
    374         long javaTime = 0;
    375 
    376         int MULTIPLICATOR = 50000; //Run the doubleValue() calls within a loop since they are pretty fast..
    377         int runsProcessed = 0;
    378         for (runsProcessed = 0; runsProcessed < numRuns; runsProcessed++) {
    379             NativeBigInteger g = new NativeBigInteger(_sampleGenerator);
    380             long beforeDoubleValue = System.currentTimeMillis();
    381             double dNative=0;
    382             for(int mult=0;mult<MULTIPLICATOR;mult++)
    383                 dNative = g.doubleValue();
    384             long afterDoubleValue = System.currentTimeMillis();
    385             double jval=0;
    386             for(int mult=0;mult<MULTIPLICATOR;mult++)
    387                 jval = jg.doubleValue();
    388             long afterJavaDoubleValue = System.currentTimeMillis();
    389 
    390             totalTime += (afterDoubleValue - beforeDoubleValue);
    391             javaTime += (afterJavaDoubleValue - afterDoubleValue);
    392             if (dNative!=jval) {
    393                 System.err.println("ERROR: [" + runsProcessed + "]\tnative double != java double");
    394                 System.err.println("ERROR: native double value: " + dNative);
    395                 System.err.println("ERROR: java double value: " + jval);
    396                 System.err.println("ERROR: run time: " + totalTime + "ms (" + (totalTime / (runsProcessed + 1)) + "ms each)");
    397                 break;
    398             } else {
    399                 System.out.println("DEBUG: current run time: " + (afterDoubleValue - beforeDoubleValue) + "ms (total: "
    400                                    + totalTime + "ms, " + (totalTime / (runsProcessed + 1)) + "ms each)");
    401             }
    402         }
    403         System.out.println("INFO: run time: " + totalTime + "ms (" + (totalTime / (runsProcessed + 1)) + "ms each)");
    404         if (numRuns == runsProcessed)
    405             System.out.println("INFO: " + runsProcessed + " runs complete without any errors");
    406         else
    407             System.out.println("ERROR: " + runsProcessed + " runs until we got an error");
    408 
    409         if (_nativeOk) {
    410             System.out.println("native run time: \t" + totalTime + "ms (" + (totalTime / (runsProcessed + 1))
    411                                + "ms each)");
    412             System.out.println("java run time:   \t" + javaTime + "ms (" + (javaTime / (runsProcessed + 1)) + "ms each)");
    413             System.out.println("native = " + ((totalTime * 100.0d) / (double) javaTime) + "% of pure java time");
    414         } else {
    415             System.out.println("java run time: \t" + javaTime + "ms (" + (javaTime / (runsProcessed + 1)) + "ms each)");
    416             System.out.println("However, we couldn't load the native library, so this doesn't test much");
    417         }
    418     }
    419 *********/
    420    
    421  
    422350    /**
    423351     * <p>Do whatever we can to load up the native library backing this BigInteger's native methods.
Note: See TracChangeset for help on using the changeset viewer.