Delete some unused code

This commit is contained in:
Henrik Rydgård 2024-04-30 00:57:46 +02:00
parent 93c32e1e8d
commit 9745fa813f
4 changed files with 1 additions and 426 deletions

View file

@ -37,7 +37,6 @@
void imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input);
void imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input);
void mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input);
/* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */
COSTABLE(16);

View file

@ -29,183 +29,6 @@
#include "mathematics.h"
#include "compat.h"
/* Stein's binary GCD algorithm:
* https://en.wikipedia.org/wiki/Binary_GCD_algorithm */
int64_t av_gcd(int64_t a, int64_t b) {
int za, zb, k;
int64_t u, v;
if (a == 0)
return b;
if (b == 0)
return a;
za = ff_ctzll(a);
zb = ff_ctzll(b);
k = FFMIN(za, zb);
u = llabs(a >> za);
v = llabs(b >> zb);
while (u != v) {
if (u > v)
FFSWAP(int64_t, v, u);
v -= u;
v >>= ff_ctzll(v);
}
return (uint64_t)u << k;
}
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, AVRounding rnd)
{
int64_t r = 0;
av_assert2(c > 0);
av_assert2(b >=0);
av_assert2((unsigned)(rnd&~AV_ROUND_PASS_MINMAX)<=5 && (rnd&~AV_ROUND_PASS_MINMAX)!=4);
if (c <= 0 || b < 0 || !((unsigned)(rnd&~AV_ROUND_PASS_MINMAX)<=5 && (rnd&~AV_ROUND_PASS_MINMAX)!=4))
return INT64_MIN;
if (rnd & AV_ROUND_PASS_MINMAX) {
if (a == INT64_MIN || a == INT64_MAX)
return a;
rnd = (AVRounding)(rnd - AV_ROUND_PASS_MINMAX);
}
if (a < 0)
return -(uint64_t)av_rescale_rnd(-FFMAX(a, -INT64_MAX), b, c, (AVRounding)((int)rnd ^ (((int)rnd >> 1) & 1)));
if (rnd == AV_ROUND_NEAR_INF)
r = c / 2;
else if (rnd & 1)
r = c - 1;
if (b <= INT_MAX && c <= INT_MAX) {
if (a <= INT_MAX)
return (a * b + r) / c;
else {
int64_t ad = a / c;
int64_t a2 = (a % c * b + r) / c;
if (ad >= INT32_MAX && b && ad > (INT64_MAX - a2) / b)
return INT64_MIN;
return ad * b + a2;
}
} else {
#if 1
uint64_t a0 = a & 0xFFFFFFFF;
uint64_t a1 = a >> 32;
uint64_t b0 = b & 0xFFFFFFFF;
uint64_t b1 = b >> 32;
uint64_t t1 = a0 * b1 + a1 * b0;
uint64_t t1a = t1 << 32;
int i;
a0 = a0 * b0 + t1a;
a1 = a1 * b1 + (t1 >> 32) + (a0 < t1a);
a0 += r;
a1 += (int64_t)a0 < r;
for (i = 63; i >= 0; i--) {
a1 += a1 + ((a0 >> i) & 1);
t1 += t1;
if (c <= (int64_t)a1) {
a1 -= c;
t1++;
}
}
if (t1 > INT64_MAX)
return INT64_MIN;
return t1;
}
#else
AVInteger ai;
ai = av_mul_i(av_int2i(a), av_int2i(b));
ai = av_add_i(ai, av_int2i(r));
return av_i2int(av_div_i(ai, av_int2i(c)));
}
#endif
}
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
{
return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
}
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, AVRounding rnd)
{
int64_t b = bq.num * (int64_t)cq.den;
int64_t c = cq.num * (int64_t)bq.den;
return av_rescale_rnd(a, b, c, rnd);
}
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
{
return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF);
}
int av_reduce(int *dst_num, int *dst_den,
int64_t num, int64_t den, int64_t max)
{
AVRational a0 = { 0, 1 }, a1 = { 1, 0 };
int sign = (num < 0) ^ (den < 0);
int64_t gcd = av_gcd(FFABS(num), FFABS(den));
if (gcd) {
num = FFABS(num) / gcd;
den = FFABS(den) / gcd;
}
if (num <= max && den <= max) {
a1 = AVRational{ (int)num, (int)den };
den = 0;
}
while (den) {
uint64_t x = num / den;
int64_t next_den = num - den * x;
int64_t a2n = x * a1.num + a0.num;
int64_t a2d = x * a1.den + a0.den;
if (a2n > max || a2d > max) {
if (a1.num) x = (max - a0.num) / a1.num;
if (a1.den) x = FFMIN(x, (max - a0.den) / a1.den);
if (den * (2 * x * a1.den + a0.den) > num * a1.den)
a1 = AVRational{(int)(x * a1.num + a0.num), (int)(x * a1.den + a0.den) };
break;
}
a0 = a1;
a1 = AVRational{(int)a2n, (int)a2d };
num = den;
den = next_den;
}
av_assert2(av_gcd(a1.num, a1.den) <= 1U);
av_assert2(a1.num <= max && a1.den <= max);
*dst_num = sign ? -a1.num : a1.num;
*dst_den = a1.den;
return den == 0;
}
AVRational av_mul_q(AVRational b, AVRational c)
{
av_reduce(&b.num, &b.den,
b.num * (int64_t)c.num,
b.den * (int64_t)c.den, INT_MAX);
return b;
}
AVRational av_div_q(AVRational b, AVRational c)
{
return av_mul_q(b, AVRational { c.den, c.num });
}
AVRational av_add_q(AVRational b, AVRational c) {
av_reduce(&b.num, &b.den,
b.num * (int64_t)c.den +
c.num * (int64_t)b.den,
b.den * (int64_t)c.den, INT_MAX);
return b;
}
static const uint8_t ff_logg2_tab[256] = {
0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
@ -232,15 +55,3 @@ int av_log2(unsigned int v)
return n;
}
int av_log2_16bit(unsigned int v)
{
int n = 0;
if (v & 0xff00) {
v >>= 8;
n += 8;
}
n += ff_logg2_tab[v];
return n;
}

