Discussions related to Visual Prolog
Martin Meyer
VIP Member
Posts: 298
Joined: 14 Nov 2002 0:01

Bit Operations

Unread post by Martin Meyer »

Hello Thomas,

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).
In 32bit mode it outputs 1/1, but in 64bit mode 1/0.
Regards Martin
User avatar
Thomas Linder Puls
VIP Member
Posts: 1245
Joined: 28 Feb 2000 0:01

Re: Bit Operations

Unread post by Thomas Linder Puls »

Thank you. We will look at it. The calculation in 64bit is clearly wrong.
Regards Thomas Linder Puls
PDC
Post Reply