commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1392813 - /commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DRemTransformer.java
Date Tue, 02 Oct 2012 09:36:30 GMT
Author: luc
Date: Tue Oct  2 09:36:30 2012
New Revision: 1392813

URL: http://svn.apache.org/viewvc?rev=1392813&view=rev
Log:
Avoid using an additional local variable for computing remainder.

Modified:
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DRemTransformer.java

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DRemTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DRemTransformer.java?rev=1392813&r1=1392812&r2=1392813&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DRemTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DRemTransformer.java
Tue Oct  2 09:36:30 2012
@@ -25,7 +25,6 @@ import org.objectweb.asm.tree.AbstractIn
 import org.objectweb.asm.tree.InsnList;
 import org.objectweb.asm.tree.InsnNode;
 import org.objectweb.asm.tree.MethodInsnNode;
-import org.objectweb.asm.tree.VarInsnNode;
 
 /** Differentiation transformer for DREM instructions.
  * @version $Id$
@@ -41,8 +40,11 @@ public class DRemTransformer implements 
     /** Name of the {@link org.apache.commons.math3.analysis.differentiation.DerivativeStructure}
method corresponding to the multiplication. */
     private static final String MULTIPLY_METHOD = "multiply";
 
-    /** Name of the {@link org.apache.commons.math3.analysis.differentiation.DerivativeStructure}
method corresponding to the addition. */
-    private static final String ADD_METHOD = "add";
+    /** Name of the {@link org.apache.commons.math3.analysis.differentiation.DerivativeStructure}
method corresponding to the subtraction. */
+    private static final String SUBTRACT_METHOD = "subtract";
+
+    /** Name of the {@link org.apache.commons.math3.analysis.differentiation.DerivativeStructure}
method corresponding to the negation. */
+    private static final String NEGATE_METHOD = "negate";
 
     /** Indicator for top stack element conversion. */
     private final boolean stack0Converted;
@@ -78,34 +80,38 @@ public class DRemTransformer implements 
             }
         } else {
 
-            // set up a temporary variable
-            final int tmp1 = methodDifferentiator.getTmp(1);
-
             // operand stack initial state: a, ds_b
             list.add(new InsnNode(Opcodes.DUP_X2));                                     
      // => ds_b, a, ds_b
             list.add(new InsnNode(Opcodes.POP));                                        
      // => ds_b, a
-            list.add(new VarInsnNode(Opcodes.DSTORE, tmp1));                            
      // => ds_b
-            list.add(new InsnNode(Opcodes.DUP));                                        
      // => ds_b, ds_b
+            list.add(new InsnNode(Opcodes.DUP2_X1));                                    
      // => a, ds_b, a
+            list.add(new InsnNode(Opcodes.DUP2_X1));                                    
      // => a, a, ds_b, a
+            list.add(new InsnNode(Opcodes.POP2));                                       
      // => a, a, ds_b
+            list.add(new InsnNode(Opcodes.DUP_X2));                                     
      // => a, ds_b, a, ds_b
             list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, DS_TYPE.getInternalName(),
                                         VALUE_GETTER_METHOD,
-                                        Type.getMethodDescriptor(Type.DOUBLE_TYPE)));   
      // => ds_b, b0
-            list.add(new InsnNode(Opcodes.DUP2));                                       
      // => ds_b, b0, b0
-            list.add(new VarInsnNode(Opcodes.DLOAD,  tmp1));                            
      // => ds_b, b0, b0, a
-            list.add(new InsnNode(Opcodes.DUP2_X2));                                    
      // => ds_b, b0, a, b0, a
-            list.add(new InsnNode(Opcodes.POP2));                                       
      // => ds_b, b0, a, b0
-            list.add(new InsnNode(Opcodes.DREM));                                       
      // => ds_b, b0, a%b0
-            list.add(new VarInsnNode(Opcodes.DLOAD,  tmp1));                            
      // => ds_b, b0, a%b0, a
-            list.add(new InsnNode(Opcodes.DSUB));                                       
      // => ds_b, b0, a%b0-a
-            list.add(new InsnNode(Opcodes.DUP2_X2));                                    
      // => ds_b, a%b0-a, b0, a%b0-a
-            list.add(new InsnNode(Opcodes.POP2));                                       
      // => ds_b, a%b0-a, b0
-            list.add(new InsnNode(Opcodes.DDIV));                                       
      // => ds_b, q=(a%b0-a)/b0
+                                        Type.getMethodDescriptor(Type.DOUBLE_TYPE)));   
      // => a, ds_b, a, b0
+            list.add(new InsnNode(Opcodes.DUP2_X2));                                    
      // => a, ds_b, b0, a, b0
+            list.add(new InsnNode(Opcodes.DUP2_X2));                                    
      // => a, ds_b, b0, b0, a, b0
+            list.add(new InsnNode(Opcodes.POP2));                                       
      // => a, ds_b, b0, b0, a
+            list.add(new InsnNode(Opcodes.DUP2_X2));                                    
      // => a, ds_b, b0, a, b0, a
+            list.add(new InsnNode(Opcodes.DUP2_X2));                                    
      // => a, ds_b, b0, a, a, b0, a
+            list.add(new InsnNode(Opcodes.POP2));                                       
      // => a, ds_b, b0, a, a, b0
+            list.add(new InsnNode(Opcodes.DREM));                                       
      // => a, ds_b, b0, a, a%b0
+            list.add(new InsnNode(Opcodes.DSUB));                                       
      // => a, ds_b, b0, a-a%b0
+            list.add(new InsnNode(Opcodes.DUP2_X2));                                    
      // => a, ds_b, a-a%b0, b0, a-a%b0
+            list.add(new InsnNode(Opcodes.POP2));                                       
      // => a, ds_b, a-a%b0, b0
+            list.add(new InsnNode(Opcodes.DDIV));                                       
      // => a, ds_b, q=(a-a%b0)/b0
             list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, DS_TYPE.getInternalName(),
                                         MULTIPLY_METHOD,
-                                        Type.getMethodDescriptor(DS_TYPE, Type.DOUBLE_TYPE)));
// => q*b
-            list.add(new VarInsnNode(Opcodes.DLOAD,  tmp1));                            
      // => q*b, a
+                                        Type.getMethodDescriptor(DS_TYPE, Type.DOUBLE_TYPE)));
// => a, q*ds_b
+            list.add(new InsnNode(Opcodes.DUP_X2));                                     
      // => q*ds_b, a, q*ds_b
+            list.add(new InsnNode(Opcodes.POP));                                        
      // => q*ds_b, a
+            list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, DS_TYPE.getInternalName(),
+                                        SUBTRACT_METHOD,
+                                        Type.getMethodDescriptor(DS_TYPE, Type.DOUBLE_TYPE)));
// => q*ds_b-a
             list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, DS_TYPE.getInternalName(),
-                                        ADD_METHOD,
-                                        Type.getMethodDescriptor(DS_TYPE, Type.DOUBLE_TYPE)));
// => a+q*b
+                                        NEGATE_METHOD,
+                                        Type.getMethodDescriptor(DS_TYPE)));            
      // => a-q*ds_b
 
         }
 



Mime
View raw message