提交 a21ddec6 编写于 作者: D Dmytro Laktyushkin 提交者: Alex Deucher

drm/amd/display: fix 31_32_fixpt shift functions

Signed-off-by: NDmytro Laktyushkin <Dmytro.Laktyushkin@amd.com>
Reviewed-by: NEric Yang <eric.yang2@amd.com>
Acked-by: NHarry Wentland <harry.wentland@amd.com>
Signed-off-by: NAlex Deucher <alexander.deucher@amd.com>
上级 6b8e1eb7
...@@ -27,6 +27,12 @@ ...@@ -27,6 +27,12 @@
#define __DAL_FIXED31_32_H__ #define __DAL_FIXED31_32_H__
#define FIXED31_32_BITS_PER_FRACTIONAL_PART 32 #define FIXED31_32_BITS_PER_FRACTIONAL_PART 32
#ifndef LLONG_MIN
#define LLONG_MIN (1LL<<63)
#endif
#ifndef LLONG_MAX
#define LLONG_MAX (-1LL>>1)
#endif
/* /*
* @brief * @brief
...@@ -45,6 +51,7 @@ struct fixed31_32 { ...@@ -45,6 +51,7 @@ struct fixed31_32 {
long long value; long long value;
}; };
/* /*
* @brief * @brief
* Useful constants * Useful constants
...@@ -201,14 +208,12 @@ static inline struct fixed31_32 dc_fixpt_clamp( ...@@ -201,14 +208,12 @@ static inline struct fixed31_32 dc_fixpt_clamp(
*/ */
static inline struct fixed31_32 dc_fixpt_shl(struct fixed31_32 arg, unsigned char shift) static inline 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)) || ASSERT(((arg.value >= 0) && (arg.value <= LLONG_MAX >> shift)) ||
((arg.value < 0) && (arg.value >= LLONG_MIN >> shift))); ((arg.value < 0) && (arg.value >= (LLONG_MIN / (1 << shift)))));
res.value = arg.value << shift; arg.value = arg.value << shift;
return res; return arg;
} }
/* /*
...@@ -217,9 +222,14 @@ static inline struct fixed31_32 dc_fixpt_shl(struct fixed31_32 arg, unsigned cha ...@@ -217,9 +222,14 @@ static inline struct fixed31_32 dc_fixpt_shl(struct fixed31_32 arg, unsigned cha
*/ */
static inline struct fixed31_32 dc_fixpt_shr(struct fixed31_32 arg, unsigned char shift) static inline struct fixed31_32 dc_fixpt_shr(struct fixed31_32 arg, unsigned char shift)
{ {
struct fixed31_32 res; bool negative = arg.value < 0;
res.value = arg.value >> shift;
return res; if (negative)
arg.value = -arg.value;
arg.value = arg.value >> shift;
if (negative)
arg.value = -arg.value;
return arg;
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册