From: Luke Kenneth Casson Leighton Date: Wed, 28 Jul 2021 18:04:52 +0000 (+0100) Subject: start on inverse DCT, transforming to iterative X-Git-Tag: xlen-bcd~188 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=09ddf103542595c2ca63cd54c9070ef2a9370356;p=openpower-isa.git start on inverse DCT, transforming to iterative --- diff --git a/src/openpower/decoder/isa/fastdct-test.py b/src/openpower/decoder/isa/fastdct-test.py index 14214b2b..033df0ff 100644 --- a/src/openpower/decoder/isa/fastdct-test.py +++ b/src/openpower/decoder/isa/fastdct-test.py @@ -27,8 +27,8 @@ import fastdctlee, naivedct, remap_dct_yield class FastDctTest(unittest.TestCase): - def tst_fast_dct_lee_vs_naive(self): - for i in range(3, 10): + def test_fast_dct_lee_vs_naive(self): + for i in range(3, 4): n = 2**i vector = FastDctTest.nonrandom_vector(n) expect = naivedct.transform(vector) @@ -36,10 +36,10 @@ class FastDctTest(unittest.TestCase): actual = fastdctlee.transform2(vector) self.assertListAlmostEqual(actual, expect) expect = naivedct.inverse_transform(vector) - actual = fastdctlee.inverse_transform(vector) + actual = fastdctlee.inverse_transform2(vector) self.assertListAlmostEqual(actual, expect) - def test_yield_dct_lee_vs_naive(self): + def tst_yield_dct_lee_vs_naive(self): for i in range(3, 4): n = 2**i vector = FastDctTest.nonrandom_vector(n) diff --git a/src/openpower/decoder/isa/fastdctlee.py b/src/openpower/decoder/isa/fastdctlee.py index 68678ab9..1fefc39b 100644 --- a/src/openpower/decoder/isa/fastdctlee.py +++ b/src/openpower/decoder/isa/fastdctlee.py @@ -310,37 +310,44 @@ def inverse_transform(vector, root=True, indent=0): inverse_transform(alpha, False, indent+1) inverse_transform(beta , False, indent+1) for i in range(half): - x = alpha[i] - y = beta[i] / (math.cos((i + 0.5) * math.pi / n) * 2) + x, y = alpha[i], beta[i] + coeff = (math.cos((i + 0.5) * math.pi / n) * 2) + y /= coeff vector[i] = x + y - vector[-(i + 1)] = x - y + vector[n-(i+1)] = x - y print (idt, " v[%d] = alpha[%d]+beta[%d]" % (i, i, i)) print (idt, " v[%d] = alpha[%d]-beta[%d]" % (n-i-1, i, i)) return vector -def inverse_transform2(vector, root=True): +def inverse_transform2(vector, root=True, indent=0): + idt = " " * indent n = len(vector) if root: vector = list(vector) + vector[0] /= 2 if n == 1: return vector elif n == 0 or n % 2 != 0: raise ValueError() else: half = n // 2 - alpha = [0] - beta = [1] + alpha = [vector[0]] + beta = [vector[1]] for i in range(2, n, 2): - alpha.append(i) - beta.append(("add", i - 1, i + 1)) - inverse_transform2(alpha, False) - inverse_transform2(beta , False) + alpha.append(vector[i]) + beta.append(vector[i - 1] + vector[i + 1]) + inverse_transform2(alpha, False, indent+1) + inverse_transform2(beta , False, indent+1) for i in range(half): + x, y = alpha[i], beta[i] + coeff = (math.cos((i + 0.5) * math.pi / n) * 2) + y /= coeff + vector[i] = x + y + vector[n-(i+1)] = x - y + print (idt, " v[%d] = alpha[%d]+beta[%d]" % (i, i, i)) + print (idt, " v[%d] = alpha[%d]-beta[%d]" % (n-i-1, i, i)) x = alpha[i] - y = ("cos", beta[i], i) - vector[i] = ("add", x, y) - vector[-(i + 1)] = ("sub", x, y) return vector