From d8ae5d7fa919490b652f72a5a5f285f1992b1b61 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 17 Sep 2023 19:42:22 +0100 Subject: [PATCH] illustrate the intermediary step of converting poly1305-donna.py to a form that is "reasonably close" to how the SVP64 assembler, using REMAP Indexed, would work. https://bugs.libre-soc.org/show_bug.cgi?id=1157#c3 for details --- src/openpower/decoder/isa/poly1305-donna.py | 40 ++++++++++++++++----- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/openpower/decoder/isa/poly1305-donna.py b/src/openpower/decoder/isa/poly1305-donna.py index 91c6e7f8..66e4c4a1 100644 --- a/src/openpower/decoder/isa/poly1305-donna.py +++ b/src/openpower/decoder/isa/poly1305-donna.py @@ -158,14 +158,38 @@ class Poly1305Donna(object): print("finish %x %x %x" % (h0, h1, h2)) - c = 0 - h1 += c; c = (h1 >> 44); h1 &= ff; - h2 += c; c = (h2 >> 42); h2 &= f3; - h0 += c * 5; c = (h0 >> 44); h0 &= ff; - h1 += c; c = (h1 >> 44); h1 &= ff; - h2 += c; c = (h2 >> 42); h2 &= f3; - h0 += c * 5; c = (h0 >> 44); h0 &= ff; - h1 += c; + # commented-out from the original (left in for comparison), + # see https://bugs.libre-soc.org/show_bug.cgi?id=1157#c3 + # as to what is going on here + + #c = 0 + #h1 += c; c = (h1 >> 44); h1 &= ff; + #h2 += c; c = (h2 >> 42); h2 &= f3; + #h0 += c * 5; c = (h0 >> 44); h0 &= ff; + #h1 += c; c = (h1 >> 44); h1 &= ff; + #h2 += c; c = (h2 >> 42); h2 &= f3; + #h0 += c * 5; c = (h0 >> 44); h0 &= ff; + #h1 += c; + + # okaaay, first "preparation" for conversion to SVP64 REMAP/Indexed: + # extract the constants/indices from the original above and look for the + # common pattern, which is: + # h? += c * ?; c = (h? >> ??); h? &= ??; + + # these appear to be repeated twice + idxconsts = [ # hN c* shf + [1, 1, 44], + [2, 1, 42], + [0, 4, 44] + ] + c = 0 # start with carry=0 + for hidx, cmul, shf in idxconsts*2: # repeat the pattern twice + self.h[hidx] += c * cmul # don't worry about *1 + c = self.h[hidx] >> shf # these two could use dsrd + self.h[hidx] &= (1<