Skip to content

Commit 1afbebb

Browse files
committed
Coreview multiplexers updated and added for branch compare forward.
Signed-off-by: Pavel Pisa <[email protected]>
1 parent 1475013 commit 1afbebb

File tree

9 files changed

+251
-32
lines changed

9 files changed

+251
-32
lines changed

qtmips_gui/coreview.cpp

+34-18
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
connect(machine->core(), &machine::Core::SIG, \
6666
VAR, &coreview::MultiText::multitext_update); \
6767
} while(false)
68+
#define NEW_MUX(VAR, X, Y, SIG, ...) do { \
69+
NEW(Multiplexer, VAR, X, Y, __VA_ARGS__); \
70+
connect(machine->core(), SIGNAL(SIG(std::uint32_t)), VAR, SLOT(set(std::uint32_t))); \
71+
} while(false)
72+
#define NEW_MINIMUX(VAR, X, Y, SIG, ...) do { \
73+
NEW(MiniMux, VAR, X, Y, __VA_ARGS__); \
74+
connect(machine->core(), SIGNAL(SIG(std::uint32_t)), VAR, SLOT(set(std::uint32_t))); \
75+
} while(false)
6876

6977
CoreViewScene::CoreViewScene(machine::QtMipsMachine *machine) : QGraphicsScene() {
7078
setSceneRect(0, 0, SC_WIDTH, SC_HEIGHT);
@@ -85,7 +93,7 @@ CoreViewScene::CoreViewScene(machine::QtMipsMachine *machine) : QGraphicsScene()
8593
NEW_B(Constant, ft.adder_4, ft.adder->connector_in_b(), "4");
8694
NEW(Junction, ft.junc_pc, 80, mem_program->connector_address()->y());
8795
NEW(Junction, ft.junc_pc_4, 130, 380);
88-
NEW(Multiplexer, ft.multiplex, 20, 390, 2);
96+
NEW_MUX(ft.multiplex, 20, 390, fetch_branch_value, 2);
8997
// Decode stage
9098
NEW(LogicBlock, dc.ctl_block, 230, 90, {"Control", "unit"});
9199
dc.ctl_block->setSize(35, 70);
@@ -94,7 +102,7 @@ CoreViewScene::CoreViewScene(machine::QtMipsMachine *machine) : QGraphicsScene()
94102
NEW(Adder, dc.add, 340, 428);
95103
const coreview::Connector *dc_con_sign_ext = dc.sign_ext->new_connector(1, 0);
96104
NEW(Junction, dc.j_sign_ext, 290, dc_con_sign_ext->y());
97-
NEW(LogicBlock, dc.cmp, 320, 200, "=");
105+
NEW(LogicBlock, dc.cmp, 312, 200, "=");
98106
NEW(And, dc.and_branch, 350, 190);
99107
dc.cmp->setSize(24, 12);
100108
NEW(Junction, dc.j_inst_up, 190, 126);
@@ -103,8 +111,8 @@ CoreViewScene::CoreViewScene(machine::QtMipsMachine *machine) : QGraphicsScene()
103111
NEW(Junction, dc.j_jump_reg, 355, 94);
104112
// Execute stage
105113
NEW(Junction, ex.j_mux, 450, 303);
106-
NEW(Multiplexer, ex.mux_imm, 470, 292, 2, true);
107-
NEW(Multiplexer, ex.mux_regdest, 480, 370, 2, true);
114+
NEW_MUX(ex.mux_imm, 470, 292, execute_alusrc_value, 2, true);
115+
NEW_MUX(ex.mux_regdest, 480, 370, execute_regdest_value, 2, true);
108116
// Memory
109117
NEW(Junction, mm.j_addr, 570, mem_data->connector_address()->y());
110118
static QMap<std::uint32_t, QString> excause_map =
@@ -123,7 +131,7 @@ CoreViewScene::CoreViewScene(machine::QtMipsMachine *machine) : QGraphicsScene()
123131
NEW_MULTI(mm.multi_excause, 602, 447, memory_excause_value, excause_map, true);
124132
new_label("Exception", 595, 437);
125133
// WriteBack stage
126-
NEW(Multiplexer, wb.mem_or_reg, 690, 252, 2, true);
134+
NEW_MUX(wb.mem_or_reg, 690, 252, writeback_memtoreg_value, 2, true);
127135
NEW(Junction, wb.j_reg_write_val, 411, 510);
128136

129137
// Connections //
@@ -204,7 +212,7 @@ CoreViewScene::CoreViewScene(machine::QtMipsMachine *machine) : QGraphicsScene()
204212
NEW_V(560, 260, memory_alu_value, true); // Alu output
205213
NEW_V(560, 345, memory_rt_value, true); // rt
206214
NEW_V(650, 290, memory_mem_value, true); // Memory output
207-
NEW_V(570, 113, execute_memtoreg_value, false, 1);
215+
NEW_V(570, 113, memory_memtoreg_value, false, 1);
208216
NEW_V(630, 220, memory_memwrite_value, false, 1);
209217
NEW_V(620, 220, memory_memread_value, false, 1);
210218
// Write back stage
@@ -377,12 +385,13 @@ CoreViewScenePipelined::CoreViewScenePipelined(machine::QtMipsMachine *machine)
377385
struct coreview::Latch::ConnectorPair lp_dc_rt = latch_id_ex->new_connector(regs->connector_read2()->y() - latch_id_ex->y());
378386
coreview::Bus *regs_bus1 = new_bus(regs->connector_read1(), lp_dc_rs.in);
379387
coreview::Bus *regs_bus2 = new_bus(regs->connector_read2(), lp_dc_rt.in);
380-
//if (machine->config().hazard_unit() == machine::MachineConfig::HU_NONE) {
381-
const coreview::Connector *regs_bus_con = dc.cmp->new_connector(-0.5, 1);
388+
const coreview::Connector *regs_bus_con;
389+
if (machine->config().hazard_unit() != machine::MachineConfig::HU_STALL_FORWARD) {
390+
regs_bus_con = dc.cmp->new_connector(-0.5, 1);
382391
new_bus(regs_bus1->new_connector(regs_bus_con->point(), coreview::Connector::AX_Y), regs_bus_con);
383392
regs_bus_con = dc.cmp->new_connector(0.5, 1);
384393
new_bus(regs_bus2->new_connector(regs_bus_con->point(), coreview::Connector::AX_Y), regs_bus_con);
385-
//} // TODO else
394+
}
386395
struct coreview::Latch::ConnectorPair lp_dc_immed = latch_id_ex->new_connector(dc.j_sign_ext->y() - latch_id_ex->y());
387396
new_bus(dc.j_sign_ext->new_connector(coreview::Connector::AX_X), lp_dc_immed.in);
388397
struct coreview::Latch::ConnectorPair regdest_dc_rt = latch_id_ex->new_connector(ex.mux_regdest->connector_in(0)->point().y() - latch_id_ex->y());
@@ -489,8 +498,10 @@ CoreViewScenePipelined::CoreViewScenePipelined(machine::QtMipsMachine *machine)
489498
NEW_V(610, 385, memory_regw_num_value, false, 2, 0, 10);
490499

491500
if (machine->config().hazard_unit() == machine::MachineConfig::HU_STALL_FORWARD) {
492-
NEW(Multiplexer, hu.mux_alu_reg_a, 430, 232, 3, false);
493-
NEW(Multiplexer, hu.mux_alu_reg_b, 430, 285, 3, false);
501+
NEW_MUX(hu.mux_alu_reg_a, 430, 232, execute_reg1_ff_value, 3, false);
502+
NEW_MUX(hu.mux_alu_reg_b, 430, 285, execute_reg2_ff_value, 3, false);
503+
NEW_MINIMUX(hu.mux_branch_reg_a, 296, 228, forward_m_d_rs_value, 2, false);
504+
NEW_MINIMUX(hu.mux_branch_reg_b, 314, 228, forward_m_d_rt_value, 2, false);
494505
NEW(Junction, hu.j_alu_out, 420, 490);
495506

496507
con = new_bus(lp_dc_rs.out, hu.mux_alu_reg_a->connector_in(0));
@@ -507,24 +518,29 @@ CoreViewScenePipelined::CoreViewScenePipelined(machine::QtMipsMachine *machine)
507518
con = new_bus(hu.j_alu_out->new_connector(CON_AX_Y), hu.mux_alu_reg_a->connector_in(2));
508519
con = new_bus(hu.j_alu_out->new_connector(CON_AX_Y), hu.mux_alu_reg_b->connector_in(2));
509520

510-
con = new_bus(hu.j_alu_out->new_connector(CON_AX_X), dc.cmp->new_connector(-0.5, 1));
521+
con = new_bus(hu.j_alu_out->new_connector(CON_AX_X), hu.mux_branch_reg_a->connector_in(1));
511522
con->setAxes({CON_AXIS_Y(380), CON_AXIS_X(330)});
512-
con = new_bus(hu.j_alu_out->new_connector(CON_AX_X), dc.cmp->new_connector(0.5, 1));
523+
con = new_bus(hu.j_alu_out->new_connector(CON_AX_X), hu.mux_branch_reg_b->connector_in(1));
513524
con->setAxes({CON_AXIS_Y(380), CON_AXIS_X(330)});
514525

526+
new_bus(regs_bus1->new_connector(hu.mux_branch_reg_a->connector_in(0)->point(), coreview::Connector::AX_Y), hu.mux_branch_reg_a->connector_in(0));
527+
new_bus(regs_bus2->new_connector(hu.mux_branch_reg_b->connector_in(0)->point(), coreview::Connector::AX_Y), hu.mux_branch_reg_b->connector_in(0));
528+
529+
con = new_bus(hu.mux_branch_reg_a->connector_out(), dc.cmp->new_connector(-0.75, 1));
530+
con = new_bus(hu.mux_branch_reg_b->connector_out(), dc.cmp->new_connector(0.75, 1));
531+
515532
struct coreview::Latch::ConnectorPair regdest_dc_rs = latch_id_ex->new_connector(ex.mux_regdest->connector_in(0)->point().y() - latch_id_ex->y() - 8);
516533
new_bus(dc.instr_bus->new_connector(0, ex.mux_regdest->connector_in(0)->y() - 8), regdest_dc_rs.in, 2);
517534
new_label("RsE", 427, 364);
518535
NEW_V(450, 370, execute_rs_num_value, false, 2, 0, 10);
519536
NEW(Junction, ex.j_rs_num, 442, 372);
520537
new_bus(regdest_dc_rs.out, ex.j_rs_num->new_connector(coreview::Connector::AX_X), 2);
521538

539+
NEW_V(434, 227, execute_reg1_ff_value, false, 1); // Register 1 forward to ALU
540+
NEW_V(434, 280, execute_reg2_ff_value, false, 1); // Register 2 forward to ALU
522541

523-
NEW_V(434, 250, execute_reg1_ff_value, false, 1); // Register 1 forward to ALU
524-
NEW_V(434, 303, execute_reg2_ff_value, false, 1); // Register 2 forward to ALU
525-
526-
NEW_V(312, 290, forward_m_d_rs_value, false, 1); // Register 1 forward for bxx and jr, jalr
527-
NEW_V(327, 290, forward_m_d_rt_value, false, 1); // Register 2 forward for beq, bne
542+
NEW_V(291, 230, forward_m_d_rs_value, false, 1); // Register 1 forward for bxx and jr, jalr
543+
NEW_V(333, 230, forward_m_d_rt_value, false, 1); // Register 2 forward for beq, bne
528544

529545
}
530546
}

