document lookup table

This commit is contained in:
2026-07-06 11:28:20 +02:00
parent 6c6dc32822
commit d7bdfd2502
+9
View File
@@ -1,6 +1,12 @@
from typing import Callable
def pack_lut_4(f: Callable[..., int], order: tuple[int, int, int, int] = (0, 1, 2, 3)) -> int:
"""
Pack a 4-input Boolean function into a 16-bit LUT (Look-Up Table).
The function is evaluated for all 16 input combinations, and the result for input index ``i`` is stored in bit ``i`` of the returned integer.
The ``order`` parameter specifies how the input bits of the LUT index are mapped to the arguments of ``f``, allowing input permutations.
"""
lut = 0
for idx in range(16):
bits = [(idx >> i) & 1 for i in range(4)] # b0, b1, b2, b3
@@ -63,6 +69,9 @@ def F32_7(x0, x1, y0, y1):
return (x0 & x1 & y1) ^ (x0 & y0 & y1) ^ (x0 & y0) ^ (x1 & y0 & y1) ^ x1 ^ y0 ^ y1 ^ 1
def main():
"""
Derive TEA3 Look-Up Tables from F31 and F32 definitions.
"""
F31_orders = [
(0, 1, 2, 3),
(0, 1, 2, 3),