Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: Add helper for conversion from signed-magnitude

CTM values are defined as signed-magnitude values. Add
a helper that converts from CTM signed-magnitude fixed
point value to the twos-complement value used by
drm_fixed.

Reviewed-by: Sebastian Wick <sebastian.wick@redhat.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
Signed-off-by: Harry Wentland <harry.wentland@amd.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Melissa Wen <mwen@igalia.com>
Signed-off-by: Simon Ser <contact@emersion.fr>
Link: https://patch.msgid.link/20251115000237.3561250-2-alex.hung@amd.com

authored by

Harry Wentland and committed by
Simon Ser
4fc18382 c884ee70

+17
+17
include/drm/drm_fixed.h
··· 78 78 #define DRM_FIXED_EPSILON 1LL 79 79 #define DRM_FIXED_ALMOST_ONE (DRM_FIXED_ONE - DRM_FIXED_EPSILON) 80 80 81 + /** 82 + * @drm_sm2fixp 83 + * 84 + * Convert a 1.31.32 signed-magnitude fixed point to 32.32 85 + * 2s-complement fixed point 86 + * 87 + * @return s64 2s-complement fixed point 88 + */ 89 + static inline s64 drm_sm2fixp(__u64 a) 90 + { 91 + if ((a & (1LL << 63))) { 92 + return -(a & 0x7fffffffffffffffll); 93 + } else { 94 + return a; 95 + } 96 + } 97 + 81 98 static inline s64 drm_int2fixp(int a) 82 99 { 83 100 return ((s64)a) << DRM_FIXED_POINT;