aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmytro Laktyushkin <Dmytro.Laktyushkin@amd.com>2018-04-18 14:11:43 -0400
committerAlex Deucher <alexander.deucher@amd.com>2018-05-18 17:08:23 -0400
commitab9c2062d960df84d41c03efc49cb01071b398c6 (patch)
tree039708e7da6d59f07f678eec4fa9e82bc44d8348
parente8838df1cb987fe690dfd069824ff08107327607 (diff)
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>
-rw-r--r--drivers/gpu/drm/amd/display/include/fixed31_32.h17
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);
496 496
497int dc_fixpt_s4d19(struct fixed31_32 arg); 497int dc_fixpt_s4d19(struct fixed31_32 arg);
498 498
499static inline struct fixed31_32 dc_fixpt_truncate(struct fixed31_32 arg, unsigned int frac_bits)
500{
501 bool negative = arg.value < 0;
502
503 if (frac_bits >= FIXED31_32_BITS_PER_FRACTIONAL_PART) {
504 ASSERT(frac_bits == FIXED31_32_BITS_PER_FRACTIONAL_PART);
505 return arg;
506 }
507
508 if (negative)
509 arg.value = -arg.value;
510 arg.value &= (~0LL) << (FIXED31_32_BITS_PER_FRACTIONAL_PART - frac_bits);
511 if (negative)
512 arg.value = -arg.value;
513 return arg;
514}
515
499#endif 516#endif