value range propagation for _bitwise_ OR
Ellery Newcomer
ellery-newcomer at utulsa.edu
Sat Dec 4 11:32:51 PST 2010
On 12/04/2010 01:21 PM, Ellery Newcomer wrote:
> is it just me, or does this fail for
>
> minA = 0
> minB = 0
> maxA = 0x80_00_00_00
> maxB = 0x80_00_00_00
>
> I'm pretty sure you need to handle 1<< 32 specially
i'm thinking this is better:
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;
a = a & maxA & maxB;
if (a != 0)
a = (1 << highbit (a)) - 1;
}
uint32_t b = maxB ^ minB;
if (b != 0) {
b |= (1 << highbit (b)) - 1;
b = b & maxA & maxB;
if (b != 0)
b = (1 << highbit (b)) - 1;
}
return maxA|maxB|a|b;
}
More information about the Digitalmars-d
mailing list