View file

@ -26,75 +26,7 @@
#include "compat.h"
#if HAVE_FAST_CLZ
#if AV_GCC_VERSION_AT_LEAST(3,4)
#ifndef ff_log2
# define ff_log2(x) (31 - __builtin_clz((x)|1))
# ifndef ff_log2_16bit
# define ff_log2_16bit av_log2
# endif
#endif /* ff_log2 */
#endif /* AV_GCC_VERSION_AT_LEAST(3,4) */
#endif
int av_log2(unsigned int v);
int av_log2_16bit(unsigned int v);
/**
* @addtogroup lavu_math
* @{
*/
#if HAVE_FAST_CLZ
#if AV_GCC_VERSION_AT_LEAST(3,4)
#ifndef ff_ctz
#define ff_ctz(v) __builtin_ctz(v)
#endif
#ifndef ff_ctzll
#define ff_ctzll(v) __builtin_ctzll(v)
#endif
#ifndef ff_clz
#define ff_clz(v) __builtin_clz(v)
#endif
#endif
#endif
#ifndef ff_ctz
#define ff_ctz ff_ctz_c
/**
* Trailing zero bit count.
*
* @param v input value. If v is 0, the result is undefined.
* @return the number of trailing 0-bits
*/
/* We use the De-Bruijn method outlined in:
* http://supertech.csail.mit.edu/papers/debruijn.pdf. */
static inline int ff_ctz_c(int v)
{
static const uint8_t debruijn_ctz32[32] = {
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
};
return debruijn_ctz32[(uint32_t)((v & -v) * 0x077CB531U) >> 27];
}
#endif
#ifndef ff_ctzll
#define ff_ctzll ff_ctzll_c
/* We use the De-Bruijn method outlined in:
* http://supertech.csail.mit.edu/papers/debruijn.pdf. */
static inline int ff_ctzll_c(long long v)
{
static const uint8_t debruijn_ctz64[64] = {
0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12
};
return debruijn_ctz64[(uint64_t)((v & -v) * 0x022FDD63CC95386DU) >> 58];
}
#endif
static inline int sign_extend(int val, unsigned bits)
{
@ -134,149 +66,6 @@ static inline unsigned zero_extend(unsigned val, unsigned bits)
#ifndef M_SQRT2
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
#endif
/**
* @addtogroup lavu_math
* @{
*/
enum AVRounding {
AV_ROUND_ZERO = 0, ///< Round toward zero.
AV_ROUND_INF = 1, ///< Round away from zero.
AV_ROUND_DOWN = 2, ///< Round toward -infinity.
AV_ROUND_UP = 3, ///< Round toward +infinity.
AV_ROUND_NEAR_INF = 5, ///< Round to nearest and halfway cases away from zero.
AV_ROUND_PASS_MINMAX = 8192, ///< Flag to pass INT64_MIN/MAX through instead of rescaling, this avoids special cases for AV_NOPTS_VALUE
};
/**
* rational number numerator/denominator
*/
typedef struct AVRational {
int num; ///< numerator
int den; ///< denominator
} AVRational;
/**
* Compute the greatest common divisor of a and b.
*
* @return gcd of a and b up to sign; if a >= 0 and b >= 0, return value is >= 0;
* if a == 0 and b == 0, returns 0.
*/
int64_t av_gcd(int64_t a, int64_t b);
/**
* Rescale a 64-bit integer with rounding to nearest.
* A simple a*b/c isn't possible as it can overflow.
*/
int64_t av_rescale(int64_t a, int64_t b, int64_t c);
/**
* Rescale a 64-bit integer with specified rounding.
* A simple a*b/c isn't possible as it can overflow.
*
* @return rescaled value a, or if AV_ROUND_PASS_MINMAX is set and a is
* INT64_MIN or INT64_MAX then a is passed through unchanged.
*/
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, AVRounding);
/**
* Rescale a 64-bit integer by 2 rational numbers.
*/
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq);
/**
* Rescale a 64-bit integer by 2 rational numbers with specified rounding.
*
* @return rescaled value a, or if AV_ROUND_PASS_MINMAX is set and a is
* INT64_MIN or INT64_MAX then a is passed through unchanged.
*/
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, AVRounding);
/**
* Create a rational.
* Useful for compilers that do not support compound literals.
* @note The return value is not reduced.
*/
static inline AVRational av_make_q(int num, int den)
{
AVRational r = { num, den };
return r;
}
/**
* Compare two rationals.
* @param a first rational
* @param b second rational
* @return 0 if a==b, 1 if a>b, -1 if a<b, and INT_MIN if one of the
* values is of the form 0/0
*/
static inline int av_cmp_q(AVRational a, AVRational b) {
const int64_t tmp = a.num * (int64_t)b.den - b.num * (int64_t)a.den;
if (tmp) return (int)((tmp ^ a.den ^ b.den) >> 63) | 1;
else if (b.den && a.den) return 0;
else if (a.num && b.num) return (a.num >> 31) - (b.num >> 31);
else return INT_MIN;
}
/**
* Convert rational to double.
* @param a rational to convert
* @return (double) a
*/
static inline double av_q2d(AVRational a) {
return a.num / (double)a.den;
}
/**
* Reduce a fraction.
* This is useful for framerate calculations.
* @param dst_num destination numerator
* @param dst_den destination denominator
* @param num source numerator
* @param den source denominator
* @param max the maximum allowed for dst_num & dst_den
* @return 1 if exact, 0 otherwise
*/
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max);
/**
* Multiply two rationals.
* @param b first rational
* @param c second rational
* @return b*c
*/
AVRational av_mul_q(AVRational b, AVRational c);
/**
* Divide one rational by another.
* @param b first rational
* @param c second rational
* @return b/c
*/
AVRational av_div_q(AVRational b, AVRational c);
/**
* Add two rationals.
* @param b first rational
* @param c second rational
* @return b+c
*/
AVRational av_add_q(AVRational b, AVRational c);
/**
* Invert a rational.
* @param q value
* @return 1 / q
*/
static inline AVRational av_inv_q(AVRational q)
{
AVRational r = { q.den, q.num };
return r;
}
/**
* Clear high bits from an unsigned integer starting with specific bit position
* @param a value to clip
@ -287,27 +76,3 @@ static inline unsigned av_mod_uintp2(unsigned a, unsigned p)
{
return a & ((1 << p) - 1);
}
/**
* Count number of bits set to one in x
* @param x value to count bits of
* @return the number of bits set to one in x
*/
static inline int av_popcount(uint32_t x)
{
x -= (x >> 1) & 0x55555555;
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
x = (x + (x >> 4)) & 0x0F0F0F0F;
x += x >> 8;
return (x + (x >> 16)) & 0x3F;
}
/**
* Count number of bits set to one in x
* @param x value to count bits of
* @return the number of bits set to one in x
*/
static inline int av_popcount64(uint64_t x)
{
return av_popcount((uint32_t)x) + av_popcount((uint32_t)(x >> 32));
}

@ -1 +1 @@
Subproject commit a6cdbb4a529d85b74777597fcff037dde7bef66b
Subproject commit e88f74992527b9ade48ae1591378ec2cf363bef9