Coder Social home page Coder Social logo

alprn42 / instruction-counter Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 20 KB

In this project, ınstruction numbers from a c program are counted with pin and c++.

C++ 100.00%
cpp pin instruction counter matmul instruction-counter branch-instruction registers resgister-counter

instruction-counter's Introduction

Instruction-Counter

In this project, ınstruction numbers from a c program are counted with pin and c++.

The Output:

Total Count (Task1) 721299

Task2

Branch Count: 68083

Memory Count: 340091

Arithmetic Count: 313125

Task3

Freqquency Of RAX 1498

Freqquency Of RBX 388

Freqquency Of RCX 477

Freqquency Of RDX 713

Freqquency Of RSI 556

Freqquency Of RDI 681

Freqquency Of RSP 2403

Freqquency Of RBP 308

Freqquency Of R8 156

Freqquency Of R9 115

Freqquency Of R10 162

Freqquency Of R11 70

Freqquency Of R12 235

Freqquency Of R13 188

Freqquency Of R14 188

Freqquency Of R15 153

General Explanation:

Firstly, I downloaded matmul.c, matmul.h and matmul.sh files from the link. After that I downloaded the pin that a binary instrumentation tool. I customized some settings for pin with the following lines:

set env INTEL_JIT_PROFILER32 /ia32/bin/libpinjitprofiling.so

set env INTEL_JIT_PROFILER64 /intel64/bin/libpinjitprofiling.so

make all TARGET=intel64

Then, I opened new folder in pin/source/tools folder and run the c code in this folder. Also I put my cpp codes for pin instrumentation in this folder. After I run the matmul code , I used the output file to count instructions.

TASK -1:

In task 1, the total number of instructions were wanted. Therefore, I used a manual example from pin files which is inscount0.cpp. I used to following methods to calculate total numbers of instructions.

VOID dototalcount() { total++; }

This method just changing the number of total variable.

INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)dototalcount, IARG_END);

This method calls instructions and dototalcount method.

Also, PIN is a CISC architecture but it tries to use advantages of RISC architecture.

TASK-2:

In this task, the number of instructions wanted according to their types. I just used if conditions to find memory and branch instructions like following lines:

if (INS_IsBranch(ins)) {

INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)dobranchcount, IARG_END);

}

for (UINT32 memOp = 0; memOp < memOperands; memOp++)

{

if (INS_MemoryOperandIsWritten(ins,memOp) || INS_MemoryOperandIsRead(ins,memOp)) {

INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)domemcount, IARG_END);

}

}

However, in the memory instructions I checked if an instruction is written to memory or read from memory. If it is one of them I changed counter by 1.

Also, to calculate the arithmetic instructions I used this formula:

total-(branchcount+memcount)

TASK-3:

In this task the frequencies of usage of register in pin were asked. I just used again if conditions to calculate this for each register with different counters(c,c1,c2,c3,…….).

if (INS_RegWContain(ins,REG_RBX)) {

c2++;

}

instruction-counter's People

Contributors

alprn42 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.