harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r646262 - in /harmony/enhanced/drlvm/trunk: src/test/microbenchmark/harmony-5480/ src/test/regression/H5480/ vm/jitrino/src/codegenerator/ia32/ vm/jitrino/src/optimizer/
Date Wed, 09 Apr 2008 10:51:18 GMT
Author: varlax
Date: Wed Apr  9 03:50:57 2008
New Revision: 646262

URL: http://svn.apache.org/viewvc?rev=646262&view=rev
Log:
Postfix to HARMONY-5480:
- not appropriate magic for int/long ABS;
- bad signature used for ATAN2;
- incorrect magic for ATAN2 (it should give results ranged as (-Pi,Pi) but gave (-Pi/2,Pi/2))
Regression test provided.
BTW, sin/cos/tan now have lesser accuracy than required by spec (~10units vs 1 ulp).

Added:
    harmony/enhanced/drlvm/trunk/src/test/microbenchmark/harmony-5480/
    harmony/enhanced/drlvm/trunk/src/test/microbenchmark/harmony-5480/MathTest.java   (with
props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H5480/
    harmony/enhanced/drlvm/trunk/src/test/regression/H5480/LooseMathTest.java   (with props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H5480/run.test.xml   (with props)
Modified:
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ia32/Ia32APIMagics.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp

Added: harmony/enhanced/drlvm/trunk/src/test/microbenchmark/harmony-5480/MathTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/microbenchmark/harmony-5480/MathTest.java?rev=646262&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/microbenchmark/harmony-5480/MathTest.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/microbenchmark/harmony-5480/MathTest.java Wed Apr
 9 03:50:57 2008
@@ -0,0 +1,40 @@
+package math;
+
+/**
+ * A microbenchmark on trigonometric/logarithmic math methods.
+ * On DRLVM, specific optimization can be switched on/off from commandline: 
+ * -XX:jit.arg.Math_as_magic=true/false.
+ */
+
+public class MathTest {
+	static void f() {
+		Math.abs(-123987.1236d);
+		Math.asin(0.7);
+		Math.acos(0.7);		
+		Math.log(123.123);
+		Math.log10(123.123);
+		Math.log1p(123.123);		
+		Math.sin(12312.123);
+		Math.cos(12312.123);
+		Math.sqrt(234234.234234);
+		Math.tan(234234.12342134);
+		Math.atan(2347.234);
+		Math.atan2(231.123, 0);
+		Math.abs(-123.1231123f);				
+	}
+    public static void main(String[] args) {    	
+    	System.out.println("Warmup started....");
+    	for (int i = 0; i < 2500 * 2500; i ++) {
+		     f();
+		}
+    	for (int i = 0; i < 250 * 2500; i ++) {
+		     f();
+		}
+    	System.out.println("Warmup ended....");
+    	long start = System.currentTimeMillis();		
+		for (int i = 0; i < 2500 * 2500; i ++) {
+    		f();
+		}
+		System.out.println("floor result: " + (System.currentTimeMillis() - start));	
+	}
+}

Propchange: harmony/enhanced/drlvm/trunk/src/test/microbenchmark/harmony-5480/MathTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H5480/LooseMathTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H5480/LooseMathTest.java?rev=646262&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H5480/LooseMathTest.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H5480/LooseMathTest.java Wed Apr  9 03:50:57
2008
@@ -0,0 +1,130 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.drlvm.tests.regression.h5480;
+
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+public class LooseMathTest extends TestCase {
+    static {
+        // Let lazy resolution (if any) ramp up
+        Math.class.hashCode();
+    }
+    static Random rnd = new Random();
+
+    public void testABS() throws Exception {
+        int i = rnd.nextInt();
+        assertEquals("int " + i, StrictMath.abs(i), Math.abs(i));
+        long j = rnd.nextLong();
+        assertEquals("long " + j, StrictMath.abs(j), Math.abs(j));
+        float f = rnd.nextInt() * rnd.nextFloat();
+        assertEquals("float " + f, StrictMath.abs(f), Math.abs(f));
+        double d = rnd.nextInt() * rnd.nextDouble();
+        assertEquals("d=" + d, StrictMath.abs(d), Math.abs(d));
+    }
+
+    public void testSQRT() throws Exception {
+        double d = rnd.nextInt() * rnd.nextDouble();
+        d *= Math.signum(d);
+        double ulp = Math.ulp(StrictMath.sqrt(d));
+        assertEquals("d=" + d + " ulp="+ulp, StrictMath.sqrt(d), Math.sqrt(d), ulp);
+    }
+
+    public void testSIN() throws Exception {
+        double d = rnd.nextInt() * rnd.nextDouble();
+        //x87 trigonometry is less accurate...
+        double ulp = 1.e-9; //Math.ulp(StrictMath.sin(d));
+        assertEquals("d=" + d + " ulp="+ulp, StrictMath.sin(d), Math.sin(d), ulp);
+    }
+    
+    public void testASIN() throws Exception {
+        double d = rnd.nextDouble();
+        double ulp = Math.ulp(StrictMath.asin(d));
+        assertEquals("d=" + d + " ulp="+ulp, StrictMath.asin(d), Math.asin(d), ulp);
+    }
+
+    public void testCOS() throws Exception {
+        double d = rnd.nextInt() * rnd.nextDouble();
+        //x87 trigonometry is less accurate...
+        double ulp = 1.e-9; //Math.ulp(StrictMath.cos(d));
+        assertEquals("d=" + d + " ulp="+ulp, StrictMath.cos(d), Math.cos(d), ulp);
+    }
+
+    public void testACOS() throws Exception {
+        double d = rnd.nextDouble();
+        double ulp = Math.ulp(StrictMath.acos(d));
+        assertEquals("d=" + d + " ulp="+ulp, StrictMath.acos(d), Math.acos(d), ulp);
+    }
+
+    public void testTAN() throws Exception {
+        double d = rnd.nextInt() * rnd.nextDouble();
+        //x87 trigonometry is less accurate...
+        double ulp = 1.e-9; //Math.ulp(StrictMath.tan(d));
+        assertEquals("d=" + d + " ulp="+ulp, StrictMath.tan(d), Math.tan(d), ulp);
+    }
+
+    public void testATAN() throws Exception {
+        double d = rnd.nextInt() * rnd.nextDouble();
+        double ulp = Math.ulp(StrictMath.atan(d));
+        assertEquals("d=" + d + " ulp="+ulp, StrictMath.atan(d), Math.atan(d), ulp);
+    }
+    
+    public void testLOG() throws Exception {
+        double d = rnd.nextInt() * rnd.nextDouble();
+        d *= Math.signum(d);
+        double ulp = Math.ulp(StrictMath.log(d));
+        assertEquals("d=" + d + " ulp="+ulp, StrictMath.log(d), Math.log(d), ulp);
+    }
+
+    public void testLOG10() throws Exception {
+        double d = rnd.nextInt() * rnd.nextDouble();
+        d *= Math.signum(d);
+        double ulp = Math.ulp(StrictMath.log10(d));
+        assertEquals("d=" + d + " ulp="+ulp, StrictMath.log10(d), Math.log10(d), ulp);
+    }
+
+    public void testLOG1P() throws Exception {
+        double d = rnd.nextInt() * rnd.nextDouble();
+        d *= Math.signum(d);
+        double ulp = Math.ulp(StrictMath.log1p(d));
+        assertEquals("d=" + d + " ulp="+ulp, StrictMath.log1p(d), Math.log1p(d), ulp);
+
+        d = rnd.nextDouble();
+        ulp = Math.ulp(StrictMath.log1p(d));
+        assertEquals("small d=" + d + " ulp="+ulp, StrictMath.log1p(d), Math.log1p(d), ulp);
+    }
+
+    public void testATAN2() throws Exception {
+        double d1 = rnd.nextInt() * rnd.nextDouble();
+        double d2 = rnd.nextInt() * rnd.nextDouble();
+        assertEquals("d1=" + d1 + " d2=" + d2, 
+                StrictMath.atan2(d1,d2), Math.atan2(d1,d2), Math.ulp(StrictMath.atan2(d1,d2)));
+        double q1 = Math.atan2(1, 1);
+        double q2 = Math.atan2(1, -1);
+        double q3 = Math.atan2(-1, -1);
+        double q4 = Math.atan2(-1, 1);
+        //System.out.println(q1+"\n"+q2+"\n"+q3+"\n"+q4+"\n");
+        
+        assertTrue("q1="+q1, q1 > 0 && q1 < Math.PI/2);
+        assertTrue("q2="+q2, q2 > Math.PI/2 && q1 < Math.PI);
+        assertTrue("q3="+q3, q3 < -Math.PI/2 && q1 > -Math.PI);
+        assertTrue("q4="+q4, q4 < 0 && q1 > -Math.PI/2);
+    }
+}
+

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H5480/LooseMathTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H5480/run.test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H5480/run.test.xml?rev=646262&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H5480/run.test.xml (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H5480/run.test.xml Wed Apr  9 03:50:57
2008
@@ -0,0 +1,33 @@
+<!-- 
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+     
+         http://www.apache.org/licenses/LICENSE-2.0
+     
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License. -->
+
+<project name="RUN HARMONY-5480 Regression Test">
+    <target name="run-test">
+        <run-junit-test 
+             test="org.apache.harmony.drlvm.tests.regression.h5480.LooseMathTest"
+             vmarg="-Xem:jet">
+        </run-junit-test>
+        <!--run-junit-test 
+             test="org.apache.harmony.drlvm.tests.regression.h5206.VolatileLongTest"
+             vmarg="-Xint">
+        </run-junit-test-->
+        <run-junit-test 
+             test="org.apache.harmony.drlvm.tests.regression.h5480.LooseMathTest"
+             vmarg="-Xem:opt">
+        </run-junit-test>
+    </target>
+</project>
+

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H5480/run.test.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ia32/Ia32APIMagics.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ia32/Ia32APIMagics.cpp?rev=646262&r1=646261&r2=646262&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ia32/Ia32APIMagics.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/codegenerator/ia32/Ia32APIMagics.cpp Wed Apr
 9 03:50:57 2008
@@ -181,21 +181,17 @@
                                 if (!strcmp(methodName, "atan")) {                      
             
                                        handlers.push_back(new (tmpMM) Math_Handler_x_D_x_D(irm,
callInst, md, ATAN)); 
                                 }
-                                if (!strcmp(methodName, "atan2")) {                     
             
-                                       handlers.push_back(new (tmpMM) Math_Handler_x_D_x_D(irm,
callInst, md, ATAN2)); 
-                                }
                                 if (!strcmp(methodName, "asin")) {                      
             
                                        handlers.push_back(new (tmpMM) Math_Handler_x_D_x_D(irm,
callInst, md, ASIN)); 
                                 }
                                 if (!strcmp(methodName, "acos")) {                      
             
                                        handlers.push_back(new (tmpMM) Math_Handler_x_D_x_D(irm,
callInst, md, ACOS)); 
                                 }
-                            } else {
-                                if (!strcmp(methodName, "abs")) {                       
            
-                                       handlers.push_back(new (tmpMM) Math_Handler_x_D_x_D(irm,
callInst, md, ABS, Mnemonic_FABS)); 
-                                }
-                            }                                                           
                                                                                         
        
-                                
+                            } else if (!strcmp(signature, "(F)F") && !strcmp(methodName,
"abs")) {
+                                handlers.push_back(new (tmpMM) Math_Handler_x_D_x_D(irm,
callInst, md, ABS, Mnemonic_FABS));
+                            } else if (!strcmp(signature, "(DD)D") && !strcmp(methodName,
"atan2")) {
+                                handlers.push_back(new (tmpMM) Math_Handler_x_D_x_D(irm,
callInst, md, ATAN2)); 
+                            }
                         }
 #endif
                     } else if( ri->getKind() == Opnd::RuntimeInfo::Kind_InternalHelperAddress
) {
@@ -277,14 +273,14 @@
              }                 
              node->appendInst(irm->newInst(Mnemonic_FYL2X, fp0));        
              break;
