updating my code to the new bit operations I came upon a case with an unexpected result (in build 902):
Code: Select all
open bit
class predicates
getHighBitMask64_oldStyle : (unsigned64 X) -> unsigned64 Mask.
clauses
getHighBitMask64_oldStyle(X) = bitAnd(X_7, bitNot(bitRight(X_7, 1))) :-
X_1 = bitOr(X, bitRight(X, 1)),
X_2 = bitOr(X_1, bitRight(X_1, 1)),
X_3 = bitOr(X_2, bitRight(X_2, 2)),
X_4 = bitOr(X_3, bitRight(X_3, 4)),
X_5 = bitOr(X_4, bitRight(X_4, 8)),
X_6 = bitOr(X_5, bitRight(X_5, 16)),
X_7 = bitOr(X_6, bitRight(X_6, 32)).
class predicates
getHighBitMask64_newStyle : (unsigned64 X) -> unsigned64 Mask.
clauses
getHighBitMask64_newStyle(X) = X_7 ** ~~(X_7 >> 1) :-
X_1 = X ++ X >> 1,
X_2 = X_1 ++ X_1 >> 1,
X_3 = X_2 ++ X_2 >> 2,
X_4 = X_3 ++ X_3 >> 4,
X_5 = X_4 ++ X_4 >> 8,
X_6 = X_5 ++ X_5 >> 16,
X_7 = X_6 ++ X_6 >> 32.
clauses
run() :-
X = 4,
Result_oldStyle = getHighBitMask64_oldStyle(X),
Result_newStyle = getHighBitMask64_newStyle(X),
stdIO::write(Result_oldStyle, '/', Result_newStyle).