mirror of
https://github.com/guilhermewerner/tomasulo-simulator
synced 2025-06-15 13:24:20 +00:00
Branch logic
This commit is contained in:
@ -15,13 +15,14 @@ import { ProgramContext } from '../src/ProgramContext';
|
|||||||
export default function Home() {
|
export default function Home() {
|
||||||
const { program } = useContext(ProgramContext);
|
const { program } = useContext(ProgramContext);
|
||||||
|
|
||||||
console.log(JSON.stringify(program));
|
//console.log(JSON.stringify(program));
|
||||||
|
|
||||||
let baseI = {
|
let baseI = {
|
||||||
issue: null,
|
issue: null,
|
||||||
exeCompleta: null,
|
exeCompleta: null,
|
||||||
write: null,
|
write: null,
|
||||||
busy: false,
|
busy: false,
|
||||||
|
discart: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
let instructions = [];
|
let instructions = [];
|
||||||
@ -44,6 +45,7 @@ export default function Home() {
|
|||||||
vk: null,
|
vk: null,
|
||||||
qj: null,
|
qj: null,
|
||||||
qk: null,
|
qk: null,
|
||||||
|
jump: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let fUnites = [
|
let fUnites = [
|
||||||
@ -160,9 +162,9 @@ export default function Home() {
|
|||||||
for (let i = 0; i < instructionStatus.length; i++) {
|
for (let i = 0; i < instructionStatus.length; i++) {
|
||||||
let element = instructionStatus[i];
|
let element = instructionStatus[i];
|
||||||
|
|
||||||
console.log("element:", element.instrucao.operacao);
|
//console.log("element:", element.instrucao.operacao);
|
||||||
|
|
||||||
if (element.issue === null) {
|
if (element.issue === null && !element.discart) {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,7 +173,7 @@ export default function Home() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getFunctionalUnity(instr) {
|
function getFunctionalUnity(instr) {
|
||||||
console.log("getFunctionalUnity:", instr.operacao);
|
//console.log("getFunctionalUnity:", instr.operacao);
|
||||||
|
|
||||||
switch (instr.operacao) {
|
switch (instr.operacao) {
|
||||||
case 'ADD':
|
case 'ADD':
|
||||||
@ -389,11 +391,12 @@ export default function Home() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function issueInstruction() {
|
function issueInstruction() {
|
||||||
console.log("issueInstruction");
|
//console.log("issueInstruction");
|
||||||
|
|
||||||
let novaInstrucao = fetchInstruction();
|
let novaInstrucao = fetchInstruction();
|
||||||
|
|
||||||
if (novaInstrucao) {
|
if (novaInstrucao) {
|
||||||
|
console.log(novaInstrucao);
|
||||||
let ufInstrucao = getFunctionalUnity(novaInstrucao.instrucao);
|
let ufInstrucao = getFunctionalUnity(novaInstrucao.instrucao);
|
||||||
let UFParaUsar = getEmptyFunctionalUnity(ufInstrucao);
|
let UFParaUsar = getEmptyFunctionalUnity(ufInstrucao);
|
||||||
|
|
||||||
@ -406,7 +409,8 @@ export default function Home() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
novaInstrucao.issue = clock;
|
novaInstrucao.issue = clock;
|
||||||
if ((UFParaUsar.tipoUnidade !== 'Store') && (UFParaUsar.operacao !== 'BEQ') && (UFParaUsar.operacao !== 'BEQ')) {
|
|
||||||
|
if ((UFParaUsar.tipoUnidade !== 'Store') && (UFParaUsar.operacao !== 'BEQ')) {
|
||||||
writeRegister(novaInstrucao.instrucao, novaInstrucao.posicao);
|
writeRegister(novaInstrucao.instrucao, novaInstrucao.posicao);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -430,6 +434,15 @@ export default function Home() {
|
|||||||
for (let key in functionalUnits) {
|
for (let key in functionalUnits) {
|
||||||
var uf = functionalUnits[key];
|
var uf = functionalUnits[key];
|
||||||
|
|
||||||
|
if (uf.instrucao?.operacao === "BEQ") {
|
||||||
|
if (uf.instrucao?.registradorR === uf.instrucao?.registradorS) {
|
||||||
|
let entry = uf.estadoInstrucao.posicao;
|
||||||
|
instructionStatus[entry].discart = true;
|
||||||
|
instructionStatus[entry + 1].discart = true;
|
||||||
|
setInstructionStatus(instructionStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((uf.ocupado) && (uf.vj !== null) && (uf.vk !== null)) {
|
if ((uf.ocupado) && (uf.vj !== null) && (uf.vk !== null)) {
|
||||||
uf.tempo = uf.tempo - 1;
|
uf.tempo = uf.tempo - 1;
|
||||||
uf.estadoInstrucao.busy = true;
|
uf.estadoInstrucao.busy = true;
|
||||||
@ -483,15 +496,24 @@ export default function Home() {
|
|||||||
function nextCycle() {
|
function nextCycle() {
|
||||||
setClock(clock + 1);
|
setClock(clock + 1);
|
||||||
console.log(clock);
|
console.log(clock);
|
||||||
issueInstruction();
|
|
||||||
executeInstruction();
|
let jump = issueInstruction();
|
||||||
writeInstruction();
|
|
||||||
|
if (!jump) {
|
||||||
|
executeInstruction();
|
||||||
|
writeInstruction();
|
||||||
|
}
|
||||||
|
|
||||||
setInstructionStatus(instructionStatus);
|
setInstructionStatus(instructionStatus);
|
||||||
setMmoryUnits(memoryUnits);
|
setMmoryUnits(memoryUnits);
|
||||||
setFunctionalUnits(functionalUnits);
|
setFunctionalUnits(functionalUnits);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFormatedState(instr) {
|
function getFormatedState(instr) {
|
||||||
|
if (instr.discart) {
|
||||||
|
return "Discarted";
|
||||||
|
}
|
||||||
|
|
||||||
if (instr.write !== null) {
|
if (instr.write !== null) {
|
||||||
return "Commit";
|
return "Commit";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user