qtmips_gui/coreview.h

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "coreview/connection.h"
4444
#include "coreview/programcounter.h"
4545
#include "coreview/multiplexer.h"
46+
#include "coreview/minimux.h"
4647
#include "coreview/latch.h"
4748
#include "coreview/alu.h"
4849
#include "coreview/adder.h"
@@ -114,6 +115,8 @@ class CoreViewScene : public QGraphicsScene {
114115
coreview::Multiplexer *mux_alu_reg_b;
115116
coreview::Junction *j_alu_out;
116117
coreview::MultiText *multi_stall;
118+
coreview::MiniMux *mux_branch_reg_a;
119+
coreview::MiniMux *mux_branch_reg_b;
117120
} hu;
118121

119122
coreview::Connection *new_connection(const coreview::Connector*, const coreview::Connector*);

qtmips_gui/coreview/minimux.cpp

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*******************************************************************************
3+
* QtMips - MIPS 32-bit Architecture Subset Simulator
4+
*
5+
* Implemented to support following courses:
6+
*
7+
* B35APO - Computer Architectures
8+
* https://cw.fel.cvut.cz/wiki/courses/b35apo
9+
*
10+
* B4M35PAP - Advanced Computer Architectures
11+
* https://cw.fel.cvut.cz/wiki/courses/b4m35pap/start
12+
*
13+
* Copyright (c) 2017-2019 Karel Koci<[email protected]>
14+
* Copyright (c) 2019 Pavel Pisa <[email protected]>
15+
*
16+
* Faculty of Electrical Engineering (http://www.fel.cvut.cz)
17+
* Czech Technical University (http://www.cvut.cz/)
18+
*
19+
* This program is free software; you can redistribute it and/or
20+
* modify it under the terms of the GNU General Public License
21+
* as published by the Free Software Foundation; either version 2
22+
* of the License, or (at your option) any later version.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program; if not, write to the Free Software
31+
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
32+
* Boston, MA 02110-1301, USA.
33+
*
34+
******************************************************************************/
35+
36+
#include "minimux.h"
37+
#include <cmath>
38+
39+
using namespace coreview;
40+
41+
//////////////////////
42+
#define WIDTH 6
43+
#define HEIGHT 8
44+
#define GAP 8
45+
#define PENW 1
46+
//////////////////////
47+
48+
MiniMux::MiniMux(unsigned size, bool ctl_up): QGraphicsObject(nullptr) {
49+
this->size = size;
50+
seton = -1;
51+
ctlfrom = ctl_up;
52+
con_ctl = new Connector(Connector::AX_X);
53+
con_out = new Connector(Connector::AX_Y);
54+
con_in = new Connector*[size];
55+
for (unsigned i = 0; i < size; i++)
56+
con_in[i] = new Connector(Connector::AX_Y);
57+
setPos(x(), y()); // Set connectors possitions
58+
}
59+
60+
MiniMux::~MiniMux() {
61+
delete con_ctl;
62+
delete con_out;
63+
for (unsigned i = 0; i < size; i++)
64+
delete con_in[i];
65+
delete[] con_in;
66+
}
67+
68+
#define C_WIDTH (WIDTH + (GAP * (size -1 )))
69+
70+
QRectF MiniMux::boundingRect() const {
71+
return QRectF(-PENW / 2, -PENW / 2, C_WIDTH + PENW, WIDTH + PENW);
72+
}
73+
74+
void MiniMux::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) {
75+
painter->setPen(QPen(QColor(200, 200, 200), 2));
76+
if (seton >= 0 && seton < (int)size)
77+
painter->drawLine((WIDTH / 2) + (seton * GAP), HEIGHT, C_WIDTH / 2, 0);
78+
79+
painter->setPen(QColor(0, 0, 0));
80+
const QPointF poly[] = {
81+
QPointF(0, HEIGHT),
82+
QPointF(HEIGHT / 2, 0),
83+
QPointF(C_WIDTH - (HEIGHT / 2), 0),
84+
QPointF(C_WIDTH, HEIGHT)
85+
};
86+
painter->drawPolygon(poly, sizeof(poly) / sizeof(QPointF));
87+
}
88+
89+
void MiniMux::setPos(qreal x, qreal y) {
90+
QGraphicsItem::setPos(x, y);
91+
/*if (ctlfrom)
92+
con_ctl->setPos(x + (WIDTH / 2), y + (WIDTH / 4));
93+
else
94+
con_ctl->setPos(x + (WIDTH / 2), y + C_HEIGHT - (WIDTH / 4));
95+
*/
96+
con_out->setPos(x + (C_WIDTH / 2), y);
97+
for (unsigned i = 0; i < size; i++)
98+
con_in[i]->setPos(x + (WIDTH / 2) + (i * GAP), y + HEIGHT);
99+
}
100+
101+
const Connector *MiniMux::connector_ctl() const {
102+
return con_ctl;
103+
}
104+
105+
const Connector *MiniMux::connector_out() const {
106+
return con_out;
107+
}
108+
109+
const Connector *MiniMux::connector_in(unsigned i) const {
110+
SANITY_ASSERT(i < size, "MiniMux: requested out of range input connector");
111+
return con_in[i];
112+
}
113+
114+
void MiniMux::set(std::uint32_t i) {
115+
if (seton != (int)i) {
116+
seton = (int)i;
117+
update();
118+
}
119+
}
120+

qtmips_gui/coreview/minimux.h

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*******************************************************************************
3+
* QtMips - MIPS 32-bit Architecture Subset Simulator
4+
*
5+
* Implemented to support following courses:
6+
*
7+
* B35APO - Computer Architectures
8+
* https://cw.fel.cvut.cz/wiki/courses/b35apo
9+
*
10+
* B4M35PAP - Advanced Computer Architectures
11+
* https://cw.fel.cvut.cz/wiki/courses/b4m35pap/start
12+
*
13+
* Copyright (c) 2017-2019 Karel Koci<[email protected]>
14+
* Copyright (c) 2019 Pavel Pisa <[email protected]>
15+
*
16+
* Faculty of Electrical Engineering (http://www.fel.cvut.cz)
17+
* Czech Technical University (http://www.cvut.cz/)
18+
*
19+
* This program is free software; you can redistribute it and/or
20+
* modify it under the terms of the GNU General Public License
21+
* as published by the Free Software Foundation; either version 2
22+
* of the License, or (at your option) any later version.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program; if not, write to the Free Software
31+
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
32+
* Boston, MA 02110-1301, USA.
33+
*
34+
******************************************************************************/
35+
36+
#ifndef COREVIEW_MINIMUX_H
37+
#define COREVIEW_MINIMUX_H
38+
39+
#include <QGraphicsObject>
40+
#include "qtmipsexception.h"
41+
#include "connection.h"
42+
43+
namespace coreview {
44+
45+
class MiniMux : public QGraphicsObject {
46+
Q_OBJECT
47+
public:
48+
MiniMux(unsigned size, bool ctl_up = false);
49+
~MiniMux();
50+
51+
QRectF boundingRect() const;
52+
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
53+
54+
void setPos(qreal x, qreal y);
55+
const Connector *connector_ctl() const; // Control input
56+
const Connector *connector_out() const; // Output
57+
const Connector *connector_in(unsigned i) const; // Inputs
58+
59+
public slots:
60+
void set(std::uint32_t i); // Set what value should be set as connected (indexing from 1 where 0 is no line)
61+
62+
private:
63+
bool ctlfrom;
64+
unsigned size;
65+
int seton;
66+
Connector *con_ctl, *con_out, **con_in;
67+
};
68+
69+
}
70+
71+
#endif // COREVIEW_MINIMUX_H

qtmips_gui/coreview/multiplexer.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ using namespace coreview;
4545
#define PENW 1
4646
//////////////////////
4747

48-
Multiplexer::Multiplexer(unsigned size, bool ctl_up) {
48+
Multiplexer::Multiplexer(unsigned size, bool ctl_up): QGraphicsObject(nullptr) {
4949
this->size = size;
50-
seton = 0;
50+
seton = -1;
5151
ctlfrom = ctl_up;
5252
con_ctl = new Connector(Connector::AX_Y);
5353
con_out = new Connector(Connector::AX_X);
@@ -72,9 +72,9 @@ QRectF Multiplexer::boundingRect() const {
7272
}
7373

7474
void Multiplexer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) {
75-
painter->setPen(QColor(200, 200, 200));
76-
if (seton > 0 && seton <= size)
77-
painter->drawLine(0, (HEIGHT / 2) + ((seton - 1) * GAP), WIDTH, C_HEIGHT / 2);
75+
painter->setPen(QPen(QColor(200, 200, 200), 2));
76+
if (seton >= 0 && seton < (int)size)
77+
painter->drawLine(0, (HEIGHT / 2) + (seton * GAP), WIDTH, C_HEIGHT / 2);
7878

7979
painter->setPen(QColor(0, 0, 0));
8080
const QPointF poly[] = {
@@ -110,8 +110,10 @@ const Connector *Multiplexer::connector_in(unsigned i) const {
110110
return con_in[i];
111111
}
112112

113-
void Multiplexer::set(unsigned i) {
114-
seton = i;
115-
update();
113+
void Multiplexer::set(std::uint32_t i) {
114+
if (seton != (int)i) {
115+
seton = (int)i;
116+
update();
117+
}
116118
}
117119

0 commit comments

Comments
 (0)