diff options
author | Dmytro Laktyushkin <Dmytro.Laktyushkin@amd.com> | 2018-04-18 14:11:43 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2018-05-18 16:08:23 -0500 |
commit | ab9c2062d960df84d41c03efc49cb01071b398c6 (patch) | |
tree | 039708e7da6d59f07f678eec4fa9e82bc44d8348 /drivers/gpu/drm/amd/display/include | |
parent | e8838df1cb987fe690dfd069824ff08107327607 (diff) | |
download | linux-stable-ab9c2062d960df84d41c03efc49cb01071b398c6.tar.gz linux-stable-ab9c2062d960df84d41c03efc49cb01071b398c6.tar.bz2 linux-stable-ab9c2062d960df84d41c03efc49cb01071b398c6.zip |
drm/amd/display: add fixed point fractional bit truncation function
Signed-off-by: Dmytro Laktyushkin <Dmytro.Laktyushkin@amd.com>
Reviewed-by: Tony Cheng <Tony.Cheng@amd.com>
Acked-by: Harry Wentland <harry.wentland@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/display/include')
-rw-r--r-- | drivers/gpu/drm/amd/display/include/fixed31_32.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/display/include/fixed31_32.h b/drivers/gpu/drm/amd/display/include/fixed31_32.h index ebfd33e91ee8..61f11e23bf70 100644 --- a/drivers/gpu/drm/amd/display/include/fixed31_32.h +++ b/drivers/gpu/drm/amd/display/include/fixed31_32.h @@ -496,4 +496,21 @@ unsigned int dc_fixpt_clamp_u0d10(struct fixed31_32 arg); int dc_fixpt_s4d19(struct fixed31_32 arg); +static inline struct fixed31_32 dc_fixpt_truncate(struct fixed31_32 arg, unsigned int frac_bits) +{ + bool negative = arg.value < 0; + + if (frac_bits >= FIXED31_32_BITS_PER_FRACTIONAL_PART) { + ASSERT(frac_bits == FIXED31_32_BITS_PER_FRACTIONAL_PART); + return arg; + } + + if (negative) + arg.value = -arg.value; + arg.value &= (~0LL) << (FIXED31_32_BITS_PER_FRACTIONAL_PART - frac_bits); + if (negative) + arg.value = -arg.value; + return arg; +} + #endif |