This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[JAVA] Generate fconst_2 bytecode
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org, <java-patches at gcc dot gnu dot org>
- Cc: Andrew Haley <aph at redhat dot com>
- Date: Wed, 17 Sep 2003 20:52:55 -0600 (MDT)
- Subject: [JAVA] Generate fconst_2 bytecode
Whilst investigating optimal JVM bytecode sequences for min and max,
I noticed a FIXME in jcf-write.c's generate_bytecode_insns. It turns
out that we're not currently generating the fconst_2 instruction to
load 2.0f onto the stack. The simple patch below adds the necessary
tests to fix this. Note, there is no dconst_2 bytecode.
I've downgraded the remaining FIXME item to a ???. Whilst we
could generate bytecode sequences such as "iconst_3 ; i2d" to load
the floating point value 3.0 onto the operand stack (instead of
"ldc 3.0"), I'm not sure that this would be a performance win on
most interpreters. However, if someone has a table of timings to
prove otherwise, implementing this optimization should be easy.
The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all languages except treelang, and regression tested
with a top-level "make -k check" with no new failures.
Ok for mainline?
2003-09-17 Roger Sayle <roger@eyesopen.com>
* jcf-write.c (generate_bytecode_insns): Add support for fconst_2.
Index: jcf-write.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-write.c,v
retrieving revision 1.130
diff -c -3 -p -r1.130 jcf-write.c
*** jcf-write.c 12 Aug 2003 20:34:51 -0000 1.130
--- jcf-write.c 17 Sep 2003 22:30:29 -0000
*************** generate_bytecode_insns (tree exp, int t
*** 1462,1469 ****
OP1 (prec == 1 ? OPCODE_fconst_0 : OPCODE_dconst_0);
else if (real_onep (exp))
OP1 (prec == 1 ? OPCODE_fconst_1 : OPCODE_dconst_1);
! /* FIXME Should also use fconst_2 for 2.0f.
! Also, should use iconst_2/ldc followed by i2f/i2d
for other float/double when the value is a small integer. */
else
{
--- 1462,1470 ----
OP1 (prec == 1 ? OPCODE_fconst_0 : OPCODE_dconst_0);
else if (real_onep (exp))
OP1 (prec == 1 ? OPCODE_fconst_1 : OPCODE_dconst_1);
! else if (prec == 1 && real_twop (exp))
! OP1 (OPCODE_fconst_2);
! /* ??? We could also use iconst_3/ldc followed by i2f/i2d
for other float/double when the value is a small integer. */
else
{
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833