diff options
Diffstat (limited to '')
| -rw-r--r-- | infra/arbiter.h | 42 | ||||
| -rw-r--r-- | infra/pipetrace.cpp | 9 | ||||
| -rw-r--r-- | infra/pipetrace.h | 37 | ||||
| -rw-r--r-- | infra/port.h | 45 | ||||
| -rw-r--r-- | infra/queue.h | 29 | ||||
| -rw-r--r-- | infra/sim.cpp | 9 | ||||
| -rw-r--r-- | infra/sim.h | 38 | ||||
| -rw-r--r-- | infra/stat.h | 35 |
8 files changed, 0 insertions, 244 deletions
diff --git a/infra/arbiter.h b/infra/arbiter.h deleted file mode 100644 index 5dd1647..0000000 --- a/infra/arbiter.h +++ /dev/null | |||
| @@ -1,42 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cassert> | ||
| 4 | #include <optional> | ||
| 5 | #include <utility> | ||
| 6 | |||
| 7 | #include "infra/sim.h" | ||
| 8 | |||
| 9 | namespace infra { | ||
| 10 | template<typename T, unsigned int peers> struct priority_arbiter : public sim { | ||
| 11 | std::array<port<T>, peers> peerp; | ||
| 12 | port<T> *outp = nullptr; | ||
| 13 | |||
| 14 | void clock() { | ||
| 15 | for (unsigned int i = 0; i < peers; ++i) { | ||
| 16 | if (outp->can_write() && peerp[i].can_read()) | ||
| 17 | outp->write(peerp[i].read()); | ||
| 18 | } | ||
| 19 | } | ||
| 20 | }; | ||
| 21 | |||
| 22 | template<typename T, unsigned int peers> struct round_robin_arbiter : public sim { | ||
| 23 | std::array<port<T>, peers> peerp; | ||
| 24 | port<T> *outp = nullptr; | ||
| 25 | unsigned int initial = 0; | ||
| 26 | |||
| 27 | void clock() { | ||
| 28 | bool initially_empty = outp->can_write(); | ||
| 29 | for (unsigned int i = initial; i < peers; ++i) { | ||
| 30 | if (outp->can_write() && peerp[i].can_read()) | ||
| 31 | outp->write(peerp[i].read()); | ||
| 32 | } | ||
| 33 | for (unsigned int i = 0; i < initial; ++i) { | ||
| 34 | if (outp->can_write() && peerp[i].can_read()) | ||
| 35 | outp->write(peerp[i].read()); | ||
| 36 | } | ||
| 37 | if (initially_empty && !outp->can_write()) | ||
| 38 | if (++initial == peers) | ||
| 39 | initial = 0; | ||
| 40 | } | ||
| 41 | }; | ||
| 42 | } | ||
diff --git a/infra/pipetrace.cpp b/infra/pipetrace.cpp deleted file mode 100644 index e6642ef..0000000 --- a/infra/pipetrace.cpp +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | #include <cstdint> | ||
| 2 | #include <ostream> | ||
| 3 | |||
| 4 | #include "infra/pipetrace.h" | ||
| 5 | |||
| 6 | namespace infra { | ||
| 7 | std::ostream *pt::ptfile = nullptr; | ||
| 8 | std::uint64_t pt::next_record = 0; | ||
| 9 | } | ||
diff --git a/infra/pipetrace.h b/infra/pipetrace.h deleted file mode 100644 index 656b9b9..0000000 --- a/infra/pipetrace.h +++ /dev/null | |||
| @@ -1,37 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cstdint> | ||
| 4 | #include <fmt/format.h> | ||
| 5 | #include <ostream> | ||
| 6 | #include <string> | ||
| 7 | |||
| 8 | namespace infra { | ||
| 9 | struct transaction { | ||
| 10 | std::uint64_t record = ~(std::uint64_t)0; | ||
| 11 | }; | ||
| 12 | |||
| 13 | struct pt { | ||
| 14 | static std::ostream *ptfile; | ||
| 15 | |||
| 16 | static std::uint64_t next_record; | ||
| 17 | |||
| 18 | static transaction toplevel() { | ||
| 19 | transaction t; | ||
| 20 | t.record = next_record++; | ||
| 21 | return t; | ||
| 22 | } | ||
| 23 | |||
| 24 | static transaction child(const transaction &p) { | ||
| 25 | transaction t; | ||
| 26 | t.record = next_record++; | ||
| 27 | if (ptfile) | ||
| 28 | *ptfile << fmt::format("{} parent {}\n", t.record, p.record); | ||
| 29 | return t; | ||
| 30 | } | ||
| 31 | |||
| 32 | static void event(const transaction &t, const char *event, std::uint64_t time, const std::string &data) { | ||
| 33 | if (ptfile) | ||
| 34 | *ptfile << fmt::format("@{} {} {} {}\n", time, t.record, event, data); | ||
| 35 | } | ||
| 36 | }; | ||
| 37 | } | ||
diff --git a/infra/port.h b/infra/port.h deleted file mode 100644 index 06a3aa5..0000000 --- a/infra/port.h +++ /dev/null | |||
| @@ -1,45 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cassert> | ||
| 4 | #include <optional> | ||
| 5 | #include <utility> | ||
| 6 | |||
| 7 | #include "infra/sim.h" | ||
| 8 | |||
| 9 | namespace infra { | ||
| 10 | template<typename T> struct port : public sim { | ||
| 11 | std::optional<T> consumer_side; | ||
| 12 | std::optional<T> producer_side; | ||
| 13 | |||
| 14 | bool can_read() { return consumer_side.has_value(); } | ||
| 15 | bool can_write() { return !producer_side.has_value(); } | ||
| 16 | |||
| 17 | T read() { | ||
| 18 | assert(can_read()); | ||
| 19 | auto x = std::move(*consumer_side); | ||
| 20 | consumer_side.reset(); | ||
| 21 | return x; | ||
| 22 | } | ||
| 23 | |||
| 24 | const T & peek() { | ||
| 25 | assert(can_read()); | ||
| 26 | return *consumer_side; | ||
| 27 | } | ||
| 28 | |||
| 29 | void discard() { | ||
| 30 | consumer_side.reset(); | ||
| 31 | } | ||
| 32 | |||
| 33 | void write(T &&x) { | ||
| 34 | assert(can_write()); | ||
| 35 | producer_side = std::move(x); | ||
| 36 | } | ||
| 37 | |||
| 38 | void unclock() { | ||
| 39 | if (!consumer_side && producer_side) { | ||
| 40 | consumer_side = std::move(*producer_side); | ||
| 41 | producer_side.reset(); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | }; | ||
| 45 | } | ||
diff --git a/infra/queue.h b/infra/queue.h deleted file mode 100644 index 1e490bc..0000000 --- a/infra/queue.h +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cassert> | ||
| 4 | #include <deque> | ||
| 5 | #include <optional> | ||
| 6 | #include <utility> | ||
| 7 | |||
| 8 | #include "infra/port.h" | ||
| 9 | #include "infra/sim.h" | ||
| 10 | |||
| 11 | namespace infra { | ||
| 12 | template<typename T, unsigned int size> struct queue : public sim { | ||
| 13 | port<T> input; | ||
| 14 | port<T> *output = nullptr; | ||
| 15 | std::deque<T> elements; | ||
| 16 | |||
| 17 | void clock() { | ||
| 18 | if (input.can_read() && elements.size() < size) { | ||
| 19 | auto x = input.read(); | ||
| 20 | elements.emplace_back(std::move(x)); | ||
| 21 | } | ||
| 22 | if (output->can_write() && !elements.empty()) { | ||
| 23 | auto &x = elements.front(); | ||
| 24 | output->write(std::move(x)); | ||
| 25 | elements.pop_front(); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | }; | ||
| 29 | } | ||
diff --git a/infra/sim.cpp b/infra/sim.cpp deleted file mode 100644 index 21acc8c..0000000 --- a/infra/sim.cpp +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | #include <cstdint> | ||
| 2 | #include <vector> | ||
| 3 | |||
| 4 | #include "infra/sim.h" | ||
| 5 | |||
| 6 | namespace infra { | ||
| 7 | std::vector<sim *> sim::sims; | ||
| 8 | std::uint64_t sim::now = 0; | ||
| 9 | } | ||
diff --git a/infra/sim.h b/infra/sim.h deleted file mode 100644 index 185916a..0000000 --- a/infra/sim.h +++ /dev/null | |||
| @@ -1,38 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cstdint> | ||
| 4 | #include <string> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "infra/pipetrace.h" | ||
| 8 | |||
| 9 | namespace infra { | ||
| 10 | struct sim { | ||
| 11 | virtual void clock() {} | ||
| 12 | virtual void unclock() {} | ||
| 13 | |||
| 14 | static std::vector<sim *> sims; | ||
| 15 | |||
| 16 | static std::uint64_t now; | ||
| 17 | |||
| 18 | sim() { | ||
| 19 | sims.emplace_back(this); | ||
| 20 | } | ||
| 21 | |||
| 22 | virtual ~sim() { | ||
| 23 | std::erase(sims, this); | ||
| 24 | } | ||
| 25 | |||
| 26 | static void advance() { | ||
| 27 | for (auto &s : sims) | ||
| 28 | s->clock(); | ||
| 29 | for (auto &s : sims) | ||
| 30 | s->unclock(); | ||
| 31 | ++now; | ||
| 32 | } | ||
| 33 | |||
| 34 | void pte(const transaction &t, const char *event, const std::string &data) { | ||
| 35 | pt::event(t, event, now, data); | ||
| 36 | } | ||
| 37 | }; | ||
| 38 | } | ||
diff --git a/infra/stat.h b/infra/stat.h deleted file mode 100644 index f1ca75a..0000000 --- a/infra/stat.h +++ /dev/null | |||
| @@ -1,35 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <fmt/format.h> | ||
| 4 | #include <utility> | ||
| 5 | |||
| 6 | #include "infra/sim.h" | ||
| 7 | |||
| 8 | namespace infra { | ||
| 9 | struct stat : public sim { | ||
| 10 | std::string name; | ||
| 11 | std::uint64_t numerator = 0; | ||
| 12 | std::uint64_t denominator = 0; | ||
| 13 | |||
| 14 | stat(std::string name) | ||
| 15 | : name(std::move(name)) | ||
| 16 | { } | ||
| 17 | |||
| 18 | ~stat() { | ||
| 19 | fmt::print("# {} {}\n", name, (double)numerator/(double)denominator); | ||
| 20 | } | ||
| 21 | |||
| 22 | void unclock() { | ||
| 23 | ++denominator; | ||
| 24 | } | ||
| 25 | |||
| 26 | stat & operator++() { | ||
| 27 | ++numerator; | ||
| 28 | return *this; | ||
| 29 | } | ||
| 30 | |||
| 31 | stat & operator++(int) { | ||
| 32 | return operator++(); | ||
| 33 | } | ||
| 34 | }; | ||
| 35 | } | ||
