On 19/04/16 21:36, Luca Barbato wrote:
> - *f->adaptcoeffs = ((res & ((~0UL) << 31)) ^ ((~0UL) << 30))
> >>
> + *f->adaptcoeffs = ((res & INT32_MIN) ^ (INT32_MIN >> 1)) >>
> (25 + (absres <= f->avg*3) + (absres <=
> f->avg*4/3));
This is still relying on implementation-defined behaviour by right-shifting a
negative signed integer (and on int being 32 bits). The compiler can still do
the wrong thing if it wants, but at least it now has to have documented that it
will in advance.
Maybe the second function below would be a preferable form, making it obvious
what's actually going on?
---
#include <stdio.h>
#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
#define FFSIGN(a) ((a) > 0 ? 1 : -1)
int wtf(int res, int avg)
{
int absres = FFABS(res);
if (absres)
return ((res & (-1<<31)) ^ (-1<<30)) >>
(25 + (absres <= avg*3) + (absres <= avg*4/3));
else
return 0;
}
int less_wtf(int res, int avg)
{
int absres = FFABS(res);
return -FFSIGN(res) *
((absres == 0) ? 0 :
(absres <= avg * 4 / 3) ? 8 :
(absres <= avg * 3) ? 16 :
32);
}
int main(void)
{
int res, avg, a, b;
for (res = -10000; res <= +10000; res++) {
for (avg = -10000; avg <= +10000; avg++) {
a = wtf(res, avg);
b = less_wtf(res, avg);
if (a != b) {
printf("Fails at %d, %d (%d, %d).\n", res, avg, a, b);
return 1;
}
}
}
return 0;
}
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel