分类: C/C++
2009-07-23 17:58:36
1、
c = (w1|w2)&ox01010101;
或
c = (w1&w2)&ox01010101;
w1 = (w1&0xFEFEFEFE)>>1;
w2 = (w2&0xFEFEFEFE)>>1;
w = w1 + w2 +- c;
2、
#define
avg_nornd(a,b) (a&b)+(((a^b)&0xFEFEFEFE)>>1)
#define avg_rnd(a,b) ( a|b)- (((a^b)&0xFEFEFEFE)>>1)
3、
#define BYTE_VEC32(c) ((c)*0x01010101UL)
static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
{
return
(a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
}
static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
{
return
(a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
}
开动你牛X的脑袋~