Commit f3ba7a2f authored by Dmytro Laktyushkin's avatar Dmytro Laktyushkin Committed by Alex Deucher

drm/amd/display: inline more of fixed point code

Signed-off-by: default avatarDmytro Laktyushkin <Dmytro.Laktyushkin@amd.com>
Reviewed-by: default avatarTony Cheng <Tony.Cheng@amd.com>
Acked-by: default avatarHarry Wentland <harry.wentland@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent eb0e5154
...@@ -64,9 +64,7 @@ static inline unsigned long long complete_integer_division_u64( ...@@ -64,9 +64,7 @@ static inline unsigned long long complete_integer_division_u64(
#define GET_FRACTIONAL_PART(x) \ #define GET_FRACTIONAL_PART(x) \
(FRACTIONAL_PART_MASK & (x)) (FRACTIONAL_PART_MASK & (x))
struct fixed31_32 dc_fixpt_from_fraction( struct fixed31_32 dc_fixpt_from_fraction(long long numerator, long long denominator)
long long numerator,
long long denominator)
{ {
struct fixed31_32 res; struct fixed31_32 res;
...@@ -118,63 +116,7 @@ struct fixed31_32 dc_fixpt_from_fraction( ...@@ -118,63 +116,7 @@ struct fixed31_32 dc_fixpt_from_fraction(
return res; return res;
} }
struct fixed31_32 dc_fixpt_from_int_nonconst( struct fixed31_32 dc_fixpt_mul(struct fixed31_32 arg1, struct fixed31_32 arg2)
long long arg)
{
struct fixed31_32 res;
ASSERT((LONG_MIN <= arg) && (arg <= LONG_MAX));
res.value = arg << FIXED31_32_BITS_PER_FRACTIONAL_PART;
return res;
}
struct fixed31_32 dc_fixpt_shl(
struct fixed31_32 arg,
unsigned char shift)
{
struct fixed31_32 res;
ASSERT(((arg.value >= 0) && (arg.value <= LLONG_MAX >> shift)) ||
((arg.value < 0) && (arg.value >= LLONG_MIN >> shift)));
res.value = arg.value << shift;
return res;
}
struct fixed31_32 dc_fixpt_add(
struct fixed31_32 arg1,
struct fixed31_32 arg2)
{
struct fixed31_32 res;
ASSERT(((arg1.value >= 0) && (LLONG_MAX - arg1.value >= arg2.value)) ||
((arg1.value < 0) && (LLONG_MIN - arg1.value <= arg2.value)));
res.value = arg1.value + arg2.value;
return res;
}
struct fixed31_32 dc_fixpt_sub(
struct fixed31_32 arg1,
struct fixed31_32 arg2)
{
struct fixed31_32 res;
ASSERT(((arg2.value >= 0) && (LLONG_MIN + arg2.value <= arg1.value)) ||
((arg2.value < 0) && (LLONG_MAX + arg2.value >= arg1.value)));
res.value = arg1.value - arg2.value;
return res;
}
struct fixed31_32 dc_fixpt_mul(
struct fixed31_32 arg1,
struct fixed31_32 arg2)
{ {
struct fixed31_32 res; struct fixed31_32 res;
...@@ -225,8 +167,7 @@ struct fixed31_32 dc_fixpt_mul( ...@@ -225,8 +167,7 @@ struct fixed31_32 dc_fixpt_mul(
return res; return res;
} }
struct fixed31_32 dc_fixpt_sqr( struct fixed31_32 dc_fixpt_sqr(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
struct fixed31_32 res; struct fixed31_32 res;
...@@ -266,8 +207,7 @@ struct fixed31_32 dc_fixpt_sqr( ...@@ -266,8 +207,7 @@ struct fixed31_32 dc_fixpt_sqr(
return res; return res;
} }
struct fixed31_32 dc_fixpt_recip( struct fixed31_32 dc_fixpt_recip(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
/* /*
* @note * @note
...@@ -281,8 +221,7 @@ struct fixed31_32 dc_fixpt_recip( ...@@ -281,8 +221,7 @@ struct fixed31_32 dc_fixpt_recip(
arg.value); arg.value);
} }
struct fixed31_32 dc_fixpt_sinc( struct fixed31_32 dc_fixpt_sinc(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
struct fixed31_32 square; struct fixed31_32 square;
...@@ -326,16 +265,14 @@ struct fixed31_32 dc_fixpt_sinc( ...@@ -326,16 +265,14 @@ struct fixed31_32 dc_fixpt_sinc(
return res; return res;
} }
struct fixed31_32 dc_fixpt_sin( struct fixed31_32 dc_fixpt_sin(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
return dc_fixpt_mul( return dc_fixpt_mul(
arg, arg,
dc_fixpt_sinc(arg)); dc_fixpt_sinc(arg));
} }
struct fixed31_32 dc_fixpt_cos( struct fixed31_32 dc_fixpt_cos(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
/* TODO implement argument normalization */ /* TODO implement argument normalization */
...@@ -367,8 +304,7 @@ struct fixed31_32 dc_fixpt_cos( ...@@ -367,8 +304,7 @@ struct fixed31_32 dc_fixpt_cos(
* *
* Calculated as Taylor series. * Calculated as Taylor series.
*/ */
static struct fixed31_32 fixed31_32_exp_from_taylor_series( static struct fixed31_32 fixed31_32_exp_from_taylor_series(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
unsigned int n = 9; unsigned int n = 9;
...@@ -396,8 +332,7 @@ static struct fixed31_32 fixed31_32_exp_from_taylor_series( ...@@ -396,8 +332,7 @@ static struct fixed31_32 fixed31_32_exp_from_taylor_series(
res)); res));
} }
struct fixed31_32 dc_fixpt_exp( struct fixed31_32 dc_fixpt_exp(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
/* /*
* @brief * @brief
...@@ -440,8 +375,7 @@ struct fixed31_32 dc_fixpt_exp( ...@@ -440,8 +375,7 @@ struct fixed31_32 dc_fixpt_exp(
return dc_fixpt_one; return dc_fixpt_one;
} }
struct fixed31_32 dc_fixpt_log( struct fixed31_32 dc_fixpt_log(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
struct fixed31_32 res = dc_fixpt_neg(dc_fixpt_one); struct fixed31_32 res = dc_fixpt_neg(dc_fixpt_one);
/* TODO improve 1st estimation */ /* TODO improve 1st estimation */
...@@ -472,61 +406,6 @@ struct fixed31_32 dc_fixpt_log( ...@@ -472,61 +406,6 @@ struct fixed31_32 dc_fixpt_log(
return res; return res;
} }
struct fixed31_32 dc_fixpt_pow(
struct fixed31_32 arg1,
struct fixed31_32 arg2)
{
return dc_fixpt_exp(
dc_fixpt_mul(
dc_fixpt_log(arg1),
arg2));
}
int dc_fixpt_floor(
struct fixed31_32 arg)
{
unsigned long long arg_value = abs_i64(arg.value);
if (arg.value >= 0)
return (int)GET_INTEGER_PART(arg_value);
else
return -(int)GET_INTEGER_PART(arg_value);
}
int dc_fixpt_round(
struct fixed31_32 arg)
{
unsigned long long arg_value = abs_i64(arg.value);
const long long summand = dc_fixpt_half.value;
ASSERT(LLONG_MAX - (long long)arg_value >= summand);
arg_value += summand;
if (arg.value >= 0)
return (int)GET_INTEGER_PART(arg_value);
else
return -(int)GET_INTEGER_PART(arg_value);
}
int dc_fixpt_ceil(
struct fixed31_32 arg)
{
unsigned long long arg_value = abs_i64(arg.value);
const long long summand = dc_fixpt_one.value -
dc_fixpt_epsilon.value;
ASSERT(LLONG_MAX - (long long)arg_value >= summand);
arg_value += summand;
if (arg.value >= 0)
return (int)GET_INTEGER_PART(arg_value);
else
return -(int)GET_INTEGER_PART(arg_value);
}
/* this function is a generic helper to translate fixed point value to /* this function is a generic helper to translate fixed point value to
* specified integer format that will consist of integer_bits integer part and * specified integer format that will consist of integer_bits integer part and
...@@ -570,32 +449,27 @@ static inline unsigned int clamp_ux_dy( ...@@ -570,32 +449,27 @@ static inline unsigned int clamp_ux_dy(
return min_clamp; return min_clamp;
} }
unsigned int dc_fixpt_u2d19( unsigned int dc_fixpt_u2d19(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
return ux_dy(arg.value, 2, 19); return ux_dy(arg.value, 2, 19);
} }
unsigned int dc_fixpt_u0d19( unsigned int dc_fixpt_u0d19(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
return ux_dy(arg.value, 0, 19); return ux_dy(arg.value, 0, 19);
} }
unsigned int dc_fixpt_clamp_u0d14( unsigned int dc_fixpt_clamp_u0d14(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
return clamp_ux_dy(arg.value, 0, 14, 1); return clamp_ux_dy(arg.value, 0, 14, 1);
} }
unsigned int dc_fixpt_clamp_u0d10( unsigned int dc_fixpt_clamp_u0d10(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
return clamp_ux_dy(arg.value, 0, 10, 1); return clamp_ux_dy(arg.value, 0, 10, 1);
} }
int dc_fixpt_s4d19( int dc_fixpt_s4d19(struct fixed31_32 arg)
struct fixed31_32 arg)
{ {
if (arg.value < 0) if (arg.value < 0)
return -(int)ux_dy(dc_fixpt_abs(arg).value, 4, 19); return -(int)ux_dy(dc_fixpt_abs(arg).value, 4, 19);
......
...@@ -70,24 +70,19 @@ static const struct fixed31_32 dc_fixpt_ln2_div_2 = { 1488522236LL }; ...@@ -70,24 +70,19 @@ static const struct fixed31_32 dc_fixpt_ln2_div_2 = { 1488522236LL };
* @brief * @brief
* result = numerator / denominator * result = numerator / denominator
*/ */
struct fixed31_32 dc_fixpt_from_fraction( struct fixed31_32 dc_fixpt_from_fraction(long long numerator, long long denominator);
long long numerator,
long long denominator);
/* /*
* @brief * @brief
* result = arg * result = arg
*/ */
struct fixed31_32 dc_fixpt_from_int_nonconst(long long arg); static inline struct fixed31_32 dc_fixpt_from_int(int arg)
static inline struct fixed31_32 dc_fixpt_from_int(long long arg)
{ {
if (__builtin_constant_p(arg)) { struct fixed31_32 res;
struct fixed31_32 res;
BUILD_BUG_ON((LONG_MIN > arg) || (arg > LONG_MAX)); res.value = (long long) arg << FIXED31_32_BITS_PER_FRACTIONAL_PART;
res.value = arg << FIXED31_32_BITS_PER_FRACTIONAL_PART;
return res; return res;
} else
return dc_fixpt_from_int_nonconst(arg);
} }
/* /*
...@@ -129,8 +124,7 @@ static inline struct fixed31_32 dc_fixpt_abs(struct fixed31_32 arg) ...@@ -129,8 +124,7 @@ static inline struct fixed31_32 dc_fixpt_abs(struct fixed31_32 arg)
* @brief * @brief
* result = arg1 < arg2 * result = arg1 < arg2
*/ */
static inline bool dc_fixpt_lt(struct fixed31_32 arg1, static inline bool dc_fixpt_lt(struct fixed31_32 arg1, struct fixed31_32 arg2)
struct fixed31_32 arg2)
{ {
return arg1.value < arg2.value; return arg1.value < arg2.value;
} }
...@@ -139,8 +133,7 @@ static inline bool dc_fixpt_lt(struct fixed31_32 arg1, ...@@ -139,8 +133,7 @@ static inline bool dc_fixpt_lt(struct fixed31_32 arg1,
* @brief * @brief
* result = arg1 <= arg2 * result = arg1 <= arg2
*/ */
static inline bool dc_fixpt_le(struct fixed31_32 arg1, static inline bool dc_fixpt_le(struct fixed31_32 arg1, struct fixed31_32 arg2)
struct fixed31_32 arg2)
{ {
return arg1.value <= arg2.value; return arg1.value <= arg2.value;
} }
...@@ -149,8 +142,7 @@ static inline bool dc_fixpt_le(struct fixed31_32 arg1, ...@@ -149,8 +142,7 @@ static inline bool dc_fixpt_le(struct fixed31_32 arg1,
* @brief * @brief
* result = arg1 == arg2 * result = arg1 == arg2
*/ */
static inline bool dc_fixpt_eq(struct fixed31_32 arg1, static inline bool dc_fixpt_eq(struct fixed31_32 arg1, struct fixed31_32 arg2)
struct fixed31_32 arg2)
{ {
return arg1.value == arg2.value; return arg1.value == arg2.value;
} }
...@@ -159,8 +151,7 @@ static inline bool dc_fixpt_eq(struct fixed31_32 arg1, ...@@ -159,8 +151,7 @@ static inline bool dc_fixpt_eq(struct fixed31_32 arg1,
* @brief * @brief
* result = min(arg1, arg2) := (arg1 <= arg2) ? arg1 : arg2 * result = min(arg1, arg2) := (arg1 <= arg2) ? arg1 : arg2
*/ */
static inline struct fixed31_32 dc_fixpt_min(struct fixed31_32 arg1, static inline struct fixed31_32 dc_fixpt_min(struct fixed31_32 arg1, struct fixed31_32 arg2)
struct fixed31_32 arg2)
{ {
if (arg1.value <= arg2.value) if (arg1.value <= arg2.value)
return arg1; return arg1;
...@@ -172,8 +163,7 @@ static inline struct fixed31_32 dc_fixpt_min(struct fixed31_32 arg1, ...@@ -172,8 +163,7 @@ static inline struct fixed31_32 dc_fixpt_min(struct fixed31_32 arg1,
* @brief * @brief
* result = max(arg1, arg2) := (arg1 <= arg2) ? arg2 : arg1 * result = max(arg1, arg2) := (arg1 <= arg2) ? arg2 : arg1
*/ */
static inline struct fixed31_32 dc_fixpt_max(struct fixed31_32 arg1, static inline struct fixed31_32 dc_fixpt_max(struct fixed31_32 arg1, struct fixed31_32 arg2)
struct fixed31_32 arg2)
{ {
if (arg1.value <= arg2.value) if (arg1.value <= arg2.value)
return arg2; return arg2;
...@@ -209,17 +199,23 @@ static inline struct fixed31_32 dc_fixpt_clamp( ...@@ -209,17 +199,23 @@ static inline struct fixed31_32 dc_fixpt_clamp(
* @brief * @brief
* result = arg << shift * result = arg << shift
*/ */
struct fixed31_32 dc_fixpt_shl( static inline struct fixed31_32 dc_fixpt_shl(struct fixed31_32 arg, unsigned char shift)
struct fixed31_32 arg, {
unsigned char shift); struct fixed31_32 res;
ASSERT(((arg.value >= 0) && (arg.value <= LLONG_MAX >> shift)) ||
((arg.value < 0) && (arg.value >= LLONG_MIN >> shift)));
res.value = arg.value << shift;
return res;
}
/* /*
* @brief * @brief
* result = arg >> shift * result = arg >> shift
*/ */
static inline struct fixed31_32 dc_fixpt_shr( static inline struct fixed31_32 dc_fixpt_shr(struct fixed31_32 arg, unsigned char shift)
struct fixed31_32 arg,
unsigned char shift)
{ {
struct fixed31_32 res; struct fixed31_32 res;
res.value = arg.value >> shift; res.value = arg.value >> shift;
...@@ -235,38 +231,50 @@ static inline struct fixed31_32 dc_fixpt_shr( ...@@ -235,38 +231,50 @@ static inline struct fixed31_32 dc_fixpt_shr(
* @brief * @brief
* result = arg1 + arg2 * result = arg1 + arg2
*/ */
struct fixed31_32 dc_fixpt_add( static inline struct fixed31_32 dc_fixpt_add(struct fixed31_32 arg1, struct fixed31_32 arg2)
struct fixed31_32 arg1, {
struct fixed31_32 arg2); struct fixed31_32 res;
ASSERT(((arg1.value >= 0) && (LLONG_MAX - arg1.value >= arg2.value)) ||
((arg1.value < 0) && (LLONG_MIN - arg1.value <= arg2.value)));
res.value = arg1.value + arg2.value;
return res;
}
/* /*
* @brief * @brief
* result = arg1 + arg2 * result = arg1 + arg2
*/ */
static inline struct fixed31_32 dc_fixpt_add_int(struct fixed31_32 arg1, static inline struct fixed31_32 dc_fixpt_add_int(struct fixed31_32 arg1, int arg2)
int arg2)
{ {
return dc_fixpt_add(arg1, return dc_fixpt_add(arg1, dc_fixpt_from_int(arg2));
dc_fixpt_from_int(arg2));
} }
/* /*
* @brief * @brief
* result = arg1 - arg2 * result = arg1 - arg2
*/ */
struct fixed31_32 dc_fixpt_sub( static inline struct fixed31_32 dc_fixpt_sub(struct fixed31_32 arg1, struct fixed31_32 arg2)
struct fixed31_32 arg1, {
struct fixed31_32 arg2); struct fixed31_32 res;
ASSERT(((arg2.value >= 0) && (LLONG_MIN + arg2.value <= arg1.value)) ||
((arg2.value < 0) && (LLONG_MAX + arg2.value >= arg1.value)));
res.value = arg1.value - arg2.value;
return res;
}
/* /*
* @brief * @brief
* result = arg1 - arg2 * result = arg1 - arg2
*/ */
static inline struct fixed31_32 dc_fixpt_sub_int(struct fixed31_32 arg1, static inline struct fixed31_32 dc_fixpt_sub_int(struct fixed31_32 arg1, int arg2)
int arg2)
{ {
return dc_fixpt_sub(arg1, return dc_fixpt_sub(arg1, dc_fixpt_from_int(arg2));
dc_fixpt_from_int(arg2));
} }
...@@ -279,49 +287,40 @@ static inline struct fixed31_32 dc_fixpt_sub_int(struct fixed31_32 arg1, ...@@ -279,49 +287,40 @@ static inline struct fixed31_32 dc_fixpt_sub_int(struct fixed31_32 arg1,
* @brief * @brief
* result = arg1 * arg2 * result = arg1 * arg2
*/ */
struct fixed31_32 dc_fixpt_mul( struct fixed31_32 dc_fixpt_mul(struct fixed31_32 arg1, struct fixed31_32 arg2);
struct fixed31_32 arg1,
struct fixed31_32 arg2);
/* /*
* @brief * @brief
* result = arg1 * arg2 * result = arg1 * arg2
*/ */
static inline struct fixed31_32 dc_fixpt_mul_int(struct fixed31_32 arg1, static inline struct fixed31_32 dc_fixpt_mul_int(struct fixed31_32 arg1, int arg2)
int arg2)
{ {
return dc_fixpt_mul(arg1, return dc_fixpt_mul(arg1, dc_fixpt_from_int(arg2));
dc_fixpt_from_int(arg2));
} }
/* /*
* @brief * @brief
* result = square(arg) := arg * arg * result = square(arg) := arg * arg
*/ */
struct fixed31_32 dc_fixpt_sqr( struct fixed31_32 dc_fixpt_sqr(struct fixed31_32 arg);
struct fixed31_32 arg);
/* /*
* @brief * @brief
* result = arg1 / arg2 * result = arg1 / arg2
*/ */
static inline struct fixed31_32 dc_fixpt_div_int(struct fixed31_32 arg1, static inline struct fixed31_32 dc_fixpt_div_int(struct fixed31_32 arg1, long long arg2)
long long arg2)
{ {
return dc_fixpt_from_fraction(arg1.value, return dc_fixpt_from_fraction(arg1.value, dc_fixpt_from_int(arg2).value);
dc_fixpt_from_int(arg2).value);
} }
/* /*
* @brief * @brief
* result = arg1 / arg2 * result = arg1 / arg2
*/ */
static inline struct fixed31_32 dc_fixpt_div(struct fixed31_32 arg1, static inline struct fixed31_32 dc_fixpt_div(struct fixed31_32 arg1, struct fixed31_32 arg2)
struct fixed31_32 arg2)
{ {
return dc_fixpt_from_fraction(arg1.value, return dc_fixpt_from_fraction(arg1.value, arg2.value);
arg2.value);
} }
/* /*
...@@ -336,8 +335,7 @@ static inline struct fixed31_32 dc_fixpt_div(struct fixed31_32 arg1, ...@@ -336,8 +335,7 @@ static inline struct fixed31_32 dc_fixpt_div(struct fixed31_32 arg1,
* @note * @note
* No special actions taken in case argument is zero. * No special actions taken in case argument is zero.
*/ */
struct fixed31_32 dc_fixpt_recip( struct fixed31_32 dc_fixpt_recip(struct fixed31_32 arg);
struct fixed31_32 arg);
/* /*
* @brief * @brief
...@@ -352,8 +350,7 @@ struct fixed31_32 dc_fixpt_recip( ...@@ -352,8 +350,7 @@ struct fixed31_32 dc_fixpt_recip(
* Argument specified in radians, * Argument specified in radians,
* internally it's normalized to [-2pi...2pi] range. * internally it's normalized to [-2pi...2pi] range.
*/ */
struct fixed31_32 dc_fixpt_sinc( struct fixed31_32 dc_fixpt_sinc(struct fixed31_32 arg);
struct fixed31_32 arg);
/* /*
* @brief * @brief
...@@ -363,8 +360,7 @@ struct fixed31_32 dc_fixpt_sinc( ...@@ -363,8 +360,7 @@ struct fixed31_32 dc_fixpt_sinc(
* Argument specified in radians, * Argument specified in radians,
* internally it's normalized to [-2pi...2pi] range. * internally it's normalized to [-2pi...2pi] range.
*/ */
struct fixed31_32 dc_fixpt_sin( struct fixed31_32 dc_fixpt_sin(struct fixed31_32 arg);
struct fixed31_32 arg);
/* /*
* @brief * @brief
...@@ -376,8 +372,7 @@ struct fixed31_32 dc_fixpt_sin( ...@@ -376,8 +372,7 @@ struct fixed31_32 dc_fixpt_sin(
* passing arguments outside that range * passing arguments outside that range
* will cause incorrect result! * will cause incorrect result!
*/ */
struct fixed31_32 dc_fixpt_cos( struct fixed31_32 dc_fixpt_cos(struct fixed31_32 arg);
struct fixed31_32 arg);
/* /*
* @brief * @brief
...@@ -391,8 +386,7 @@ struct fixed31_32 dc_fixpt_cos( ...@@ -391,8 +386,7 @@ struct fixed31_32 dc_fixpt_cos(
* @note * @note
* Currently, function is verified for abs(arg) <= 1. * Currently, function is verified for abs(arg) <= 1.
*/ */
struct fixed31_32 dc_fixpt_exp( struct fixed31_32 dc_fixpt_exp(struct fixed31_32 arg);
struct fixed31_32 arg);
/* /*
* @brief * @brief
...@@ -404,8 +398,7 @@ struct fixed31_32 dc_fixpt_exp( ...@@ -404,8 +398,7 @@ struct fixed31_32 dc_fixpt_exp(
* Currently, no special actions taken * Currently, no special actions taken
* in case of invalid argument(s). Take care! * in case of invalid argument(s). Take care!
*/ */
struct fixed31_32 dc_fixpt_log( struct fixed31_32 dc_fixpt_log(struct fixed31_32 arg);
struct fixed31_32 arg);
/* /*
* @brief * @brief
...@@ -419,9 +412,13 @@ struct fixed31_32 dc_fixpt_log( ...@@ -419,9 +412,13 @@ struct fixed31_32 dc_fixpt_log(
* @note * @note
* Currently, abs(arg1) should be less than 1. Take care! * Currently, abs(arg1) should be less than 1. Take care!
*/ */
struct fixed31_32 dc_fixpt_pow( static inline struct fixed31_32 dc_fixpt_pow(struct fixed31_32 arg1, struct fixed31_32 arg2)
struct fixed31_32 arg1, {
struct fixed31_32 arg2); return dc_fixpt_exp(
dc_fixpt_mul(
dc_fixpt_log(arg1),
arg2));
}
/* /*
* @brief * @brief
...@@ -432,22 +429,56 @@ struct fixed31_32 dc_fixpt_pow( ...@@ -432,22 +429,56 @@ struct fixed31_32 dc_fixpt_pow(
* @brief * @brief
* result = floor(arg) := greatest integer lower than or equal to arg * result = floor(arg) := greatest integer lower than or equal to arg
*/ */
int dc_fixpt_floor( static inline int dc_fixpt_floor(struct fixed31_32 arg)
struct fixed31_32 arg); {
unsigned long long arg_value = arg.value > 0 ? arg.value : -arg.value;
if (arg.value >= 0)
return (int)(arg_value >> FIXED31_32_BITS_PER_FRACTIONAL_PART);
else
return -(int)(arg_value >> FIXED31_32_BITS_PER_FRACTIONAL_PART);
}
/* /*
* @brief * @brief
* result = round(arg) := integer nearest to arg * result = round(arg) := integer nearest to arg
*/ */
int dc_fixpt_round( static inline int dc_fixpt_round(struct fixed31_32 arg)
struct fixed31_32 arg); {
unsigned long long arg_value = arg.value > 0 ? arg.value : -arg.value;
const long long summand = dc_fixpt_half.value;
ASSERT(LLONG_MAX - (long long)arg_value >= summand);
arg_value += summand;
if (arg.value >= 0)
return (int)(arg_value >> FIXED31_32_BITS_PER_FRACTIONAL_PART);
else
return -(int)(arg_value >> FIXED31_32_BITS_PER_FRACTIONAL_PART);
}
/* /*
* @brief * @brief
* result = ceil(arg) := lowest integer greater than or equal to arg * result = ceil(arg) := lowest integer greater than or equal to arg
*/ */
int dc_fixpt_ceil( static inline int dc_fixpt_ceil(struct fixed31_32 arg)
struct fixed31_32 arg); {
unsigned long long arg_value = arg.value > 0 ? arg.value : -arg.value;
const long long summand = dc_fixpt_one.value -
dc_fixpt_epsilon.value;
ASSERT(LLONG_MAX - (long long)arg_value >= summand);
arg_value += summand;
if (arg.value >= 0)
return (int)(arg_value >> FIXED31_32_BITS_PER_FRACTIONAL_PART);
else
return -(int)(arg_value >> FIXED31_32_BITS_PER_FRACTIONAL_PART);
}
/* the following two function are used in scaler hw programming to convert fixed /* the following two function are used in scaler hw programming to convert fixed
* point value to format 2 bits from integer part and 19 bits from fractional * point value to format 2 bits from integer part and 19 bits from fractional
...@@ -455,20 +486,14 @@ int dc_fixpt_ceil( ...@@ -455,20 +486,14 @@ int dc_fixpt_ceil(
* fractional * fractional
*/ */
unsigned int dc_fixpt_u2d19( unsigned int dc_fixpt_u2d19(struct fixed31_32 arg);
struct fixed31_32 arg);
unsigned int dc_fixpt_u0d19(
struct fixed31_32 arg);
unsigned int dc_fixpt_u0d19(struct fixed31_32 arg);
unsigned int dc_fixpt_clamp_u0d14( unsigned int dc_fixpt_clamp_u0d14(struct fixed31_32 arg);
struct fixed31_32 arg);
unsigned int dc_fixpt_clamp_u0d10( unsigned int dc_fixpt_clamp_u0d10(struct fixed31_32 arg);
struct fixed31_32 arg);
int dc_fixpt_s4d19( int dc_fixpt_s4d19(struct fixed31_32 arg);
struct fixed31_32 arg);
#endif #endif
...@@ -913,7 +913,7 @@ static void apply_lut_1d( ...@@ -913,7 +913,7 @@ static void apply_lut_1d(
struct fixed31_32 lut2; struct fixed31_32 lut2;
const int max_lut_index = 4095; const int max_lut_index = 4095;
const struct fixed31_32 max_lut_index_f = const struct fixed31_32 max_lut_index_f =
dc_fixpt_from_int_nonconst(max_lut_index); dc_fixpt_from_int(max_lut_index);
int32_t index = 0, index_next = 0; int32_t index = 0, index_next = 0;
struct fixed31_32 index_f; struct fixed31_32 index_f;
struct fixed31_32 delta_lut; struct fixed31_32 delta_lut;
...@@ -934,7 +934,7 @@ static void apply_lut_1d( ...@@ -934,7 +934,7 @@ static void apply_lut_1d(
norm_y = dc_fixpt_mul(max_lut_index_f, norm_y = dc_fixpt_mul(max_lut_index_f,
*regamma_y); *regamma_y);
index = dc_fixpt_floor(norm_y); index = dc_fixpt_floor(norm_y);
index_f = dc_fixpt_from_int_nonconst(index); index_f = dc_fixpt_from_int(index);
if (index < 0 || index > max_lut_index) if (index < 0 || index > max_lut_index)
continue; continue;
...@@ -1094,7 +1094,7 @@ static void interpolate_user_regamma(uint32_t hw_points_num, ...@@ -1094,7 +1094,7 @@ static void interpolate_user_regamma(uint32_t hw_points_num,
struct fixed31_32 *tf_point; struct fixed31_32 *tf_point;
struct fixed31_32 hw_x; struct fixed31_32 hw_x;
struct fixed31_32 norm_factor = struct fixed31_32 norm_factor =
dc_fixpt_from_int_nonconst(255); dc_fixpt_from_int(255);
struct fixed31_32 norm_x; struct fixed31_32 norm_x;
struct fixed31_32 index_f; struct fixed31_32 index_f;
struct fixed31_32 lut1; struct fixed31_32 lut1;
...@@ -1134,7 +1134,7 @@ static void interpolate_user_regamma(uint32_t hw_points_num, ...@@ -1134,7 +1134,7 @@ static void interpolate_user_regamma(uint32_t hw_points_num,
if (index < 0 || index > 255) if (index < 0 || index > 255)
continue; continue;
index_f = dc_fixpt_from_int_nonconst(index); index_f = dc_fixpt_from_int(index);
index_next = (index == 255) ? index : index + 1; index_next = (index == 255) ? index : index + 1;
if (color == 0) { if (color == 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment