avutil: Move av_rint64_clip_* to internal.h

The function is renamed to ff_rint64_clip()

This should avoid build failures on VS2012
Feel free to changes this to a different solution

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer 2015-11-15 02:35:02 +01:00
parent 08b520636e
commit 5c3dee7dad
2 changed files with 37 additions and 39 deletions

View File

@ -298,42 +298,6 @@ static av_always_inline av_const double av_clipd_c(double a, double amin, double
else return a;
}
/**
* Clip and convert a double value into the long long amin-amax range.
* This function is needed because conversion of floating point to integers when
* it does not fit in the integer's representation does not necessarily saturate
* correctly (usually converted to a cvttsd2si on x86) which saturates numbers
* > INT64_MAX to INT64_MIN. The standard marks such conversions as undefined
* behavior, allowing this sort of mathematically bogus conversions. This provides
* a safe alternative that is slower obviously but assures safety and better
* mathematical behavior.
* @param a value to clip
* @param amin minimum value of the clip range
* @param amax maximum value of the clip range
* @return clipped value
*/
static av_always_inline av_const int64_t av_rint64_clip_c(double a, int64_t amin, int64_t amax)
{
int64_t res;
#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
if (amin > amax) abort();
#endif
// INT64_MAX+1,INT64_MIN are exactly representable as IEEE doubles
// do range checks first
if (a >= 9223372036854775808.0)
return amax;
if (a <= -9223372036854775808.0)
return amin;
// safe to call llrint and clip accordingly
res = llrint(a);
if (res > amax)
return amax;
if (res < amin)
return amin;
return res;
}
/** Compute ceil(log2(x)).
* @param x value used to compute ceil(log2(x))
* @return computed ceiling of log2(x)
@ -547,9 +511,6 @@ static av_always_inline av_const int av_popcount64_c(uint64_t x)
#ifndef av_clipd
# define av_clipd av_clipd_c
#endif
#ifndef av_rint64_clip
# define av_rint64_clip av_rint64_clip_c
#endif
#ifndef av_popcount
# define av_popcount av_popcount_c
#endif

View File

@ -256,6 +256,43 @@ void avpriv_request_sample(void *avc,
# define ff_dlog(ctx, ...) do { if (0) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
#endif
/**
* Clip and convert a double value into the long long amin-amax range.
* This function is needed because conversion of floating point to integers when
* it does not fit in the integer's representation does not necessarily saturate
* correctly (usually converted to a cvttsd2si on x86) which saturates numbers
* > INT64_MAX to INT64_MIN. The standard marks such conversions as undefined
* behavior, allowing this sort of mathematically bogus conversions. This provides
* a safe alternative that is slower obviously but assures safety and better
* mathematical behavior.
* @param a value to clip
* @param amin minimum value of the clip range
* @param amax maximum value of the clip range
* @return clipped value
*/
static av_always_inline av_const int64_t ff_rint64_clip(double a, int64_t amin, int64_t amax)
{
int64_t res;
#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
if (amin > amax) abort();
#endif
// INT64_MAX+1,INT64_MIN are exactly representable as IEEE doubles
// do range checks first
if (a >= 9223372036854775808.0)
return amax;
if (a <= -9223372036854775808.0)
return amin;
// safe to call llrint and clip accordingly
res = llrint(a);
if (res > amax)
return amax;
if (res < amin)
return amin;
return res;
}
/**
* A wrapper for open() setting O_CLOEXEC.
*/