Fix bug in memory access of cleartext fixed-point values with binary circuits.

This commit is contained in:
Marcel Keller
2025-10-08 12:08:10 +11:00
parent a0c642db5d
commit 1986dce374

View File

@@ -1491,16 +1491,17 @@ class cbitfix(object):
malloc = staticmethod(lambda *args: cbits.malloc(*args))
n_elements = staticmethod(lambda: 1)
conv = staticmethod(lambda x: x)
load_mem = classmethod(lambda cls, *args: cls._new(cbits.load_mem(*args)))
load_mem = classmethod(lambda cls, *args: cls._new(
cbits.get_type(cls.k).load_mem(*args), adjust=False))
store_in_mem = lambda self, *args: self.v.store_in_mem(*args)
mem_size = staticmethod(lambda *args: 1)
size = 1
@classmethod
def _new(cls, value):
def _new(cls, value, adjust=True):
if isinstance(value, list):
return [cls._new(x) for x in value]
res = cls()
if cls.k < value.unit:
if cls.k < value.unit and adjust:
bits = value.bit_decompose(cls.k)
sign = bits[-1]
value += (sign << (cls.k)) * -1