please check below bit operations example (in build 1001):
Code: Select all
open bit
class predicates
getHighBitMask32_oldStyle : (unsigned X) -> unsigned Mask.
clauses
getHighBitMask32_oldStyle(X) = bitAnd(X_6, bitNot(bitRight(X_6, 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)).
class predicates
getHighBitMask32_newStyle : (unsigned X) -> unsigned Mask.
clauses
getHighBitMask32_newStyle(X) = X_6 ** ~~(X_6 >> 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.
clauses
run() :-
X = 1,
Result_oldStyle = getHighBitMask32_oldStyle(X),
Result_newStyle = getHighBitMask32_newStyle(X),
stdIO::write(Result_oldStyle, '/', Result_newStyle).