Example #1
0
  private void stage_issue() {
    System.out.println("station " + id + " in ISSUE.");

    // check operand 1
    Message msg;
    if (Qj != READY) {
      msg = bus.search_station(Qj);
      if (msg != null) { // found
        Qj = READY;
        Vj = msg.result;
      }
    } // endif

    // check operand 2
    if (Qk != READY) {
      msg = bus.search_station(Qk);
      if (msg != null) { // found
        Qk = READY;
        Vk = msg.result;
      }
    } // endif

    // if both operands ready, do execution
    if ((Qj == READY) && (Qk == READY)) {
      stage = "EX";
      stage_ex();
    }
  }
Example #2
0
  private void issue(ArrayList<String> instruction) {
    System.out.println("station " + id + " being issued with one instruction.");
    bus.issued = true;
    bus.PC++;

    Busy = true;
    stage = "ISSUE";

    Op = instruction.get(0);

    if ((Op.equals("add.d"))
        || (Op.equals("sub.d"))
        || (Op.equals("mul.d"))
        || (Op.equals("div.d"))) {
      if ((Op.equals("add.d")) || Op.equals("sub.d")) {
        cycles_left = 3;
      } else cycles_left = 6;

      // check operand 1
      int index = Integer.parseInt(instruction.get(4));
      int depend = bus.freg.getFregFlag(index);
      if (depend == READY) { // operand 1 ready
        Qj = READY;
        Vj = bus.freg.getFreg(index);
      } else { // operand 1 depends on another station
        // check bus
        Message msg = bus.search_station(depend);
        if (msg != null) {
          Qj = READY;
          Vj = msg.result;
        } else Qj = depend; // wait on that station;
      }

      // check operand 2
      index = Integer.parseInt(instruction.get(6));
      depend = bus.freg.getFregFlag(index);
      if (depend == READY) { // operand 1 ready
        Qk = READY;
        Vk = bus.freg.getFreg(index);
      } else { // operand 1 depends on another station
        // check bus
        Message msg = bus.search_station(depend);
        if (msg != null) {
          Qk = READY;
          Vk = msg.result;
        } else Qk = depend; // wait on that station;
      }

      // if they are ready, enter stage EX
      if ((Qj == READY) && (Qk == READY)) { // both operands ready
        stage = "EX";
      }

      // set register dependency flag
      int reg_dst = Integer.parseInt(instruction.get(2));
      bus.freg.setFregFlag(reg_dst, id);
      System.out.println("station " + id + ": F" + reg_dst + " now depends on it.");

    } else if (Op.equals("daddi")) {
      cycles_left = 2; // how many?

      // check operand 1
      int index = Integer.parseInt(instruction.get(4));
      int depend = bus.reg.getRegFlag(index);
      if (depend == READY) { // operand 1 ready
        Qj = READY;
        Vj = bus.reg.getReg(index);
      } else { // operand 1 depends on another station
        // check bus
        Message msg = bus.search_station(depend);
        if (msg != null) {
          Qj = READY;
          Vj = msg.result;
        } else Qj = depend; // wait on that station;
      }

      // operand 2 always ready
      Qk = READY;
      Vk = Integer.parseInt(instruction.get(6));

      // if they are ready, enter stage EX
      if ((Qj == READY) && (Qk == READY)) { // both operands ready
        stage = "EX";
      }

      // set register dependency flag
      int reg_dst = Integer.parseInt(instruction.get(2));
      bus.reg.setRegFlag(reg_dst, id);
      System.out.println("station " + id + ": R" + reg_dst + " now depends on it.");

    } else if (Op.equals("s.d")) {
      cycles_left = 1;

      // check operand 1

      int index = Integer.parseInt(instruction.get(2));
      int depend = bus.freg.getFregFlag(index);
      if (depend == READY) { // operand ready
        Qj = READY;
        Vj = bus.freg.getFreg(index);
      } else { // operand depends on another station
        // check bus
        Message msg = bus.search_station(depend);
        if (msg != null) {
          Qj = READY;
          Vj = msg.result;
        } else Qj = depend; // wait on that station;
      }

      // check operand 2

      index = Integer.parseInt(instruction.get(6));
      depend = bus.reg.getRegFlag(index);
      if (depend == READY) { // operand 1 ready
        Qk = READY;
        Vk = bus.reg.getReg(index);
      } else { // operand 1 depends on another station
        // check bus
        Message msg = bus.search_station(depend);
        if (msg != null) {
          Qk = READY;
          Vk = msg.result;
        } else Qk = depend; // wait on that station;
      }

      // if they are ready, enter stage EX
      if ((Qj == READY) && (Qk == READY)) { // both operands ready
        stage = "EX";
      }

      // no registers' value depend on s.d instruction
      // but we have to calculation A, into which memory unit the bus stores result
      // second part of A comes from Rx, which will accumulated to A in stage EX
      A = Integer.parseInt(instruction.get(4));

    } else if (Op.equals("l.d")) {
      cycles_left = 1;

      // check operand 1
      Qj = READY;
      Vj = Integer.parseInt(instruction.get(4));

      // check operand 2
      int index = Integer.parseInt(instruction.get(6));
      int depend = bus.reg.getRegFlag(index);
      if (depend == READY) { // operand 2 ready
        Qk = READY;
        Vk = bus.reg.getReg(index);
      } else { // operand 2 depends on another station
        // check bus
        Message msg = bus.search_station(depend);
        if (msg != null) {
          Qk = READY;
          Vk = msg.result;
        } else Qk = depend; // wait on that station;
      }

      // if they are ready, enter stage EX
      if ((Qj == READY) && (Qk == READY)) { // both operands ready
        stage = "EX";
      }

      // set register dependency flag
      int reg_dst = Integer.parseInt(instruction.get(2));
      bus.freg.setFregFlag(reg_dst, id);
      System.out.println("station " + id + ": F" + reg_dst + " now depends on it.");

    } else {
      System.out.println("== Station.is_match == this should not happen");
    }
  }