summaryrefslogtreecommitdiff
path: root/infra/arbiter.h
diff options
context:
space:
mode:
Diffstat (limited to 'infra/arbiter.h')
-rw-r--r--infra/arbiter.h55
1 files changed, 0 insertions, 55 deletions
diff --git a/infra/arbiter.h b/infra/arbiter.h
deleted file mode 100644
index 79a9920..0000000
--- a/infra/arbiter.h
+++ /dev/null
@@ -1,55 +0,0 @@
1#pragma once
2
3#include <array>
4#include <cassert>
5
6#include "infra/sim.h"
7
8namespace infra {
9 template<typename T, unsigned int peers> struct priority_arbiter : public sim {
10 std::array<port<T>, peers> peerp;
11 port<T> *outp = nullptr;
12
13 void clock() {
14 for (unsigned int i = 0; i < peers; ++i) {
15 if (outp->can_write() && peerp[i].can_read())
16 outp->write(peerp[i].read());
17 }
18 }
19 };
20
21 template<typename T, unsigned int peers> struct round_robin_arbiter : public sim {
22 std::array<port<T>, peers> peerp;
23 port<T> *outp = nullptr;
24 unsigned int initial = 0;
25
26 void clock() {
27 bool initially_empty = outp->can_write();
28 for (unsigned int i = initial; i < peers; ++i) {
29 if (outp->can_write() && peerp[i].can_read())
30 outp->write(peerp[i].read());
31 }
32 for (unsigned int i = 0; i < initial; ++i) {
33 if (outp->can_write() && peerp[i].can_read())
34 outp->write(peerp[i].read());
35 }
36 if (initially_empty && !outp->can_write())
37 if (++initial == peers)
38 initial = 0;
39 }
40 };
41
42 template<typename T, unsigned int peers> struct shared_bus : public sim {
43 std::array<port<T>, peers> peerp;
44 port<T> *outp = nullptr;
45
46 void clock() {
47 for (unsigned int i = 0; i < peers; ++i) {
48 if (peerp[i].can_read()) {
49 assert(outp->can_write());
50 outp->write(peerp[i].read());
51 }
52 }
53 }
54 };
55}