Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

float a = 1+1; costs 17 bytecode. #400

Open
revalo opened this issue Jan 13, 2017 · 3 comments
Open

float a = 1+1; costs 17 bytecode. #400

revalo opened this issue Jan 13, 2017 · 3 comments

Comments

@revalo
Copy link

revalo commented Jan 13, 2017

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 revalo closed this as completed Jan 14, 2017
@nmccoy
Copy link
Contributor

nmccoy commented Jan 14, 2017

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

@kazimuth
Copy link
Contributor

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 kazimuth reopened this Jan 14, 2017
@kazimuth
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants