Skip to content

Commit

Permalink
stats
Browse files Browse the repository at this point in the history
  • Loading branch information
steve committed Jul 17, 2020
1 parent 90acb1b commit 5019450
Show file tree
Hide file tree
Showing 10 changed files with 65,962 additions and 33 deletions.
Binary file added Contrib/at67/PucMon.gt1
Binary file not shown.
1 change: 1 addition & 0 deletions Contrib/at67/RUNPUCMON.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./gtemuAT67 PucMon.gt1 2> logpucmon2.txt
44 changes: 43 additions & 1 deletion Contrib/at67/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ namespace Cpu

std::vector<uint8_t> _RAM;
uint8_t _ROM[ROM_SIZE][2];
uint64_t _ROMexecutionCount[ROM_SIZE];
uint64_t _IRexecutionCount[256];
std::vector<uint8_t*> _romFiles;
RomType _romType = ROMERR;
std::map<std::string, RomType> _romTypeMap = {{"ROMV1", ROMv1}, {"ROMV2", ROMv2}, {"ROMV3", ROMv3}, {"ROMV4", ROMv4}, {"ROMV5A", ROMv5a}, {"DEVROM", DEVROM}};
Expand Down Expand Up @@ -85,7 +87,7 @@ namespace Cpu
}


//#define COLLECT_INST_STATS
#define COLLECT_INST_STATS
#if defined(COLLECT_INST_STATS)
struct InstCount
{
Expand All @@ -104,6 +106,7 @@ namespace Cpu
return (a._count > b._count);
});

fprintf(stderr, "\n**ORIGINAL STATS\n");
for(int i=0; i<_instCounts.size(); i++)
{
float percent = float(_instCounts[i]._count)/float(_totalCount)*100.0f;
Expand All @@ -116,6 +119,21 @@ namespace Cpu

fprintf(stderr, "Total instructions:%lld\n", _totalCount);
fprintf(stderr, "Total percentage:%f\n", _totalPercent);

//--

fprintf(stderr, "\n**NATIVE INSTRUCTIONS\n");
for(int i=0; i<256; i++)
{
fprintf(stderr, "%02x %09lld\n", i, _IRexecutionCount[i]);
}

fprintf(stderr, "\n**ROM ADDRESSES\n");
for(int i=0; i<ROM_SIZE; i++)
{
fprintf(stderr, "%04x %05u %09lld\n", i, i, _ROMexecutionCount[i]);
}

}
#endif

Expand All @@ -126,6 +144,17 @@ namespace Cpu
}
#endif


uint64_t get_ROMexecutionCount(int addr)
{
return _ROMexecutionCount[addr];
}
uint64_t get_IRexecutionCount(int instr)
{
return _IRexecutionCount[instr];
}


Endianness getHostEndianness(void)
{
return *((Endianness*)_endianBytes);
Expand Down Expand Up @@ -703,6 +732,15 @@ namespace Cpu

// Initialise COM port here so that we can see error messages
Loader::openComPort();


// For now no instruction has been executed
for(int i=0; i<ROM_SIZE; i++)
_ROMexecutionCount[i] = 0;
for(int i=0; i<256; i++)
_IRexecutionCount[i] = 0;


}

void cycle(const State& S, State& T)
Expand All @@ -714,6 +752,10 @@ namespace Cpu
T._IR = _ROM[S._PC][ROM_INST];
T._D = _ROM[S._PC][ROM_DATA];

// Increase the number of time the instruction at that address has been executed
_ROMexecutionCount[T._PC]++;
_IRexecutionCount[T._IR]++;

// Adapted from https://github.com/kervinck/gigatron-rom/blob/master/Contrib/dhkolf/libgtemu/gtemu.c
// Optimise for the statistically most common instructions
switch(S._IR)
Expand Down
5 changes: 4 additions & 1 deletion Contrib/at67/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ namespace Cpu
#ifdef _WIN32
void enableWin32ConsoleSaveFile(bool consoleSaveFile);
#endif


uint64_t get_ROMexecutionCount(int addr);
uint64_t get_IRexecutionCount(int instr);

Endianness getHostEndianness(void);
void swapEndianness(uint16_t& value);
void swapEndianness(uint32_t& value);
Expand Down
26 changes: 13 additions & 13 deletions Contrib/at67/graphics_config.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[Monitor] ; case sensitive
Fullscreen = 0 ; windowed = 0, fullscreen = 1
Resizable = 1 ; disable/enable resizable, only works in windowed mode
Borderless = 0 ; disable/enable borderless, only works in windowed mode and overrides Resizable
VSync = 0 ; disable/enable VSync, (not normally of value to enable)
FixedSize = 0 ; disable/enable monitor independant size, ignores everything except Width and Height
Filter = 0 ; 0=Nearest, 1=Linear, 2=Best
Width = 640 ; Desktop or <value>, only works in windowed mode
Height = 480 ; Desktop or <value>, only works in windowed mode
ScaleX = 1.5 ; <value>, only works in windowed mode
ScaleY = 1.5 ; <value>, only works in windowed mode
PosX = 40 ; <value>, only works in windowed mode
PosY = 40 ; <value>, only works in windowed mode
[Monitor] ; case sensitive
Fullscreen = 0 ; windowed = 0, fullscreen = 1
Resizable = 1 ; disable/enable resizable, only works in windowed mode
Borderless = 0 ; disable/enable borderless, only works in windowed mode and overrides Resizable
VSync = 0 ; disable/enable VSync, (not normally of value to enable)
FixedSize = 0 ; disable/enable monitor independant size, ignores everything except Width and Height
Filter = 0 ; 0=Nearest, 1=Linear, 2=Best
Width = 640 ; Desktop or <value>, only works in windowed mode
Height = 480 ; Desktop or <value>, only works in windowed mode
ScaleX = 1 ; <value>, only works in windowed mode
ScaleY = 1 ; <value>, only works in windowed mode
PosX = 40 ; <value>, only works in windowed mode
PosY = 40 ; <value>, only works in windowed mode
10 changes: 10 additions & 0 deletions Contrib/at67/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#ifndef STAND_ALONE
#include "editor.h"
#include "loader.h"
#include "graphics.h"
#include "menu.h"
#include "terminal.h"
Expand Down Expand Up @@ -806,6 +807,10 @@ namespace Image
// Quit
else if(keyCode == Editor::getEmulatorScanCode("Quit") && keyMod == Editor::getEmulatorKeyMod("Quit"))
{

//TEMP!
Loader::saveInstructionStatisticsFiles("memory_statistics_log.txt", "instruction_statistics_log.txt");

Cpu::shutdown();
exit(0);
}
Expand All @@ -821,6 +826,11 @@ namespace Image
_firstTimeRender = true;
Terminal::switchToTerminal();
}
// Statistics logs
else if(keyCode == Editor::getEmulatorScanCode("DumpStatisctics") && keyMod == Editor::getEmulatorKeyMod("DumpStatistics"))
{
Loader::saveInstructionStatisticsFiles("memory_statistics_log.txt", "instruction_statistics_log.txt");
}
}

void handleKeyUp(SDL_Keycode keyCode, Uint16 keyMod)
Expand Down
37 changes: 19 additions & 18 deletions Contrib/at67/input_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
; Left Mouse Button to compile/execute current file in Browser on Emulator
; Right Mouse Button to compile/execute current file in Browser on Hardware

[Emulator] ; case sensitive
MemoryMode = CTRL+M ; toggles between RAM, ROM0 and ROM1
MemorySize = CTRL+Z ; toggles between 32K RAM and 64K RAM
Browse = CTRL+B ; file browser
RomType = CTRL+R ; ROM browser
HexMonitor = CTRL+X ; hex monitor
Disassembler = CTRL+D ; disassembler, (vCPU or Native based on MemoryMode)
Terminal = CTRL+T ; basic serial terminal for talking to hardware
ImageEditor = CTRL+I ; basic image editor for editing graphic images
AudioEditor = CTRL+A ; basic audio editor for editing sample waveforms
ScanlineMode = CTRL+S ; toggles scanline modes, Normal, VideoB and VideoBC
Reset = CTRL+F1 ; emulator reset
Help = CTRL+H ; toggles help screen on and off
Quit = CTRL+Q ; instant quit
[Emulator] ; case sensitive
MemoryMode = CTRL+M ; toggles between RAM, ROM0 and ROM1
MemorySize = CTRL+Z ; toggles between 32K RAM and 64K RAM
Browse = CTRL+B ; file browser
RomType = CTRL+R ; ROM browser
HexMonitor = CTRL+X ; hex monitor
Disassembler = CTRL+D ; disassembler, (vCPU or Native based on MemoryMode)
Terminal = CTRL+T ; basic serial terminal for talking to hardware
ImageEditor = CTRL+I ; basic image editor for editing graphic images
AudioEditor = CTRL+A ; basic audio editor for editing sample waveforms
ScanlineMode = CTRL+S ; toggles scanline modes, Normal, VideoB and VideoBC
Reset = CTRL+F1 ; emulator reset
Help = CTRL+H ; toggles help screen on and off
Quit = CTRL+Q ; instant quit
DumpStatistics = CTRL+N ; write statistics about instruction execution (addresses and instruction counts)

