Skip to content

Commit

Permalink
Use positive logic in the sentinel variable for MOVN/MOVZ
Browse files Browse the repository at this point in the history
  • Loading branch information
lupino3 committed May 1, 2016
1 parent 12d63c3 commit e49c8b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 6 additions & 7 deletions src/org/edumips64/core/is/MOVN.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class MOVN extends ALU_RType {
final String OPCODE_VALUE = "001011";
private static final Logger logger = Logger.getLogger(MOVN.class.getName());

// Skip the Write Back if the predicate (RT != 0) is false
private boolean skipWB = false;
// Set to true if the Write Back stage should write data.
private boolean should_write = false;


public MOVN() {
Expand All @@ -56,8 +56,7 @@ public MOVN() {
public void EX() throws IrregularStringOfBitsException, IntegerOverflowException, TwosComplementSumException {
if (TR[RT_FIELD].getValue() != 0) {
TR[RD_FIELD].setBits(TR[RS_FIELD].getBinString(), 0);
} else {
skipWB = true;
should_write = true;
}

if (enableForwarding) {
Expand All @@ -67,9 +66,9 @@ public void EX() throws IrregularStringOfBitsException, IntegerOverflowException

public void doWB() throws IrregularStringOfBitsException {
// The doWB() method is overridden because it must check if the write
// on the registers must be done, checking the skipWB variable.
if (!skipWB) {
logger.info("Skipping WB as the predicate is false");
// on the registers must be done, checking the should_write variable.
if (should_write) {
logger.info("Writing to the dest register, since the condition is true.");
cpu.getRegister(params.get(RD_FIELD)).setBits(TR[RD_FIELD].getBinString(), 0);
}

Expand Down
13 changes: 6 additions & 7 deletions src/org/edumips64/core/is/MOVZ.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class MOVZ extends ALU_RType {
final String OPCODE_VALUE = "001010";
private static final Logger logger = Logger.getLogger(MOVZ.class.getName());

// Skip the Write Back if the predicate (RT == 0) is false
private boolean skipWB = false;
// Set to true if the Write Back stage should write data.
private boolean should_write = false;

public MOVZ() {
super.OPCODE_VALUE = OPCODE_VALUE;
Expand All @@ -51,8 +51,7 @@ public MOVZ() {
public void EX() throws IrregularStringOfBitsException, IntegerOverflowException, TwosComplementSumException {
if (TR[RT_FIELD].getValue() == 0) {
TR[RD_FIELD].setBits(TR[RS_FIELD].getBinString(), 0);
} else {
skipWB = true;
should_write = true;
}

if (enableForwarding) {
Expand All @@ -62,9 +61,9 @@ public void EX() throws IrregularStringOfBitsException, IntegerOverflowException
}
public void doWB() throws IrregularStringOfBitsException {
// The doWB() method is overridden because it must check if the write
// on the registers must be done, checking the skipWB variable.
if (!skipWB) {
logger.info("Skipping WB as the predicate is false");
// on the registers must be done, checking the should_write variable.
if (should_write) {
logger.info("Writing to the dest register, since the condition is true.");
cpu.getRegister(params.get(RD_FIELD)).setBits(TR[RD_FIELD].getBinString(), 0);
}

Expand Down

0 comments on commit e49c8b8

Please sign in to comment.