diff options
author | Alex Deucher <alexander.deucher@amd.com> | 2013-07-30 16:43:55 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2013-07-30 17:24:13 -0400 |
commit | a838834b2f7cbc09b6319a1fc332c03e4d665b20 (patch) | |
tree | 548865f29964a44d9f62b51f88586832e58aba08 /include | |
parent | 42a21826dc54583cdb79cc8477732e911ac9c376 (diff) |
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>
Diffstat (limited to 'include')
-rw-r--r-- | include/drm/drm_fixed.h | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/include/drm/drm_fixed.h b/include/drm/drm_fixed.h index f5e1168c7647..d639049a613d 100644 --- a/include/drm/drm_fixed.h +++ b/include/drm/drm_fixed.h | |||
@@ -84,12 +84,12 @@ static inline int drm_fixp2int(int64_t a) | |||
84 | return ((s64)a) >> DRM_FIXED_POINT; | 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 | unsigned shift, sign = (a >> 63) & 1; | 89 | unsigned shift, sign = (a >> 63) & 1; |
90 | 90 | ||
91 | for (shift = 62; shift > 0; --shift) | 91 | for (shift = 62; shift > 0; --shift) |
92 | if ((a >> shift) != sign) | 92 | if (((a >> shift) & 1) != sign) |
93 | return shift; | 93 | return shift; |
94 | 94 | ||
95 | return 0; | 95 | return 0; |
@@ -100,9 +100,9 @@ static inline s64 drm_fixp_mul(s64 a, s64 b) | |||
100 | unsigned shift = drm_fixp_msbset(a) + drm_fixp_msbset(b); | 100 | unsigned shift = drm_fixp_msbset(a) + drm_fixp_msbset(b); |
101 | s64 result; | 101 | s64 result; |
102 | 102 | ||
103 | if (shift > 63) { | 103 | if (shift > 61) { |
104 | shift = shift - 63; | 104 | shift = shift - 61; |
105 | a >>= shift >> 1; | 105 | a >>= (shift >> 1) + (shift & 1); |
106 | b >>= shift >> 1; | 106 | b >>= shift >> 1; |
107 | } else | 107 | } else |
108 | shift = 0; | 108 | shift = 0; |
@@ -120,7 +120,7 @@ static inline s64 drm_fixp_mul(s64 a, s64 b) | |||
120 | 120 | ||
121 | static inline s64 drm_fixp_div(s64 a, s64 b) | 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 | s64 result; | 124 | s64 result; |
125 | 125 | ||
126 | a <<= shift; | 126 | a <<= shift; |
@@ -154,7 +154,7 @@ static inline s64 drm_fixp_exp(s64 x) | |||
154 | } | 154 | } |
155 | 155 | ||
156 | if (x < 0) | 156 | if (x < 0) |
157 | sum = drm_fixp_div(1, sum); | 157 | sum = drm_fixp_div(DRM_FIXED_ONE, sum); |
158 | 158 | ||
159 | return sum; | 159 | return sum; |
160 | } | 160 | } |