From: Luke Kenneth Casson Leighton Date: Sun, 17 Dec 2023 22:24:13 +0000 (+0000) Subject: add first cut at parallel maxloc, adding random tests X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=920727ca3004bb5a6872c068a89ff6735c4cfd4c;p=openpower-isa.git add first cut at parallel maxloc, adding random tests --- diff --git a/src/openpower/decoder/isa/maxloc.py b/src/openpower/decoder/isa/maxloc.py index 83d89569..73553743 100644 --- a/src/openpower/decoder/isa/maxloc.py +++ b/src/openpower/decoder/isa/maxloc.py @@ -3,6 +3,8 @@ # License: LGPLv3+ # https://bugs.libre-soc.org/show_bug.cgi?id=676#c2 +from random import randint + def m2(a): m = 0; nm = 0; @@ -20,6 +22,36 @@ def m2(a): i += 1 return nm; +def sv_maxu(gpr, CR, vl, ra, rb, rt): + i = 0 + while i < vl: + CR[0] = cmpd(gpr[ra+i], gpr[rb]) + log("sv_maxss test", i, gpr[ra + i], gpr[rb], CR[0], int(CR[0])) + gpr[rt] = gpr[ra+i] if CR[0].lt else gpr[rb] + if not CR[0].gt: + break + i += 1 + return i # new VL + +# this version is more akin to SVP64, using an implementation of sv.minmax +def m3(a): + m = 0; + nm = 0; + i = 0; + n = len(a) + vl = 4 + + while (i m) : + print("%d idx %d > m %d" % (i, a[i], m)) + m = a[i] + nm = i + i += 1 + return nm; + # /*Testbench*/ test_data = [ @@ -35,3 +67,14 @@ if __name__ == '__main__': result = m2(arr) print("Index of the maximum value in an array is: %d" % result) assert (result == expected) + + # test m2 against m3 + for i in range(200): + array_len = randint(2, 15) + array = [] + for j in range(array_len): + array.append(randint(0, 20)) + print("randomised search list", array) + expected = m2(array) + print("Index of the maximum value in an array is: %d" % expected) + assert (m3(array) == expected)