SILICON
Loading...
Searching...
No Matches
arithmetic.cpp
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#include "arithmetic.hpp"
19
20#include <core/wireUtils.hpp>
21#include <core/simulator.hpp>
22
23#include <algorithm>
24#include <limits>
25#include <ranges>
26#include <stdexcept>
27#include <tuple>
28#include <utility>
29#include <variant>
30
31namespace SILICON::extra {
32using namespace SILICON::core;
33
35{
36 defineProperty("inSize", 4);
37 defineProperty("outSize", 8);
38 defineStringListProperty("mode", std::string(UNSIGNED_MODE),
39 {std::string(UNSIGNED_MODE), std::string(SIGNED_MODE)});
40
41 setPropertyCallback("inSize", [this](const PropertyValue& value) {
42 const int width = std::get<int>(requireValidSize("Extender inSize", value));
43 if (!inputs.empty())
44 setInputSize(width);
45 return value;
46 });
47 setPropertyCallback("outSize", [this](const PropertyValue& value) {
48 const int width = std::get<int>(requireValidSize("Extender outSize", value));
49 if (!outputs.empty())
50 setOutputSize(width);
51 return value;
52 });
53}
54
55Extender::Extender(Bus in, Bus out, std::string mode) : Extender()
56{
57 if (in.size() == 0 || out.size() == 0)
58 throw std::invalid_argument("Extender buses must not be empty");
59
60 setProperty("inSize", static_cast<int>(in.size()));
61 setProperty("outSize", static_cast<int>(out.size()));
62 setProperty("mode", mode);
63 inputs = {std::move(in)};
64 outputs = {std::move(out)};
65}
66
67int Extender::setInputSize(const int width)
68{
69 if (width < 1 || width > std::numeric_limits<unsigned short>::max())
70 return getPropertyValue<int>("inSize").value_or(4);
71
72 auto newInputs = getInputs();
73 if (newInputs.empty())
74 newInputs.resize(1);
75 newInputs[0].setSize(static_cast<unsigned short>(width));
76 setInputs(newInputs);
77 return width;
78}
79
80int Extender::setOutputSize(const int width)
81{
82 if (width < 1 || width > std::numeric_limits<unsigned short>::max())
83 return getPropertyValue<int>("outSize").value_or(8);
84
85 auto newOutputs = getOutputs();
86 if (newOutputs.empty())
87 newOutputs.resize(1);
88 newOutputs[0].setSize(static_cast<unsigned short>(width));
89 setOutputs(newOutputs);
90 return width;
91}
92
94{
95 if (inputs.size() != 1 || outputs.size() != 1 || inputs[0].size() == 0)
96 return;
97
98 auto value = inputs[0].getCurrentValue();
99
100 const bool signedMode =
101 getPropertyValue<std::string>("mode").value_or(std::string(UNSIGNED_MODE))
102 == SIGNED_MODE;
103
104 const State extension = signedMode ? value.back() : State::LOW;
105 value = wireUtils::normalizeBusValue(value, outputs[0].size(), extension);
106
107 sim.updateBus(outputs[0], value, 0, weak_from_this());
108}
110{
111 defineProperty("delay", 0);
112 defineProperty("size", 4);
113
114 setPropertyCallback("delay", [](const PropertyValue& value) {
115 return requireNonNegative("Complementer delay", value);
116 });
117
118 setPropertyCallback("size", [this](const PropertyValue& value) {
119 const int size = std::get<int>(requireValidSize("Complementer size", value));
120
121 if (!inputs.empty() && !outputs.empty())
122 setSize(size);
123
124 return value;
125 });
126}
127
129{
130 if (in.size() == 0 || in.size() != out.size())
131 throw std::invalid_argument(
132 "Complementer: input bus width must match non-empty output bus width");
133
134 setProperty("size", static_cast<int>(in.size()));
135 inputs = {std::move(in)};
136 outputs = {std::move(out)};
137}
138
139int Complementer::setSize(const int width)
140{
141 if (width < 1 || width > std::numeric_limits<unsigned short>::max())
142 return getPropertyValue<int>("size").value_or(4);
143
144 auto newInputs = getInputs();
145 if (newInputs.empty())
146 newInputs.resize(1);
147 newInputs[0].setSize(static_cast<unsigned short>(width));
148 setInputs(newInputs);
149
150 auto newOutputs = getOutputs();
151 if (newOutputs.empty())
152 newOutputs.resize(1);
153 newOutputs[0].setSize(static_cast<unsigned short>(width));
154 setOutputs(newOutputs);
155
156 return width;
157}
158
160{
161 if (inputs.size() != 1 || outputs.size() != 1 || inputs[0].size() != outputs[0].size())
162 return;
163
164 const int propagationDelay = getPropertyValue<int>("delay").value_or(0);
165 const auto complement = twosComplement(inputs[0].getCurrentValue());
166 sim.updateBus(outputs[0], complement, propagationDelay, weak_from_this());
167}
168
170{
171 defineProperty("delay", 2);
172 setPropertyCallback("delay", [](const PropertyValue& value) {
173 return requireNonNegative("HalfAdder delay", value);
174 });
175}
176
177HalfAdder::HalfAdder(std::array<Wire_ptr, 2> inputWires, Wire_ptr sum, Wire_ptr cout)
178 : HalfAdder()
179{
180 inputs = {{std::move(inputWires[busIndex(Inputs::A)])},
181 {std::move(inputWires[busIndex(Inputs::B)])}};
182 outputs = {{std::move(sum)}, {std::move(cout)}};
183}
184
186{
188 return;
189
190 const State a = inputState(Inputs::A);
191 const State b = inputState(Inputs::B);
192 const int propagationDelay = getPropertyValue<int>("delay").value_or(0);
193
194 sim.updateWire(outputWire(Outputs::Sum), a ^ b, propagationDelay, weak_from_this());
195 sim.updateWire(outputWire(Outputs::Cout), a && b, propagationDelay, weak_from_this());
196}
197
199{
200 defineProperty("delay", 3);
201 setPropertyCallback("delay", [](const PropertyValue& value) {
202 return requireNonNegative("FullAdder delay", value);
203 });
204}
205
206FullAdder::FullAdder(std::array<Wire_ptr, 2> inputWires, Wire_ptr cin, Wire_ptr sum,
207 Wire_ptr cout)
208 : FullAdder()
209{
210 inputs = {{std::move(inputWires[busIndex(Inputs::A)])},
211 {std::move(inputWires[busIndex(Inputs::B)])},
212 {std::move(cin)}};
213 outputs = {{std::move(sum)}, {std::move(cout)}};
214}
215
217{
219 return;
220
221 const State a = inputState(Inputs::A);
222 const State b = inputState(Inputs::B);
223 const State cin = inputState(Inputs::Cin);
224 const State sum = a ^ b ^ cin;
225 const State cout = (a && b) || (cin && (a ^ b));
226 const int propagationDelay = getPropertyValue<int>("delay").value_or(0);
227
228 sim.updateWire(outputWire(Outputs::Sum), sum, propagationDelay, weak_from_this());
229 sim.updateWire(outputWire(Outputs::Cout), cout, propagationDelay, weak_from_this());
230}
231
233{
234 defineProperty("delay", 5);
235 defineProperty("size", 4);
236
237 setPropertyCallback("delay", [](const PropertyValue& value) {
238 return requireNonNegative("AdderNBits delay", value);
239 });
240 setPropertyCallback("size", [this](const PropertyValue& value) {
241 const int size = std::get<int>(requireValidSize("AdderNBits size", value));
242
243 if (!inputs.empty() && !outputs.empty())
244 setSize(size);
245
246 return value;
247 });
248}
249
250AdderNBits::AdderNBits(std::array<Bus, 2> inputBuses, Bus sum, Wire_ptr cout)
251 : AdderNBits()
252{
253 if (inputBuses[busIndex(Inputs::A)].size() != sum.size()
254 || inputBuses[busIndex(Inputs::B)].size() != sum.size()) {
255 throw std::invalid_argument("AdderNBits: input bus width must match sum bus width");
256 }
257
258 inputs = {inputBuses[busIndex(Inputs::A)], inputBuses[busIndex(Inputs::B)]};
259 outputs = {sum, {std::move(cout)}};
260 setProperty("size", static_cast<int>(sum.size()));
261}
262
263int AdderNBits::setSize(const int width)
264{
265 if (width < 1)
266 return getPropertyValue<int>("size").value_or(4);
267
268 auto newInputs = getInputs();
269 if (newInputs.size() < 2)
270 newInputs.resize(2);
271 newInputs[busIndex(Inputs::A)].setSize(static_cast<unsigned short>(width));
272 newInputs[busIndex(Inputs::B)].setSize(static_cast<unsigned short>(width));
273 setInputs(newInputs);
274
275 auto newOutputs = getOutputs();
276 if (newOutputs.size() < 2)
277 newOutputs.resize(2);
278 newOutputs[busIndex(Outputs::Sum)].setSize(static_cast<unsigned short>(width));
279 if (newOutputs[busIndex(Outputs::Cout)].size() != 1)
280 newOutputs[busIndex(Outputs::Cout)].setSize(1);
281 setOutputs(newOutputs);
282
283 return width;
284}
285
287{
289 return;
290
291 const auto propagationDelay = getPropertyValue<int>("delay").value_or(0);
292 const auto sumWidth = outputBusSize(Outputs::Sum);
293
294 auto result = inputs[busIndex(Inputs::A)].getCurrentValue()
295 + inputs[busIndex(Inputs::B)].getCurrentValue();
296
297 const State carry = result[sumWidth];
298 result.resize(sumWidth);
299
300 sim.updateBus(outputs[busIndex(Outputs::Sum)], result, propagationDelay,
301 weak_from_this());
302
303 sim.updateWire(outputWire(Outputs::Cout), carry, propagationDelay, weak_from_this());
304}
305
307{
308 defineProperty("delay", 0, [](const PropertyValue& value) {
309 return requireNonNegative("Shifter delay", value);
310 });
311 defineProperty("size", 4, [this](const PropertyValue& value) {
312 const int width = std::get<int>(requireValidSize("Shifter size", value));
313 if (!inputs.empty() && !outputs.empty())
314 setSize(width);
315 return value;
316 });
317 defineProperty("amountSize", 4, [this](const PropertyValue& value) {
318 const int width = std::get<int>(requireValidSize("Shifter amountSize", value));
319 if (inputs.size() == 2)
320 setAmountSize(width);
321 return value;
322 });
323 defineStringListProperty("mode", std::string(RIGHT_MODE),
324 {std::string(LEFT_MODE), std::string(RIGHT_MODE)});
325 defineProperty("signed", false);
326}
327
328Shifter::Shifter(Bus value, Bus amount, Bus result) : Shifter()
329{
330 if (value.size() == 0 || amount.size() == 0 || result.size() != value.size())
331 throw std::invalid_argument(
332 "Shifter: value and result must have the same non-zero width, and amount must be non-empty");
333 inputs = {std::move(value), std::move(amount)};
334 outputs = {std::move(result)};
335 setProperty("size", static_cast<int>(outputs[0].size()));
336 setProperty("amountSize", static_cast<int>(inputs[1].size()));
337}
338
339int Shifter::setSize(const int width)
340{
341 if (width < 1 || width > std::numeric_limits<unsigned short>::max())
342 return getPropertyValue<int>("size").value_or(4);
343 auto newInputs = getInputs();
344 if (newInputs.size() < 2)
345 newInputs.resize(2);
346 newInputs[0].setSize(static_cast<unsigned short>(width));
347 setInputs(newInputs);
348 auto newOutputs = getOutputs();
349 if (newOutputs.empty())
350 newOutputs.resize(1);
351 newOutputs[0].setSize(static_cast<unsigned short>(width));
352 setOutputs(newOutputs);
353 return width;
354}
355
356int Shifter::setAmountSize(const int width)
357{
358 if (width < 1 || width > std::numeric_limits<unsigned short>::max())
359 return getPropertyValue<int>("amountSize").value_or(4);
360 auto newInputs = getInputs();
361 if (newInputs.size() < 2)
362 newInputs.resize(2);
363 newInputs[1].setSize(static_cast<unsigned short>(width));
364 setInputs(newInputs);
365 return width;
366}
367
369{
370 if (inputs.size() != 2 || outputs.size() != 1 || inputs[0].size() == 0
371 || inputs[1].size() == 0 || outputs[0].size() != inputs[0].size())
372 return;
373
374 const BusValue value = inputs[0].getCurrentValue();
375 const BusValue amount = inputs[1].getCurrentValue();
376 BusValue result;
377 if (std::ranges::find(amount, State::ERROR) != amount.end()) {
378 result.assign(value.size(), State::ERROR);
379 } else if (std::ranges::find(amount, State::UNKNOWN) != amount.end()) {
380 result.assign(value.size(), State::UNKNOWN);
381 } else {
382 // Saturate before conversion so even a very wide amount cannot overflow.
383 std::size_t count = 0;
384 for (std::size_t bit = amount.size(); bit-- > 0;) {
385 count = std::min(value.size(), count * 2 + (amount[bit] == State::HIGH));
386 }
387 const bool left =
388 getPropertyValue<std::string>("mode").value_or(std::string(RIGHT_MODE)) == LEFT_MODE;
389 const auto signedness = getPropertyValue<bool>("signed").value_or(false)
391 result = shift(value, left ? -static_cast<ptrdiff_t>(count)
392 : static_cast<ptrdiff_t>(count), signedness);
393 }
394 sim.updateBus(outputs[0], result, getPropertyValue<int>("delay").value_or(0),
395 weak_from_this());
396}
397
398namespace {
399int resizeBinaryArithmetic(Component& component, const int width,
400 const std::size_t outputCount)
401{
402 if (width < 1 || width > std::numeric_limits<unsigned short>::max())
403 return component.getPropertyValue<int>("size").value_or(4);
404 auto inputs = component.getInputs();
405 inputs.resize(2);
406 for (auto& bus : inputs)
407 bus.setSize(static_cast<unsigned short>(width));
408 component.setInputs(inputs);
409 auto outputs = component.getOutputs();
410 outputs.resize(outputCount);
411 for (auto& bus : outputs)
412 bus.setSize(static_cast<unsigned short>(width));
413 component.setOutputs(outputs);
414 return width;
415}
416} // namespace
417
419{
420 defineProperty("delay", 0, [](const PropertyValue& value) {
421 return requireNonNegative("Multiplier delay", value);
422 });
423 defineProperty("size", 4, [this](const PropertyValue& value) {
424 const int width = std::get<int>(requireValidSize("Multiplier size", value));
425 if (!inputs.empty() && !outputs.empty())
426 setSize(width);
427 return value;
428 });
429 defineProperty("signed", false);
430}
431
432Multiplier::Multiplier(std::array<Bus, 2> inputBuses, Bus product) : Multiplier()
433{
434 const auto width = inputBuses[0].size();
435 if (width == 0 || inputBuses[1].size() != width || product.size() != width)
436 throw std::invalid_argument(
437 "Multiplier: all buses must have the same non-zero width");
438 inputs = {std::move(inputBuses[0]), std::move(inputBuses[1])};
439 outputs = {std::move(product)};
440 setProperty("size", static_cast<int>(width));
441}
442
443int Multiplier::setSize(const int width)
444{
445 return resizeBinaryArithmetic(*this, width, 1);
446}
447
449{
450 defineProperty("delay", 0, [](const PropertyValue& value) {
451 return requireNonNegative("Divider delay", value);
452 });
453 defineProperty("size", 4, [this](const PropertyValue& value) {
454 const int width = std::get<int>(requireValidSize("Divider size", value));
455 if (!inputs.empty() && !outputs.empty())
456 setSize(width);
457 return value;
458 });
459 defineProperty("signed", false);
460}
461
462Divider::Divider(std::array<Bus, 2> inputBuses, Bus quotient, Bus remainder) : Divider()
463{
464 const auto width = inputBuses[0].size();
465 if (width == 0 || inputBuses[1].size() != width || quotient.size() != width
466 || remainder.size() != width)
467 throw std::invalid_argument("Divider: all buses must have the same non-zero width");
468 inputs = {std::move(inputBuses[0]), std::move(inputBuses[1])};
469 outputs = {std::move(quotient), std::move(remainder)};
470 setProperty("size", static_cast<int>(width));
471}
472
473int Divider::setSize(const int width)
474{
475 return resizeBinaryArithmetic(*this, width, 2);
476}
477
479{
480 if (inputs.size() != 2 || outputs.size() != 1 || inputs[0].size() == 0
481 || inputs[1].size() != inputs[0].size() || outputs[0].size() != inputs[0].size())
482 return;
483 const auto sign = getPropertyValue<bool>("signed").value_or(false)
486 const auto product =
487 multiply(inputs[0].getCurrentValue(), inputs[1].getCurrentValue(), sign);
488 sim.updateBus(outputs[0], wireUtils::normalizeBusValue(product, outputs[0].size()),
489 getPropertyValue<int>("delay").value_or(0), weak_from_this());
490}
491
493{
494 if (inputs.size() != 2 || outputs.size() != 2 || inputs[0].size() == 0
495 || inputs[1].size() != inputs[0].size() || outputs[0].size() != inputs[0].size()
496 || outputs[1].size() != inputs[0].size())
497 return;
498 const auto dividend = inputs[0].getCurrentValue();
499 const auto divisor = inputs[1].getCurrentValue();
500 BusValue quotient, remainder;
501 if (std::ranges::all_of(divisor, [](State state) { return state == State::LOW; })) {
502 quotient.assign(outputs[0].size(), State::UNKNOWN);
503 remainder.assign(outputs[1].size(), State::UNKNOWN);
504 } else {
505 const auto sign = getPropertyValue<bool>("signed").value_or(false)
508 std::tie(quotient, remainder) = divide(dividend, divisor, sign);
509 }
510 const auto delay = getPropertyValue<int>("delay").value_or(0);
511 sim.updateBus(outputs[0], quotient, delay, weak_from_this());
512 sim.updateBus(outputs[1], remainder, delay, weak_from_this());
513}
514
516{
517 defineProperty("delay", 0, [this](const PropertyValue& value) {
518 const auto validated = requireNonNegative("Comparator delay", value);
519 this->propagationDelay = static_cast<uint64_t>(std::get<int>(value));
520 return validated;
521 });
522
523 defineProperty("size", 4, [this](const PropertyValue& value) {
524 const int size = std::get<int>(requireValidSize("Comparator size", value));
525
526 if (!inputs.empty() && !outputs.empty())
527 setSize(size);
528
529 return value;
530 });
531
532 defineStringListProperty("mode", "==", {"==", "<", "<=", ">", ">="});
533 defineProperty("signed", false);
534}
535
537{
538 if (inputBuses[0].size() == 0 || inputBuses[0].size() != inputBuses[1].size())
539 throw std::invalid_argument(
540 "Comparator: input buses must have the same non-zero width");
541
542 this->inputs = {std::move(inputBuses[0]), std::move(inputBuses[1])};
543 this->outputs = {{std::move(output)}};
544
545 const int size = static_cast<int>(inputs[0].size());
546 setProperty("size", size);
547}
548
550{
551 const BusValue a = inputs[0].getCurrentValue();
552 const BusValue b = inputs[1].getCurrentValue();
553
554 const auto setOutput = [this, &sim](const State s) {
555 sim.updateWire(outputs[0][0], s, propagationDelay, weak_from_this());
556 };
557
558 const auto isError = [](const BusValue& value) {
559 return std::ranges::any_of(value,
560 [](const State state) { return state == State::ERROR; });
561 };
562
563 if (isError(a) || isError(b)) {
565 return;
566 }
567
568 const auto isSigned = getPropertyValue<bool>("signed").value_or(false);
569 const auto compareResult =
570 compare(a, b, static_cast<Signedness>(isSigned));
571
572 if (compareResult == std::partial_ordering::unordered) {
574 return;
575 }
576
577 const auto checkForOrdering = [compareResult](std::string_view mode) {
578 const auto modeWantEquivalent = {"==", "<=", ">="};
579 const auto modeWantLess = {"<", "<="};
580 const auto modeWantGreat = {">", ">="};
581
582 // clang-format off
583 if ((std::ranges::contains(modeWantEquivalent, mode) && compareResult == std::partial_ordering::equivalent) ||
584 (std::ranges::contains(modeWantLess, mode) && compareResult == std::partial_ordering::less) ||
585 (std::ranges::contains(modeWantGreat, mode) && compareResult == std::partial_ordering::greater))
586 return State::HIGH;
587
588 return State::LOW;
589 };
590 // clang-format on
591
592 const auto mode = getPropertyValue<std::string>("mode").value_or("==");
593 setOutput(checkForOrdering(mode));
594}
595
596int Comparator::setSize(const int width)
597{
598 if (width < 1)
599 return getPropertyValue<int>("size").value_or(4);
600
601 auto newInputs = inputs;
602 if (inputs.size() < 2)
603 newInputs.resize(2);
604
605 newInputs[0].setSize(width);
606 newInputs[1].setSize(width);
607
608 this->inputs = newInputs;
609
610 return width;
611}
612
613} // namespace SILICON::extra
Base class for all digital circuit components.
static constexpr unsigned int busIndex(Enum value)
Converts a component-local bus enum to its storage index.
Wire_ptr outputWire(unsigned int output, unsigned short bit=0) const
const std::vector< Bus > & inputBuses() const
Gets all input buses without copying.
State inputState(unsigned int input, unsigned short bit=0) const
void setOutputs(const std::vector< Bus > &newOutputs)
Replaces all output buses.
std::optional< T > getPropertyValue(std::string_view key) const
Gets a property value with type deduction.
std::vector< Bus > outputs
Output buses produced by this component.
void setInputs(const std::vector< Bus > &newInputs)
Replaces all input buses.
void setProperty(std::string_view key, const PropertyValue &value)
Sets a property value.
std::vector< Bus > getOutputs() const
Gets all output buses.
std::vector< Bus > inputs
Input buses connected to this component.
void defineStringListProperty(std::string key, std::string defaultValue, StringPropertyOptions allowedValues, PropertyCallback callback=nullptr)
Defines a string property constrained to a fixed set of values.
Definition component.cpp:79
void setOutput(unsigned int index, const Bus &bus)
Sets an output bus at a specific index.
void setPropertyCallback(std::string_view key, PropertyCallback callback)
Sets a callback for property validation/transformation.
void defineProperty(std::string key, T &&defaultValue, PropertyCallback callback=nullptr)
Defines a property with a default value and optional callback.
std::size_t outputBusSize(unsigned int output) const
std::vector< Bus > getInputs() const
Gets all input buses.
@ Sum
Sum bus, least-significant bit first.
@ A
First addend bus, least-significant bit first.
@ B
Second addend bus, least-significant bit first.
int setSize(int width)
Resizes both inputs, the sum output, and the carry output.
void simulate(SILICON::simulation::Simulator &sim) override
Evaluates the N-bit adder.
AdderNBits()
Constructs an unconnected N-bit adder.
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
int setOutputSize(int width)
static constexpr std::string_view UNSIGNED_MODE
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
int setInputSize(int width)
static constexpr std::string_view SIGNED_MODE
void simulate(SILICON::simulation::Simulator &sim) override
Evaluates the full-adder truth table.
FullAdder()
Constructs an unconnected full adder.
HalfAdder()
Constructs an unconnected half adder.
void simulate(SILICON::simulation::Simulator &sim) override
Evaluates the half-adder truth table.
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
static constexpr std::string_view RIGHT_MODE
static constexpr std::string_view LEFT_MODE
int setAmountSize(int width)
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
Executes event-driven simulation of a Circuit.
Definition simulator.hpp:74
void updateBus(const Bus &bus, const BusValue &value, uint64_t delay, const Component_weakPtr &source)
Updates a bus to a new value through the normal wire-update path.
void updateWire(const Wire_ptr &target, State newState, uint64_t delay, const Component_weakPtr &source)
Updates a wire with a new state and optional delay.
std::shared_ptr< Wire > Wire_ptr
Definition wire.hpp:116
BusValue shift(const BusValue &v, const ptrdiff_t amount, const Signedness signedness)
Definition wire.cpp:367
std::partial_ordering compare(const BusValue &lhs, const BusValue &rhs, const Signedness signedness)
Definition wire.cpp:289
std::variant< int, bool, std::string, BusValue > PropertyValue
Variant type for component properties.
PropertyValue requireValidSize(const std::string_view name, const PropertyValue &value)
Validates that an integer property value is a valid bus size.
Definition component.cpp:38
std::pair< BusValue, BusValue > divide(const BusValue &a, const BusValue &b, Signedness signedness)
Definition wire.cpp:425
PropertyValue requireNonNegative(const std::string_view name, const PropertyValue &value)
Validates that an integer property value is non-negative.
Definition component.cpp:29
BusValue twosComplement(const BusValue &n)
Definition wire.cpp:272
BusValue multiply(const BusValue &a, const BusValue &b, const Signedness signedness)
Definition wire.cpp:388
std::vector< State > BusValue
Definition wire.hpp:120
BusValue normalizeBusValue(const BusValue &value, const std::size_t width, const State extension)
Resize an LSB-first value to an exact bus width.
Definition wire.cpp:121