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

drm/amd/display: simplify dml log2 function

Current implementation is slightly inaccurate and will often
result in truncation/floor operation decrementing an exact
integer output by 1.

Only rounded down output is ever expected, just extract the fp
exponent for this to increase performance and avoid any
truncation issues.

Signed-off-by: Dmytro Laktyushkin <Dmytro.Laktyushkin@amd.com>
Reviewed-by: Eric Bernstein <Eric.Bernstein@amd.com>
Acked-by: Qingqing Zhuo <qingqing.zhuo@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Dmytro Laktyushkin and committed by
Alex Deucher
b236e048 0023b7ee

+13 -7
+13 -7
drivers/gpu/drm/amd/display/dc/dml/dml_inline_defs.h
··· 86 86 return floor; 87 87 } 88 88 89 - static inline double dml_log2(double x) 89 + /* float 90 + static inline int dml_log2(float x) 90 91 { 91 - return (double) dcn_bw_log(x, 2); 92 + unsigned int ix = *((unsigned int *)&x); 93 + 94 + return (int)((ix >> 23) & 0xff) - 127; 95 + }*/ 96 + 97 + /* double */ 98 + static inline int dml_log2(double x) 99 + { 100 + unsigned long long ix = *((unsigned long long *)&x); 101 + 102 + return (int)((ix >> 52) & 0x7ff) - 1023; 92 103 } 93 104 94 105 static inline double dml_pow(double a, int exp) ··· 125 114 static inline double dml_floor_ex(double x, double granularity) 126 115 { 127 116 return (double) dcn_bw_floor2(x, granularity); 128 - } 129 - 130 - static inline double dml_log(double x, double base) 131 - { 132 - return (double) dcn_bw_log(x, base); 133 117 } 134 118 135 119 static inline unsigned int dml_round_to_multiple(unsigned int num,