From: Luke Kenneth Casson Leighton Date: Wed, 28 Sep 2022 18:33:00 +0000 (+0100) Subject: add limit argument to MASK() helper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=18a76a378d4eee1ca65641a8565fdfd8d5a7d977;p=openpower-isa.git add limit argument to MASK() helper --- diff --git a/src/openpower/decoder/helpers.py b/src/openpower/decoder/helpers.py index 7c231ae4..ba576b13 100644 --- a/src/openpower/decoder/helpers.py +++ b/src/openpower/decoder/helpers.py @@ -117,23 +117,23 @@ def MASK32(x, y): return MASK(x+32, y+32) -def MASK(x, y): +def MASK(x, y, lim=64): if isinstance(x, SelectableInt): x = x.value if isinstance(y, SelectableInt): y = y.value if x < y: - x = 64-x - y = 63-y - mask_a = ((1 << x) - 1) & ((1 << 64) - 1) - mask_b = ((1 << y) - 1) & ((1 << 64) - 1) + x = lim-x + y = (lim-1)-y + mask_a = ((1 << x) - 1) & ((1 << lim) - 1) + mask_b = ((1 << y) - 1) & ((1 << lim) - 1) elif x == y: - return 1 << (63-x) + return 1 << ((lim-1)-x) else: - x = 64-x - y = 63-y - mask_a = ((1 << x) - 1) & ((1 << 64) - 1) - mask_b = (~((1 << y) - 1)) & ((1 << 64) - 1) + x = lim-x + y = (lim-1)-y + mask_a = ((1 << x) - 1) & ((1 << lim) - 1) + mask_b = (~((1 << y) - 1)) & ((1 << lim) - 1) return mask_a ^ mask_b