contur2
Loading...
Searching...
No Matches
alu.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include "contur/core/error.h"
11#include "contur/core/types.h"
12
13namespace contur {
14
20 class ALU
21 {
22 public:
23 ALU() = default;
24 ~ALU() = default;
25
26 // Copyable, movable (no state)
27 ALU(const ALU &) = default;
28 ALU &operator=(const ALU &) = default;
29 ALU(ALU &&) noexcept = default;
30 ALU &operator=(ALU &&) noexcept = default;
31
32 // Arithmetic operations
33
35 [[nodiscard]] Result<RegisterValue> add(RegisterValue a, RegisterValue b) const noexcept;
36
38 [[nodiscard]] Result<RegisterValue> sub(RegisterValue a, RegisterValue b) const noexcept;
39
41 [[nodiscard]] Result<RegisterValue> mul(RegisterValue a, RegisterValue b) const noexcept;
42
45 [[nodiscard]] Result<RegisterValue> div(RegisterValue a, RegisterValue b) const noexcept;
46
47 // Logic / bitwise operations
48
50 [[nodiscard]] Result<RegisterValue> bitwiseAnd(RegisterValue a, RegisterValue b) const noexcept;
51
53 [[nodiscard]] Result<RegisterValue> bitwiseOr(RegisterValue a, RegisterValue b) const noexcept;
54
56 [[nodiscard]] Result<RegisterValue> bitwiseXor(RegisterValue a, RegisterValue b) const noexcept;
57
59 [[nodiscard]] Result<RegisterValue> shiftLeft(RegisterValue a, RegisterValue b) const noexcept;
60
62 [[nodiscard]] Result<RegisterValue> shiftRight(RegisterValue a, RegisterValue b) const noexcept;
63
64 // Comparison
65
73 [[nodiscard]] RegisterValue compare(RegisterValue a, RegisterValue b) const noexcept;
74
75 // Flag constants
76
77 static constexpr RegisterValue ZERO_FLAG = 1;
78 static constexpr RegisterValue SIGN_FLAG = 2;
79 };
80
81} // namespace contur
ALU(ALU &&) noexcept=default
ALU & operator=(const ALU &)=default
RegisterValue compare(RegisterValue a, RegisterValue b) const noexcept
Compares two values and returns a flags word.
Result< RegisterValue > shiftLeft(RegisterValue a, RegisterValue b) const noexcept
Left shift: a << b.
Result< RegisterValue > bitwiseXor(RegisterValue a, RegisterValue b) const noexcept
Bitwise XOR: a ^ b.
Result< RegisterValue > div(RegisterValue a, RegisterValue b) const noexcept
Division: a / b.
ALU()=default
Result< RegisterValue > bitwiseOr(RegisterValue a, RegisterValue b) const noexcept
Bitwise OR: a | b.
ALU(const ALU &)=default
static constexpr RegisterValue ZERO_FLAG
a == b
Definition alu.h:77
Result< RegisterValue > shiftRight(RegisterValue a, RegisterValue b) const noexcept
Right shift: a >> b (arithmetic shift).
Result< RegisterValue > bitwiseAnd(RegisterValue a, RegisterValue b) const noexcept
Bitwise AND: a & b.
Result< RegisterValue > mul(RegisterValue a, RegisterValue b) const noexcept
Multiplication: a * b.
Result< RegisterValue > add(RegisterValue a, RegisterValue b) const noexcept
Addition: a + b.
Result< RegisterValue > sub(RegisterValue a, RegisterValue b) const noexcept
Subtraction: a - b.
static constexpr RegisterValue SIGN_FLAG
a < b
Definition alu.h:78
~ALU()=default
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
Error codes and Result<T> type for fallible operations.
Definition block.h:15
std::int32_t RegisterValue
Value stored in a CPU register.
Definition types.h:21
Common type aliases, sentinel constants, and forward declarations used throughout the Contur 2 kernel...