value range propagation for _bitwise_ OR
Steven Schveighoffer
schveiguy at yahoo.com
Mon Apr 12 12:58:47 PDT 2010
On Mon, 12 Apr 2010 13:56:23 -0400, Jérôme M. Berger <jeberger at free.fr>
wrote:
> Here's a fast 100% precise solution:
>
> ==============================8<------------------------------
> uint32_t maxOr (uint32_t minA, uint32_t minB,
> uint32_t maxA, uint32_t maxB)
> {
> assert (minA <= maxA);
> assert (minB <= maxB);
>
> if (maxA == 0) return maxB;
> if (maxB == 0) return maxA;
>
> uint32_t a = maxA ^ minA;
> if (a != 0) {
> a = ((1 << (highbit (a)+1)) - 1) & maxA & maxB;
> if (a != 0)
> a = (1 << highbit (a)) - 1;
> }
>
> uint32_t b = maxB ^ minB;
> if (b != 0) {
> b = ((1 << (highbit (b)+1)) - 1) & maxA & maxB;
> if (b != 0)
> b = (1 << highbit (b)) - 1;
> }
>
> return maxA|maxB|a|b;
> }
> ------------------------------>8==============================
Fails for test case:
minA = 4, maxA = 4, minB = 4, maxB = 6 (outputs 7, accurate result is 6).
I'm not quite sure what you are trying to do, but I think you are on the
right path to getting a faster solution.
-Steve
More information about the Digitalmars-d
mailing list