start implementing fp fused-mul-add pipeline
[ieee754fpu.git] / src / ieee754 / fpfma / util.py
1 from ieee754.fpcommon.fpbase import FPFormat
2 from nmigen.hdl.ast import signed, unsigned
3
4
5 def expanded_exponent_shape(fpformat):
6 assert isinstance(fpformat, FPFormat)
7 return signed(fpformat.e_width + 3)
8
9
10 EXPANDED_MANTISSA_EXTRA_LSBS = 3
11
12
13 def expanded_mantissa_shape(fpformat):
14 assert isinstance(fpformat, FPFormat)
15 return signed(fpformat.fraction_width * 3 +
16 2 + EXPANDED_MANTISSA_EXTRA_LSBS)
17
18
19 def multiplicand_mantissa_shape(fpformat):
20 assert isinstance(fpformat, FPFormat)
21 return unsigned(fpformat.fraction_width + 1)
22
23
24 def product_mantissa_shape(fpformat):
25 assert isinstance(fpformat, FPFormat)
26 return unsigned(multiplicand_mantissa_shape(fpformat).width * 2)
27
28
29 def get_fpformat(pspec):
30 width = pspec.width
31 assert isinstance(width, int)
32 fpformat = getattr(pspec, "fpformat", None)
33 if fpformat is None:
34 fpformat = FPFormat.standard(width)
35 else:
36 assert isinstance(fpformat, FPFormat)
37 assert width == fpformat.width
38 return fpformat