zkf 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. zkf/__init__.py +45 -0
  2. zkf/__main__.py +40 -0
  3. zkf/_core.py +1093 -0
  4. zkf/_tables/__init__.py +1 -0
  5. zkf/_tables/trans.py +69 -0
  6. zkf/_tables/trig.py +48 -0
  7. zkf/oracle.py +290 -0
  8. zkf/py.typed +0 -0
  9. zkf/rtl/_tables/_zkf_cordic_m16.v +105 -0
  10. zkf/rtl/_tables/_zkf_cordic_m18.v +106 -0
  11. zkf/rtl/_tables/_zkf_cordic_m24.v +109 -0
  12. zkf/rtl/_tables/_zkf_cordic_m27.v +111 -0
  13. zkf/rtl/_tables/_zkf_cordic_m32.v +113 -0
  14. zkf/rtl/_tables/_zkf_cordic_m36.v +115 -0
  15. zkf/rtl/_tables/_zkf_cordic_m48.v +121 -0
  16. zkf/rtl/_tables/_zkf_cordic_m53.v +124 -0
  17. zkf/rtl/_tables/_zkf_exp2_m16.v +161 -0
  18. zkf/rtl/_tables/_zkf_exp2_m18.v +161 -0
  19. zkf/rtl/_tables/_zkf_exp2_m24.v +353 -0
  20. zkf/rtl/_tables/_zkf_exp2_m27.v +161 -0
  21. zkf/rtl/_tables/_zkf_exp2_m32.v +225 -0
  22. zkf/rtl/_tables/_zkf_exp2_m36.v +353 -0
  23. zkf/rtl/_tables/_zkf_exp2_m48.v +161 -0
  24. zkf/rtl/_tables/_zkf_exp2_m53.v +225 -0
  25. zkf/rtl/_tables/_zkf_log2_m16.v +216 -0
  26. zkf/rtl/_tables/_zkf_log2_m18.v +216 -0
  27. zkf/rtl/_tables/_zkf_log2_m24.v +487 -0
  28. zkf/rtl/_tables/_zkf_log2_m27.v +216 -0
  29. zkf/rtl/_tables/_zkf_log2_m32.v +487 -0
  30. zkf/rtl/_tables/_zkf_log2_m36.v +849 -0
  31. zkf/rtl/_tables/_zkf_log2_m48.v +306 -0
  32. zkf/rtl/_tables/_zkf_log2_m53.v +487 -0
  33. zkf/rtl/_zkf_cordic.v +313 -0
  34. zkf/rtl/_zkf_div_core.v +283 -0
  35. zkf/rtl/_zkf_fixed_to_float.v +164 -0
  36. zkf/rtl/_zkf_horner.v +141 -0
  37. zkf/rtl/_zkf_normshift.v +281 -0
  38. zkf/rtl/_zkf_pack.v +226 -0
  39. zkf/rtl/_zkf_pmul.v +511 -0
  40. zkf/rtl/_zkf_rshift_sticky.v +197 -0
  41. zkf/rtl/_zkf_to_fixpoint.v +333 -0
  42. zkf/rtl/zkf_abs.v +12 -0
  43. zkf/rtl/zkf_add.v +526 -0
  44. zkf/rtl/zkf_addsub.v +51 -0
  45. zkf/rtl/zkf_atan2.v +892 -0
  46. zkf/rtl/zkf_cmp.v +67 -0
  47. zkf/rtl/zkf_cmp_comb.v +63 -0
  48. zkf/rtl/zkf_div.v +116 -0
  49. zkf/rtl/zkf_exp2.v +298 -0
  50. zkf/rtl/zkf_fma.v +566 -0
  51. zkf/rtl/zkf_from_int.v +121 -0
  52. zkf/rtl/zkf_is_finite.v +11 -0
  53. zkf/rtl/zkf_log2.v +432 -0
  54. zkf/rtl/zkf_mul.v +155 -0
  55. zkf/rtl/zkf_mul_ilog2.v +168 -0
  56. zkf/rtl/zkf_mul_ilog2_const.v +202 -0
  57. zkf/rtl/zkf_neg.v +14 -0
  58. zkf/rtl/zkf_pipe.v +54 -0
  59. zkf/rtl/zkf_resize.v +191 -0
  60. zkf/rtl/zkf_round.v +234 -0
  61. zkf/rtl/zkf_saturate.v +19 -0
  62. zkf/rtl/zkf_sincos.v +663 -0
  63. zkf/rtl/zkf_sort.v +65 -0
  64. zkf/rtl/zkf_to_int.v +123 -0
  65. zkf-0.1.0.dist-info/METADATA +357 -0
  66. zkf-0.1.0.dist-info/RECORD +69 -0
  67. zkf-0.1.0.dist-info/WHEEL +5 -0
  68. zkf-0.1.0.dist-info/licenses/LICENSE +201 -0
  69. zkf-0.1.0.dist-info/top_level.txt +1 -0
