From: Luke Kenneth Casson Leighton Date: Mon, 25 Sep 2023 13:59:33 +0000 (+0100) Subject: add basis of Context Manager for capturing which inputs and outputsa X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6479aa6ed404829f6a1eab296b42be772b532e39;p=openpower-isa.git add basis of Context Manager for capturing which inputs and outputsa are involved in a carry-roll-over math primitive. also very useful to generate (automated) unit tests --- diff --git a/src/openpower/decoder/isa/poly1305-donna.py b/src/openpower/decoder/isa/poly1305-donna.py index c192813e..1b728b25 100644 --- a/src/openpower/decoder/isa/poly1305-donna.py +++ b/src/openpower/decoder/isa/poly1305-donna.py @@ -67,6 +67,31 @@ def intercept(p1305, args, fn): return result +class Ctx: + """A ContextManager for noting the inputs and outputs for interception. + The idea is to create unit tests with these same inputs and record + the expected outputs + """ + + def __init__(self, log, variables, inputs, outputs): + self.log = log + self.variables = variables + self.inputs = inputs + self.outputs = outputs + + def print_vars(self, varnames): + for v in varnames: + print(" %s %s" % (v, repr(self.variables[v]))) + + def __enter__(self): + print("enter") + self.print_vars(self.inputs) + + def __exit__(self, *args): + print("exit", args, self.outputs) + self.print_vars(self.outputs) + + class Poly1305Donna(object): """Poly1305 authenticator""" @@ -119,9 +144,10 @@ class Poly1305Donna(object): print ("init t %x %x" % (t[0], t[1])) r = self.r = [0]*3 - r[0] = ( t[0] ) & 0xffc0fffffff - r[1] = ((t[0] >> 44) | (t[1] << 20)) & 0xfffffc0ffff - r[2] = ((t[1] >> 24) ) & 0x00ffffffc0f + with Ctx("init r<-t", locals(), ["r"], ["t"]): + r[0] = ( t[0] ) & 0xffc0fffffff + r[1] = ((t[0] >> 44) | (t[1] << 20)) & 0xfffffc0ffff + r[2] = ((t[1] >> 24) ) & 0x00ffffffc0f # h = 0 */ h = self.h = [0]*3