Skip to content

Commit

Permalink
Removed clean on units and implemented a better instruction copy
Browse files Browse the repository at this point in the history
  • Loading branch information
endes0 committed Feb 18, 2024
1 parent 88d400d commit 58ffa07
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 71 deletions.
16 changes: 4 additions & 12 deletions src/core/Common/FunctionalUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ interface FunctionalUnitInstruction {
}

export class FunctionalUnit {
private _stalled: number; // if >0, it is stalling (for ex because a memory fail) for that many cycles
private _instructions: FunctionalUnitInstruction[];
private _stalled: number = 0; // if >0, it is stalling (for ex because a memory fail) for that many cycles
private _instructions: FunctionalUnitInstruction[] = [];

private _nextRef: number; //TODO: use instruction uid
private _nextRef: number = 0; //TODO: use instruction uid
private _currentBlankTimeUnits: number;
private _hasExectutedInstBeforeTick: boolean;
private _hasExectutedInstBeforeTick: boolean = false;

public get type(): FunctionalUnitType {
return this._type;
Expand All @@ -78,15 +78,7 @@ export class FunctionalUnit {
private _type: FunctionalUnitType,
private _latency: number = FunctionalUnitLantencies[_type]
) {
this.clean();
}

public clean() {
this._stalled = 0;
this._nextRef = 0;
this._currentBlankTimeUnits = this._latency - 1;
this._hasExectutedInstBeforeTick = false;
this._instructions = [];
}

public tic() {
Expand Down
22 changes: 9 additions & 13 deletions src/core/Common/Instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export class Instruction {
public id: number;
public basicBlock: number;
public opcode: number;
protected _uuid: number;
protected _operands: number[] = new Array(3);
protected _operandsString: string[] = new Array(3);
protected _label: string;
Expand Down Expand Up @@ -36,18 +35,15 @@ export class Instruction {
return this._operandsString;
}

instantiate(from: Instruction, cycle: number) {
this.copy(from);
this._uuid = cycle * 1000 + this.id;
}

copy(other: Instruction) {
this.id = other.id;
this.basicBlock = other.basicBlock;
this.opcode = other.opcode;
this._operands = other.operands.slice();
this._operandsString = other.operandsString.slice();
this._breakPoint = other.breakPoint;
constructor(from?: Instruction, protected _uuid?: number) {
if (from) {
this.id = from.id;
this.basicBlock = from.basicBlock;
this.opcode = from.opcode;
this._operands = from.operands.slice();
this._operandsString = from.operandsString.slice();
this._breakPoint = from.breakPoint;
}
}

toString(): string {
Expand Down
5 changes: 4 additions & 1 deletion src/core/Common/Machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ export class Machine {
this.pc = 0;
for (let i = 0; i < FUNCTIONALUNITTYPESQUANTITY; i++) {
for (let j = 0; j < this.functionalUnit[i].length; j++) {
this.functionalUnit[i][j].clean();
this.functionalUnit[i][j] = new FunctionalUnit(
this.functionalUnit[i][j].type,
this.functionalUnit[i][j].latency
);
}
}
this.status.cycle = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/core/Superescalar/JumpPredictor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export class JumpPredictor {
_table: number[];

constructor(private _size: number) {
this._table = new Array(_size);
this._table.fill(0);
public get size(): number {
return this._size;
}

public clean() {
constructor(private _size: number) {
this._table = new Array(_size);
this._table.fill(0);
}

Expand Down
4 changes: 0 additions & 4 deletions src/core/Superescalar/PrefetchUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ export class PrefetchUnit {

constructor(private _size: number) {}

public clean() {
this._entries = [];
}

public isFull() {
return this._entries.length >= this._size;
}
Expand Down
17 changes: 6 additions & 11 deletions src/core/Superescalar/ReorderBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ interface ReorderBufferEntry {
// TODO: dont use rob entry pos as a reference to the instruction, use an instruction uid instead?
export class ReorderBuffer {
_queue: ReorderBufferEntry[] = [];
_GprMapping: { [reg: number]: number };
_FprMapping: { [reg: number]: number };
_GprMapping: { [reg: number]: number } = {};
_FprMapping: { [reg: number]: number } = {};

public get size() {
return this._size;
}

constructor(private _size: number) {}

Expand All @@ -43,15 +47,6 @@ export class ReorderBuffer {
return this._queue.length === 0;
}

/**
* clear - this method clears the reorder buffer, it is called when the machine is reseted
*/
public clear() {
this._queue = [];
this._FprMapping = {};
this._GprMapping = {};
}

/**
* isRegisterValueReady - this method checks if the rob entry wich will write in that register has already the new value
*/
Expand Down
11 changes: 4 additions & 7 deletions src/core/Superescalar/ReserveStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export interface ReserveStationEntry {
export class ReserveStation {
private _entries: ReserveStationEntry[] = new Array();

public get size(): number {
return this._size;
}

constructor(private _size: number) {}

private getInstrPos(uuid: number): number {
Expand All @@ -35,13 +39,6 @@ export class ReserveStation {
return -1;
}

/**
* clear
*/
public clear() {
this._entries = new Array();
}

/**
* isFull
*/
Expand Down
40 changes: 26 additions & 14 deletions src/core/Superescalar/Superescalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,29 @@ export class Superescalar extends Machine {
// Clean functional Units and Reserve Stations,
for (let i = 0; i < FUNCTIONALUNITTYPESQUANTITY; i++) {
for (let j = 0; j < this.functionalUnit[i].length; j++) {
this.functionalUnit[i][j].clean();
this._reserveStations[i].clear();
this.functionalUnit[i][j] = new FunctionalUnit(
this.functionalUnit[i][j].type,
this.functionalUnit[i][j].latency
);
this._reserveStations[i] = new ReserveStation(
this._reserveStations[i].size
);
}
}

// Clean the alus for the address calculus
for (let i = 0; i < this.aluMem.length; i++) {
this.aluMem[i].clean();
this.aluMem[i] = new FunctionalUnit(
this.aluMem[i].type,
this.aluMem[i].latency
);
}

// Clean prefetch, decoder and reorder buffer, the simplest way is
// to rebuild the objects
this._prefetchUnit.clean();
this._decoder.clean();
this._reorderBuffer.clear();
this._prefetchUnit = new PrefetchUnit(this._prefetchUnit.size);
this._decoder = new PrefetchUnit(this._decoder.size);
this._reorderBuffer = new ReorderBuffer(this._reorderBuffer.size);

// Clean the structures related to the registers
this._gpr.setAllBusy(false);
Expand All @@ -216,18 +224,23 @@ export class Superescalar extends Machine {
init(reset: boolean) {
super.init(reset);
// Clean Gpr, Fpr, predSalto
this._jumpPrediction.clean();
this._jumpPrediction = new JumpPredictor(this._jumpPrediction.size);

for (let i = 0; i < FUNCTIONALUNITTYPESQUANTITY; i++) {
this._reserveStations[i].clear();
this._reserveStations[i] = new ReserveStation(
this._reserveStations[i].size
);
}
this._reorderBuffer.clear();
this._decoder.clean();
this._prefetchUnit.clean();
this._reorderBuffer = new ReorderBuffer(this._reorderBuffer.size);
this._decoder = new PrefetchUnit(this._decoder.size);
this._prefetchUnit = new PrefetchUnit(this._prefetchUnit.size);
this._code = null;

for (let j = 0; j < this.aluMem.length; j++) {
this.aluMem[j].clean();
this.aluMem[j] = new FunctionalUnit(
this.aluMem[j].type,
this.aluMem[j].latency
);
}
}

Expand All @@ -236,8 +249,7 @@ export class Superescalar extends Machine {
while (!this._prefetchUnit.isFull() && this.pc < this.code.lines) {
// Importante: Hago una copia de la instrucción original para distinguir
// las distintas apariciones de una misma inst.
let instruction = new Instruction();
instruction.instantiate(
let instruction = new Instruction(
this.code.instructions[this.pc],
this.status.cycle * 100 + i
);
Expand Down
6 changes: 3 additions & 3 deletions src/core/VLIW/VLIWOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ export class VLIWOperation extends Instruction {
private _predicateFalse: number;

constructor(operation?: VLIWOperation, instruction?: Instruction, type?: FunctionalUnitType, functionalUnitIndex?: number) {
super();
if (operation) {
super(operation);
this.buildFromVLIWOperation(operation);
} else if (instruction) {
super(instruction);
this.buildFromInstruction(instruction, type, functionalUnitIndex);
} else {
super();
this._predicate = 0;
this._predicateTrue = 0;
this._predicateFalse = 0;
}
}

buildFromVLIWOperation(operation: VLIWOperation) {
this.copy(operation);
this._functionalUnitType = operation._functionalUnitType;
this._functionalUnitIndex = operation._functionalUnitIndex;
this._predicate = operation._predicate;
Expand All @@ -33,7 +34,6 @@ export class VLIWOperation extends Instruction {
}

buildFromInstruction(instruction: Instruction, functionalUnitType: FunctionalUnitType, functionalUnitIndex: number) {
this.copy(instruction);
this._functionalUnitType = functionalUnitType;
this._functionalUnitIndex = functionalUnitIndex;
this._predicate = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/test/unit/core/Common/Instruction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ beforeEach(() => {
});

test('Copied instructions should not keep the same reference', t => {
let newInstruction = new Instruction();
newInstruction.copy(originalInstruction);
let newInstruction = new Instruction(originalInstruction);
originalInstruction.id = 1;
expect(newInstruction.operands).not.toBe(100);
});

0 comments on commit 58ffa07

Please sign in to comment.