[Keyboard] ; case sensitive
Mode = CTRL+K ; toggles between, Giga, PS2, HwGiga and HwPS2
Expand All @@ -27,9 +28,9 @@ Right = D ; right input for emulator/hardware depending on Mode
Up = W ; up input for emulator/hardware depending on Mode
Down = S ; down input for emulator/hardware depending on Mode
Start = SPACE ; start input for emulator/hardware depending on Mode
Select = Z ; select input for emulator/hardware depending on Mode
A = . ; A input for emulator/hardware depending on Mode
B = / ; B input for emulator/hardware depending on Mode
Select = I ; select input for emulator/hardware depending on Mode
A = O ; A input for emulator/hardware depending on Mode
B = P ; B input for emulator/hardware depending on Mode

[Hardware] ; case sensitive
Reset = CTRL+F2 ; resets hardware
Expand All @@ -39,4 +40,4 @@ Debug = CTRL+F6 ; toggles debugging mode, can be used to pause
RunToBrk = CTRL+F7 ; run to breakpoint, does nada if no breakpoints exist
StepPC = CTRL+F8 ; single steps debugger based on vPC or native PC
StepWatch = CTRL+F9 ; single steps debugger based on a watched variable
; by default is videoY which changes once per scanline
; by default is videoY which changes once per scanline
37 changes: 37 additions & 0 deletions Contrib/at67/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <fstream>
#include <algorithm>
#include <string.h>
#include <iostream>
using namespace std;

#ifdef _WIN32
#include <windows.h>
Expand Down Expand Up @@ -335,6 +337,41 @@ namespace Loader
return totalSize;
}

bool saveInstructionStatisticsFiles(std::string const& filenameMemory, std::string const& filenameInstr)
{
std::ofstream outfileMemory(filenameMemory, std::ios::out);
if(!outfileMemory.is_open())
{
fprintf(stderr, "Loader::saveInstructionStatisticsFiles() : failed to open '%s'\n", filenameMemory.c_str());
return false;
}
std::ofstream outfileInstr(filenameInstr, std::ios::out);
if(!outfileInstr.is_open())
{
fprintf(stderr, "Loader::saveInstructionStatisticsFiles() : failed to open '%s'\n", filenameInstr.c_str());
return false;
}

// temp to debug...
ofstream ofs("/tmp/gigatrontmplogfile.txt");
clog.rdbuf(ofs.rdbuf());

clog << "\n**ROM ADDRESSES**\n";
for(int i=0; i<ROM_SIZE; i++)
{
outfileMemory << i << ":" << Cpu::get_ROMexecutionCount(i) << "\n";
clog << i << ":" << Cpu::get_ROMexecutionCount(i) << "\n";
}
clog << "\n**INSTRUCTIONS**\n";
for(int i=0; i<256; i++)
{
outfileInstr << i << ":" << Cpu::get_IRexecutionCount(i) << "\n";
clog << i << ":" << Cpu::get_IRexecutionCount(i) << "\n";
}

return true;
}


#ifndef STAND_ALONE
enum LoaderState {FirstByte=0, MsgLength, LowAddress, HighAddress, Message, LastByte, ResetIN, NumLoaderStates};
Expand Down
2 changes: 2 additions & 0 deletions Contrib/at67/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ namespace Loader
bool saveGt1File(const std::string& filepath, Gt1File& gt1File, std::string& filename);
uint16_t printGt1Stats(const std::string& filename, const Gt1File& gt1File, bool isGbasFile);

bool saveInstructionStatisticsFiles(std::string const& filenameMemory, std::string const& filenameInstr);

#ifdef _WIN32
char* getcwd(char* dst, int size);
int chdir(const char* path);
Expand Down
Loading

0 comments on commit 5019450

Please sign in to comment.