battlecode-server-2017 icon indicating copy to clipboard operation
battlecode-server-2017 copied to clipboard

float a = 1+1; costs 17 bytecode.

Open revalo opened this issue 8 years ago • 3 comments

int bc_base = Clock.getBytecodeNum();
float a = 1 + 1;
System.out.println("Bytecode Cost: " + (Clock.getBytecodeNum() - bc_base));

This prints out 17, which I feel shouldn't be the case for an addition.

revalo avatar Jan 13 '17 23:01 revalo

(It was actually 2, and the printing/calculating bytecode part used 15 alone)

nmccoy avatar Jan 14 '17 00:01 nmccoy

float z = 1 + 1;

generates:

 L0
    LINENUMBER 8 L0
    FCONST_2
    FSTORE 1
    LDC 2
    INVOKESTATIC battlecode/instrumenter/inject/RobotMonitor.incrementBytecodes (I)V

Which is what would be expected.

int bc_base = Clock.getBytecodeNum();
float a = 1 + 1;
System.out.println("Bytecode Cost: " + (Clock.getBytecodeNum() - bc_base));
  L0
    LINENUMBER 11 L0
    INVOKESTATIC battlecode/common/Clock.getBytecodeNum ()I
    ISTORE 1
    LDC 1
    INVOKESTATIC battlecode/instrumenter/inject/RobotMonitor.incrementBytecodes (I)V
   L1
    LINENUMBER 12 L1
    FCONST_2
    FSTORE 2
    LDC 2
    INVOKESTATIC battlecode/instrumenter/inject/RobotMonitor.incrementBytecodes (I)V
   L2
    LINENUMBER 13 L2
    GETSTATIC battlecode/instrumenter/inject/System.out : Ljava/io/PrintStream;
    NEW java/lang/StringBuilder
    DUP
    INVOKESPECIAL java/lang/StringBuilder.<init> ()V
    LDC "Bytecode Cost: "
    INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
    LDC 14
    INVOKESTATIC battlecode/instrumenter/inject/RobotMonitor.incrementBytecodes (I)V
    INVOKESTATIC battlecode/common/Clock.getBytecodeNum ()I
    ILOAD 1
    ISUB
    INVOKEVIRTUAL java/lang/StringBuilder.append (I)Ljava/lang/StringBuilder;
    INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String;
    INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
    LDC 12
    INVOKESTATIC battlecode/instrumenter/inject/RobotMonitor.incrementBytecodes (I)V
   L3
    LINENUMBER 14 L3
    LDC 1
    INVOKESTATIC battlecode/instrumenter/inject/RobotMonitor.incrementBytecodes (I)V
    RETURN
   L4
    LOCALVARIABLE rc Lbattlecode/common/RobotController; L0 L4 0
    LOCALVARIABLE bc_base I L1 L4 1
    LOCALVARIABLE a F L2 L4 2
    MAXSTACK = 4
    MAXLOCALS = 3

kazimuth avatar Jan 14 '17 00:01 kazimuth

I still want to look into unexpected bytecode costs, so I'll keep this open.

kazimuth avatar Jan 14 '17 00:01 kazimuth