-         case ATAN: case ATAN2:
-             node->appendInst(irm->newInst(Mnemonic_FLD, fp0, arg));              
  
-             if (func == ATAN2) {
-                 node->appendInst(irm->newInst(Mnemonic_FLD, fp0, 
-                                               getCallSrc(callInst, 1))); 
-                 node->appendInst(irm->newInst(Mnemonic_FDIVP, fp0));         
-             } 
-             node->appendInst(irm->newInst(Mnemonic_FLD1, fp0));                 
+         case ATAN:
+             node->appendInst(irm->newInst(Mnemonic_FLD, fp0, arg));
+             node->appendInst(irm->newInst(Mnemonic_FLD1, fp0));
+             node->appendInst(irm->newInst(Mnemonic_FPATAN, fp0));
+             break;
+         case ATAN2:
+             node->appendInst(irm->newInst(Mnemonic_FLD, fp0, arg));
+             node->appendInst(irm->newInst(Mnemonic_FLD, fp0, getCallSrc(callInst,
1)));
              node->appendInst(irm->newInst(Mnemonic_FPATAN, fp0));        
              break;
          case ASIN: case ACOS:

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp?rev=646262&r1=646261&r2=646262&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp Wed Apr  9 03:50:57
2008
@@ -137,23 +137,16 @@
             _inlineSkipMethodTable->add_method_record("java/lang/Math", "sqrt", "(D)D",
des, false); 
             _inlineSkipMethodTable->add_method_record("java/lang/Math", "sin", "(D)D",
des, false); 
             _inlineSkipMethodTable->add_method_record("java/lang/Math", "cos", "(D)D",
des, false); 
-            _inlineSkipMethodTable->add_method_record("java/lang/Math", "abs", "(J)J",
des, false);
-            _inlineSkipMethodTable->add_method_record("java/lang/Math", "abs", "(I)I",
des, false); 
-            _inlineSkipMethodTable->add_method_record("java/lang/Math", "abs", "(J)J",
des, false);
             _inlineSkipMethodTable->add_method_record("java/lang/Math", "abs", "(F)F",
des, false);            
             _inlineSkipMethodTable->add_method_record("java/lang/Math", "abs", "(D)D",
des, false); 
             _inlineSkipMethodTable->add_method_record("java/lang/Math", "tan", "(D)D",
des, false);           
             _inlineSkipMethodTable->add_method_record("java/lang/Math", "atan", "(D)D",
des, false);  
-            _inlineSkipMethodTable->add_method_record("java/lang/Math", "atan2", "(D)D",
des, false);  
+            _inlineSkipMethodTable->add_method_record("java/lang/Math", "atan2", "(DD)D",
des, false);  
             _inlineSkipMethodTable->add_method_record("java/lang/Math", "asin", "(D)D",
des, false); 
             _inlineSkipMethodTable->add_method_record("java/lang/Math", "acos", "(D)D",
des, false);                         
             _inlineSkipMethodTable->add_method_record("java/lang/Math", "log", "(D)D",
des, false);           
             _inlineSkipMethodTable->add_method_record("java/lang/Math", "log10", "(D)D",
des, false);           
             _inlineSkipMethodTable->add_method_record("java/lang/Math", "log1p", "(D)D",
des, false);           
-
-
-            
-
 #endif
             if(argSource->getBoolArg("System_arraycopy_as_magic",true)) {
                 _inlineSkipMethodTable->add_method_record("java/lang/System", "arraycopy",
"(Ljava/lang/Object;ILjava/lang/Object;II)V", des, false);



Mime
View raw message