Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef ASIC_SIMULATION_INSTRUCTION_H
#define ASIC_SIMULATION_INSTRUCTION_H
#include "../number.h"
#include <cstddef>
#include <cstdint>
#include <optional>
namespace asic {
enum class instruction_type : std::uint8_t {
push_input, // push(inputs[index])
push_result, // push(results[index])
push_delay, // push(delays[index])
push_constant, // push(value)
truncate, // push(trunc(pop(), bit_mask))
addition, // push(pop() + pop())
subtraction, // push(pop() - pop())
multiplication, // push(pop() * pop())
division, // push(pop() / pop())
min, // push(min(pop(), pop()))
max, // push(max(pop(), pop()))
square_root, // push(sqrt(pop()))
complex_conjugate, // push(conj(pop()))
absolute, // push(abs(pop()))
constant_multiplication, // push(pop() * value)
update_delay, // delays[index] = pop()
custom, // Custom operation. Uses custom_source[index].
forward_value // Forward the current value on the stack (push(pop()), i.e. do nothing).
};
using result_index_t = std::uint16_t;
struct instruction final {
constexpr instruction() noexcept
: index(0)
, result_index(0)
, type(instruction_type::forward_value) {}
union {
// Index used by push_input, push_result, delay and custom.
std::size_t index;
// Bit mask used by truncate.
std::int64_t bit_mask;
// Constant value used by push_constant and constant_multiplication.
number value;
};
// Index into where the result of the instruction will be stored. If the result should be ignored, this index will be one past the last valid result index.
result_index_t result_index;
// Specifies what kind of operation the instruction should execute.
instruction_type type;
};
} // namespace asic
#endif // ASIC_SIMULATION_INSTRUCTION_H