Skip to content

Commit a838834

Browse files
committed
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>
1 parent 42a2182 commit a838834

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

‎include/drm/drm_fixed.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ static inline int drm_fixp2int(int64_t a)
8484
return ((s64)a) >> DRM_FIXED_POINT;
8585
}
8686

87-
static inline s64 drm_fixp_msbset(int64_t a)
87+
static inline unsigned drm_fixp_msbset(int64_t a)
8888
{
8989
unsigned shift, sign = (a >> 63) & 1;
9090

9191
for (shift = 62; shift > 0; --shift)
92-
if ((a >> shift) != sign)
92+
if (((a >> shift) & 1) != sign)
9393
return shift;
9494

9595
return 0;
@@ -100,9 +100,9 @@ static inline s64 drm_fixp_mul(s64 a, s64 b)
100100
unsigned shift = drm_fixp_msbset(a) + drm_fixp_msbset(b);
101101
s64 result;
102102

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);
106106
b >>= shift >> 1;
107107
} else
108108
shift = 0;
@@ -120,7 +120,7 @@ static inline s64 drm_fixp_mul(s64 a, s64 b)
120120

121121
static inline s64 drm_fixp_div(s64 a, s64 b)
122122
{
123-
unsigned shift = 63 - drm_fixp_msbset(a);
123+
unsigned shift = 62 - drm_fixp_msbset(a);
124124
s64 result;
125125

126126
a <<= shift;
@@ -154,7 +154,7 @@ static inline s64 drm_fixp_exp(s64 x)
154154
}
155155

156156
if (x < 0)
157-
sum = drm_fixp_div(1, sum);
157+
sum = drm_fixp_div(DRM_FIXED_ONE, sum);
158158

159159
return sum;
160160
}

0 commit comments

Comments
 (0)