diff options
Diffstat (limited to 'zpu/sw/simulator/com/zylin/zpu/stats')
4 files changed, 225 insertions, 0 deletions
diff --git a/zpu/sw/simulator/com/zylin/zpu/stats/CountSequences.java b/zpu/sw/simulator/com/zylin/zpu/stats/CountSequences.java new file mode 100644 index 0000000..0f06aec --- /dev/null +++ b/zpu/sw/simulator/com/zylin/zpu/stats/CountSequences.java @@ -0,0 +1,94 @@ +/* + * Created on Jan 18, 2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package com.zylin.zpu.stats; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +import com.zylin.zpu.simulator.Machine; + +public class CountSequences implements Machine +{ + + private byte[] array; + private StatKeeper statKeeper; + + public static void main(String[] args) + { + new CountSequences().run(args[0]); + } + + private void run(String string) + { + try + { + File file=new File(string); + if (file.exists()) + System.out.println("It exists!"); + FileInputStream in=new FileInputStream(file); + + try + { + array=new byte[(int) file.length()]; + + if (in.read(array)!=array.length) + throw new IOException(); + + countStats(); + + statKeeper.printStats(); + } finally + { + in.close(); + } + + } catch (FileNotFoundException e) + { + e.printStackTrace(); + } catch (IOException e) + { + e.printStackTrace(); + } + + + } + + + private void countStats() + { + statKeeper=new StatKeeper(this); + for (int i=0; i<array.length; i++) + { + int j = array[i]&0xff; +// +// if ((j>=64)&&(j<96)) +// { +// j=64; +// } else if ((j>=96)&&(j<128)) +// { +// j=96; +// } else if ((j>=128)&&(j<256)) +// { +// j=128; +// } + statKeeper.countInstruction(j); + } + + } + + public long getPrevCycles() + { + return 0; + } + + public long getCycles() + { + return 0; + } +} diff --git a/zpu/sw/simulator/com/zylin/zpu/stats/DumpIt.java b/zpu/sw/simulator/com/zylin/zpu/stats/DumpIt.java new file mode 100644 index 0000000..80be11d --- /dev/null +++ b/zpu/sw/simulator/com/zylin/zpu/stats/DumpIt.java @@ -0,0 +1,17 @@ +/* + * Created on 26.nov.2004 + * + * To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package com.zylin.zpu.stats; +/** + * @author oyvind + * + * To change the template for this generated type comment go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +public interface DumpIt +{ + int dumpIt(int i); +}
\ No newline at end of file diff --git a/zpu/sw/simulator/com/zylin/zpu/stats/Instruction.java b/zpu/sw/simulator/com/zylin/zpu/stats/Instruction.java new file mode 100644 index 0000000..252dd7f --- /dev/null +++ b/zpu/sw/simulator/com/zylin/zpu/stats/Instruction.java @@ -0,0 +1,62 @@ +package com.zylin.zpu.stats; + +public class Instruction +{ + public class DumpCycles implements DumpIt + { + public int dumpIt(int i) + { + return insn[i].cycles; + } + } + + + + public Instruction[] insn=new Instruction[256]; + public int count; + public int cycles; + + public Instruction addInstruction(int i) + { + if (insn[i]==null) + { + insn[i]=new Instruction(); + } + return insn[i]; + } + + /** + * Recursive print of statistics + */ + public void printStats() + { + System.out.println("Count dump"); + DumpIt cDump = new DumpCount(); + printCount("", cDump); + } + + /** + * Recursive print of counts + * @param string + * @param dumpIt TODO + */ + private void printCount(String string, DumpIt dumpIt) + { + for (int i=0; i<insn.length; i++) + { + if (insn[i]!=null) + { + insn[i].printCount(string + ", " + i, dumpIt); + System.out.println("Count: " + insn[i].count + string + ", " + i); + } + } + } + + class DumpCount implements DumpIt + { + public int dumpIt(int i) + { + return insn[i].count; + } + } +} diff --git a/zpu/sw/simulator/com/zylin/zpu/stats/StatKeeper.java b/zpu/sw/simulator/com/zylin/zpu/stats/StatKeeper.java new file mode 100644 index 0000000..9e16e32 --- /dev/null +++ b/zpu/sw/simulator/com/zylin/zpu/stats/StatKeeper.java @@ -0,0 +1,52 @@ +package com.zylin.zpu.stats; + +import com.zylin.zpu.simulator.Machine; +import com.zylin.zpu.simulator.State; + +public class StatKeeper +{ + private Instruction top=new Instruction(); + private int trackPos; + + private State[] state = new State[3]; + private Machine simulator; + /** + * @param simulator + */ + public StatKeeper(Machine simulator) + { + this.simulator=simulator; + for (int i=0; i<state.length; i++) + { + state[i]=new State(); + } + } + /** + * this instruction has been retired. Count it. + */ + public void countInstruction(int instruction) + { + State currentState=state[trackPos%state.length]; + currentState.cycle=simulator.getPrevCycles(); // start of instruction + currentState.insn=instruction; + trackPos++; + int backtrackNum; + backtrackNum=Math.min(trackPos, state.length); + for (int i=0; i<backtrackNum; i++) + { + Instruction t=top; + for (int j=0; j<=i; j++) + { + currentState=state[(trackPos-backtrackNum+j)%state.length]; + t=t.addInstruction(currentState.insn); + } + t.count++; + } + + } + public void printStats() + { + top.printStats(); + + } +} |