From 18a76a378d4eee1ca65641a8565fdfd8d5a7d977 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Wed, 28 Sep 2022 19:33:00 +0100 Subject: [PATCH] add limit argument to MASK() helper --- src/openpower/decoder/helpers.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 -- 2.30.2