e3c28b6413c7c621c57b9cf8b153a136007d04a8
1 # SPDX-License-Identifier: LGPL-3-or-later
2 # Copyright 2022 Jacob Lifshay programmerjake@gmail.com
4 # Funded by NLnet Assure Programme 2021-02-052, https://nlnet.nl/assure part
5 # of Horizon 2020 EU Programme 957073.
8 from nmutil
.formaltest
import FHDLTestCase
9 from soc
.fu
.div
.experiment
.goldschmidt_div_sqrt
import (goldschmidt_div
,
13 class TestFixedPoint(FHDLTestCase
):
14 def test_str_roundtrip(self
):
15 for frac_wid
in range(8):
16 for bits
in range(-1 << 9, 1 << 9):
17 with self
.subTest(bits
=hex(bits
), frac_wid
=frac_wid
):
18 value
= FixedPoint(bits
, frac_wid
)
19 round_trip_value
= FixedPoint
.cast(str(value
))
20 self
.assertEqual(value
, round_trip_value
)
23 class TestGoldschmidtDiv(FHDLTestCase
):
25 assert isinstance(width
, int)
26 for d
in range(1, 1 << width
):
27 for n
in range(d
<< width
):
29 with self
.subTest(width
=width
, n
=hex(n
), d
=hex(d
),
30 expected
=hex(expected
)):
31 result
= goldschmidt_div(n
, d
, width
)
32 self
.assertEqual(result
, expected
, f
"result={hex(result)}")
34 def test_1_through_5(self
):
35 for width
in range(1, 5 + 1):
42 if __name__
== "__main__":