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

drm: fix 64 bit drm fixed point helpers

Sign bit wasn't handled properly and a small typo.

Thanks to Christian for helping me sort this out.

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

+7 -7
+7 -7
include/drm/drm_fixed.h
··· 84 84 return ((s64)a) >> DRM_FIXED_POINT; 85 85 } 86 86 87 - static inline s64 drm_fixp_msbset(int64_t a) 87 + static inline unsigned drm_fixp_msbset(int64_t a) 88 88 { 89 89 unsigned shift, sign = (a >> 63) & 1; 90 90 91 91 for (shift = 62; shift > 0; --shift) 92 - if ((a >> shift) != sign) 92 + if (((a >> shift) & 1) != sign) 93 93 return shift; 94 94 95 95 return 0; ··· 100 100 unsigned shift = drm_fixp_msbset(a) + drm_fixp_msbset(b); 101 101 s64 result; 102 102 103 - if (shift > 63) { 104 - shift = shift - 63; 105 - a >>= shift >> 1; 103 + if (shift > 61) { 104 + shift = shift - 61; 105 + a >>= (shift >> 1) + (shift & 1); 106 106 b >>= shift >> 1; 107 107 } else 108 108 shift = 0; ··· 120 120 121 121 static inline s64 drm_fixp_div(s64 a, s64 b) 122 122 { 123 - unsigned shift = 63 - drm_fixp_msbset(a); 123 + unsigned shift = 62 - drm_fixp_msbset(a); 124 124 s64 result; 125 125 126 126 a <<= shift; ··· 154 154 } 155 155 156 156 if (x < 0) 157 - sum = drm_fixp_div(1, sum); 157 + sum = drm_fixp_div(DRM_FIXED_ONE, sum); 158 158 159 159 return sum; 160 160 }