]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/amd/display: add fixed point fractional bit truncation function
authorDmytro Laktyushkin <Dmytro.Laktyushkin@amd.com>
Wed, 18 Apr 2018 18:11:43 +0000 (14:11 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 18 May 2018 21:08:23 +0000 (16:08 -0500)
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>
drivers/gpu/drm/amd/display/include/fixed31_32.h

index ebfd33e91ee88a262362c199964497fa5938ef07..61f11e23bf70b3613c89b7b5073f515f23726d93 100644 (file)
@@ -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