This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Java PATCH: Fix increments of floats/doubles


This seems like a better patch.  It actually simplifies the compiler
in addition to generating better code.

        * jcf-write.c  (generate_bytecode_insns):  For increments and
        decrements just recurse to push constant.  This handles reals as well.

Index: jcf-write.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-write.c,v
retrieving revision 1.83
diff -p -u -r1.83 jcf-write.c
--- jcf-write.c	2001/08/17 21:07:07	1.83
+++ jcf-write.c	2001/08/28 18:42:23
@@ -1442,7 +1442,7 @@ generate_bytecode_insns (exp, target, st
      int target;
      struct jcf_partial *state;
 {
-  tree type;
+  tree type, arg;
   enum java_opcode jopcode;
   int op;
   HOST_WIDE_INT value;
@@ -1908,6 +1908,7 @@ generate_bytecode_insns (exp, target, st
     case POSTINCREMENT_EXPR: value =  1; post_op = 1;  goto increment;
     increment:
 
+      arg = TREE_OPERAND (exp, 1);
       exp = TREE_OPERAND (exp, 0);
       type = TREE_TYPE (exp);
       size = TYPE_IS_WIDE (type) ? 2 : 1;
@@ -1960,12 +1961,10 @@ generate_bytecode_insns (exp, target, st
       /* Stack, if ARRAY_REF:  ..., [result, ] array, index, oldvalue. */
       /* Stack, if COMPONENT_REF:  ..., [result, ] objectref, oldvalue. */
       /* Stack, otherwise:  ..., [result, ] oldvalue. */
-      if (size == 1)
-	push_int_const (value, state);
-      else
-	push_long_const (value, (HOST_WIDE_INT)(value >= 0 ? 0 : -1), state);
-      NOTE_PUSH (size);
-      emit_binop (OPCODE_iadd + adjust_typed_op (type, 3), type, state);
+      generate_bytecode_insns (arg, STACK_TARGET, state);
+      emit_binop ((value >= 0 ? OPCODE_iadd : OPCODE_isub)
+		  + adjust_typed_op (type, 3),
+		  type, state);
       if (target != IGNORE_TARGET && ! post_op)
 	emit_dup (size, offset, state);
       /* Stack, if ARRAY_REF:  ..., [result, ] array, index, newvalue. */



-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]