-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfu.py
37 lines (32 loc) · 940 Bytes
/
cfu.py
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
from amaranth import *
from amaranth_cfu import InstructionBase, InstructionTestBase, simple_cfu, CfuTestBase
import unittest
class MeanInstruction(InstructionBase):
def elab(self, m):
with m.If(self.start):
m.d.sync += self.output.eq(self.in0 + self.in1)
m.d.sync += self.done.eq(1)
with m.Else():
m.d.sync += self.done.eq(0)
class MeanInstructionTest(InstructionTestBase):
def create_dut(self):
return MeanInstruction()
def test(self):
self.verify([
(0, 0, 0),
(4, 5, 9),
(0xffffffff, 0xffffffff, 0xfffffffe),
])
def make_cfu():
return simple_cfu({
0: MeanInstruction(),
})
class CfuTest(CfuTestBase):
def create_dut(self):
return make_cfu()
def test(self):
return self.run_ops([
((0, 34, 35), 69),
])
if __name__ == "__main__":
unittest.main()