self.addr = Signal(range(iterations))
self.data = Signal(range(-M, M-1))
- angles = [int(round(M*math.atan(2**(-i))))
+ angles = [int(round(M*math.atan(2**(-i))/(math.pi/2)))
for i in range(self.iterations)]
self.mem = Memory(width=self.data.width,
sync += i.eq(0)
sync += state.eq(CordicState.RUNNING)
sync += anglerom.addr.eq(1)
- sync += self.ready.eq(1) # debug
with m.If(state == CordicState.RUNNING):
with m.If(z >= 0):
sync += x.eq(x - dx)
print(f"{zo:x} {frac}")
self.assertEqual(str(frac), zin.__str__())
asserted = True
+
+ real_sin = yield dut.sin
+ real_sin = self.get_frac(real_sin, dut.sin.width - 2)
+ diff = abs(real_sin - expected_sin)
+ print(f"{real_sin} {expected_sin} {diff}")
+ self.assertTrue(diff < 0.001)
+
yield
sim.add_sync_process(process)
sim.run()
def run_test_assert(self, z, fracbits=8):
- self.run_test(zin=z, fracbits=fracbits)
+ zpi = z * Float16(math.pi/2)
+ e_sin = math.sin(zpi)
+ e_cos = math.cos(zpi)
+ self.run_test(zin=z, fracbits=fracbits, expected_sin=e_sin,
+ expected_cos=e_cos)
def test_1(self):
- x = Float16(.31212)
+ x = Float16(1.0)
print(x)
self.run_test_assert(x)
- # def test_neg(self):
- # self.run_test_assert(-6)
+ def test_pi_4(self):
+ x = Float16(1/3)
+ print(x)
+ self.run_test_assert(x)
def test_rand(self):
for i in range(500):