zkf/__init__.py ADDED
@@ -0,0 +1,45 @@
1
+ """ZKF (Zubax Kulibin float) engine: the bit-exact reference model plus the packaged RTL sources.
2
+
3
+ The value model is re-exported here; ``get_rtl()`` returns the Verilog modules shipped as package data.
4
+ """
5
+
6
+ from collections.abc import Mapping
7
+ from functools import cache
8
+ from importlib.resources import files
9
+ from importlib.resources.abc import Traversable
10
+ from types import MappingProxyType
11
+
12
+ from ._core import (
13
+ Atan2Result as Atan2Result,
14
+ CmpResult as CmpResult,
15
+ DivResult as DivResult,
16
+ Log2Result as Log2Result,
17
+ SinCos as SinCos,
18
+ Zkf as Zkf,
19
+ ZkfFormat as ZkfFormat,
20
+ )
21
+
22
+ # Changing the version causes a new release to be deployed and tagged when pushed to the main branch.
23
+ __version__ = "0.1.0"
24
+
25
+
26
+ @cache
27
+ def _load_rtl() -> Mapping[str, str]:
28
+ out: dict[str, str] = {}
29
+
30
+ def walk(node: Traversable, prefix: str) -> None:
31
+ for child in node.iterdir():
32
+ name = f"{prefix}{child.name}"
33
+ if child.is_dir():
34
+ walk(child, f"{name}/")
35
+ elif child.name.endswith(".v"):
36
+ out[name] = child.read_text(encoding="utf-8")
37
+
38
+ walk(files(__name__) / "rtl", "")
39
+ return MappingProxyType(dict(sorted(out.items())))
40
+
41
+
42
+ def get_rtl() -> Mapping[str, str]:
43
+ """Every packaged RTL module as a read-only mapping from POSIX path relative to ``zkf/rtl``
44
+ (e.g. ``zkf_add.v``, ``_tables/_zkf_exp2_m18.v``) to its Verilog source text."""
45
+ return _load_rtl()
zkf/__main__.py ADDED
@@ -0,0 +1,40 @@
1
+ """
2
+ Usage:
3
+ python -m zkf WEXP WMAN [VALUE]
4
+ """
5
+
6
+ import sys
7
+
8
+ from ._core import ZkfFormat, bits_to_signed
9
+
10
+
11
+ def main(argv: list[str]) -> None:
12
+ usage = f"usage: {argv[0]} WEXP WMAN [VALUE]"
13
+ if len(argv) not in (3, 4):
14
+ raise SystemExit(usage)
15
+
16
+ try:
17
+ fmt = ZkfFormat(int(argv[1]), int(argv[2]))
18
+ except ValueError as exc:
19
+ raise SystemExit(f"{usage} ({exc})")
20
+ print(f"WEXP={fmt.wexp} WMAN={fmt.wman} WFRAC={fmt.wfrac} WFULL={fmt.wfull} BIAS={fmt.bias}")
21
+ print(f"lowest = {fmt.lowest} ≈ {float(fmt.lowest):.3e}")
22
+ print(f"max = {fmt.max} ≈ {float(fmt.max):.3e}")
23
+ print(f"ε = {fmt.epsilon} ≈ {float(fmt.epsilon):.3e}")
24
+
25
+ bit_diagram = "s" + "e" * fmt.wexp + "f" * fmt.wfrac
26
+ print(bit_diagram)
27
+ print(("0123456789" * ((fmt.wfull + 10) // 10))[: fmt.wfull][::-1])
28
+ print("".join((f"{x}" * 10) for x in range(10))[: fmt.wfull][::-1])
29
+
30
+ if len(argv) > 3:
31
+ value = float(argv[3])
32
+ z = fmt.encode(value)
33
+ print(f"Value {value} represented in this format:")
34
+ print(f"signed decimal: {bits_to_signed(z.bits, fmt.wfull):+d}")
35
+ print(f"twos-complement: {z.bits:0{fmt.wfull}b}")
36
+ print(f" {bit_diagram}")
37
+
38
+
39
+ if __name__ == "__main__":
40
+ main(sys.argv)