SILICON
Loading...
Searching...
No Matches
multiplexer.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <string>
21#include <string_view>
22#include <vector>
23
24#include <core/component.hpp>
25#include <core/wire.hpp>
26
27namespace SILICON::extra {
28using namespace SILICON::core;
29
30class Multiplexer : public Component {
31private:
32 std::vector<unsigned short> selectionTable;
33
34public:
35 static constexpr std::string_view Type = "Multiplexer";
36
37 enum class Inputs : unsigned int {
39 };
40
41 enum class Outputs : unsigned int {
42 Out = 0,
43 };
44
45 std::string_view typeName() const override { return Type; }
46 ComponentMetadata metadata() const override
47 {
48 return {"Multiplexer", "Selects one input bus using a selection bus.",
50 }
51
53 Multiplexer(Bus data, Bus selection, Wire_ptr output);
54
55 int setSelectionSize(int selectionSize);
56 int setBusSize(int busSize);
57
61 std::string setSelectionTable(const std::string& specification);
62 [[nodiscard]] const std::vector<unsigned short>& selectionTableIndices() const
63 {
64 return selectionTable;
65 }
66
67 void simulate(SILICON::simulation::Simulator& sim) override;
68 void serializeYosys(SILICON::yosys::SerializationContext& context) const override;
69};
70
71class Demultiplexer : public Component {
72public:
73 static constexpr std::string_view Type = "Demultiplexer";
74
75 enum class Inputs : unsigned int {
76 Data = 0,
78 };
79
80 enum class Outputs : unsigned int {
81 Out = 0,
82 };
83
84 std::string_view typeName() const override { return Type; }
85 ComponentMetadata metadata() const override
86 {
87 return {"Demultiplexer",
88 "Routes one data bit to one output selected by a selection bus.",
90 }
91
93 Demultiplexer(Bus data, Bus selection, Bus output);
94
95 int setSelectionSize(int selectionSize);
96 int setBusSize(int busSize);
97
98 void simulate(SILICON::simulation::Simulator& sim) override;
99 void serializeYosys(SILICON::yosys::SerializationContext& context) const override;
100};
101
102class Decoder : public Component {
103public:
104 static constexpr std::string_view Type = "Decoder";
105
106 enum class Inputs : unsigned int {
109 };
110
111 enum class Outputs : unsigned int {
112 Out = 0,
113 };
114
115 std::string_view typeName() const override { return Type; }
117 {
118 return {"Decoder", "Drives one output high from a binary selection bus when enabled.",
120 }
121
122 Decoder();
123 Decoder(Bus enable, Bus selection, Bus output);
124
125 int setSelectionSize(int selectionSize);
126
127 void simulate(SILICON::simulation::Simulator& sim) override;
128 void serializeYosys(SILICON::yosys::SerializationContext& context) const override;
129};
130
131} // namespace SILICON::extra
static constexpr std::string_view Type
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
void serializeYosys(SILICON::yosys::SerializationContext &context) const override
Lower this component into native Yosys netlist cells.
std::string_view typeName() const override
Gets the component type name.
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
int setSelectionSize(int selectionSize)
static constexpr std::string_view Type
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
void serializeYosys(SILICON::yosys::SerializationContext &context) const override
Lower this component into native Yosys netlist cells.
std::string_view typeName() const override
Gets the component type name.
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
int setSelectionSize(int selectionSize)
static constexpr std::string_view Type
std::vector< unsigned short > selectionTable
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
void serializeYosys(SILICON::yosys::SerializationContext &context) const override
Lower this component into native Yosys netlist cells.
std::string setSelectionTable(const std::string &specification)
std::string_view typeName() const override
Gets the component type name.
const std::vector< unsigned short > & selectionTableIndices() const
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
int setSelectionSize(int selectionSize)
Executes event-driven simulation of a Circuit.
Definition simulator.hpp:74
Mutable module-building interface passed to component serializers.
Definition netlist.hpp:174
std::shared_ptr< Wire > Wire_ptr
Definition wire.hpp:116