[PATCH 1/2] drm/amd/display: Use macro for isnan check
Alex Deucher
alexdeucher at gmail.com
Wed Nov 29 20:30:53 UTC 2017
On Wed, Nov 29, 2017 at 3:21 PM, Harry Wentland <harry.wentland at amd.com> wrote:
> In code provided by HW teams we do a NaN check on floats
> by comparing the number against itself. This confuses most
> people including myself. Macro it out to make it self-explanatory.
>
> Don't do a NaN check for int.
>
> Signed-off-by: Harry Wentland <harry.wentland at amd.com>
> ---
> drivers/gpu/drm/amd/display/dc/calcs/dcn_calc_math.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/dc/calcs/dcn_calc_math.c b/drivers/gpu/drm/amd/display/dc/calcs/dcn_calc_math.c
> index b6abe0f3bb15..102b5db28402 100644
> --- a/drivers/gpu/drm/amd/display/dc/calcs/dcn_calc_math.c
> +++ b/drivers/gpu/drm/amd/display/dc/calcs/dcn_calc_math.c
> @@ -25,37 +25,35 @@
>
> #include "dcn_calc_math.h"
>
> +#define isNaN(number) number != number
To be on the safe side, you may want to add some parens around the
argument in case someone passes in an expression. E.g.,
#define isNaN(number) ((number) != (number))
Alex
> +
> float dcn_bw_mod(const float arg1, const float arg2)
> {
> - if (arg1 != arg1)
> + if (isNaN(arg1))
> return arg2;
> - if (arg2 != arg2)
> + if (isNaN(arg2))
> return arg1;
> return arg1 - arg1 * ((int) (arg1 / arg2));
> }
>
> float dcn_bw_min2(const float arg1, const float arg2)
> {
> - if (arg1 != arg1)
> + if (isNaN(arg1))
> return arg2;
> - if (arg2 != arg2)
> + if (isNaN(arg2))
> return arg1;
> return arg1 < arg2 ? arg1 : arg2;
> }
>
> unsigned int dcn_bw_max(const unsigned int arg1, const unsigned int arg2)
> {
> - if (arg1 != arg1)
> - return arg2;
> - if (arg2 != arg2)
> - return arg1;
> return arg1 > arg2 ? arg1 : arg2;
> }
> float dcn_bw_max2(const float arg1, const float arg2)
> {
> - if (arg1 != arg1)
> + if (isNaN(arg1))
> return arg2;
> - if (arg2 != arg2)
> + if (isNaN(arg2))
> return arg1;
> return arg1 > arg2 ? arg1 : arg2;
> }
> --
> 2.14.1
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
More information about the amd-gfx
mailing list