All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2 1/5] drm/i915: extract fixed point math to i915_fixed.h
Date: Tue, 20 Nov 2018 13:11:01 +0200	[thread overview]
Message-ID: <87ftvwf1h6.fsf@intel.com> (raw)
In-Reply-To: <20181116120729.7580-1-jani.nikula@intel.com>

On Fri, 16 Nov 2018, Jani Nikula <jani.nikula@intel.com> wrote:
> Reduce bloat in one of the bigger header files. Fix some indentation
> while at it. No functional changes.
>
> v2: Add include guards (Joonas)
>
> Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>

Pushed the series, thanks for the review.

BR,
Jani.

> ---
>  drivers/gpu/drm/i915/i915_drv.h   | 139 +----------------------------------
>  drivers/gpu/drm/i915/i915_fixed.h | 147 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 148 insertions(+), 138 deletions(-)
>  create mode 100644 drivers/gpu/drm/i915/i915_fixed.h
>
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index d69b71d368d3..9c2597a2784c 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -54,6 +54,7 @@
>  #include <drm/drm_cache.h>
>  #include <drm/drm_util.h>
>  
> +#include "i915_fixed.h"
>  #include "i915_params.h"
>  #include "i915_reg.h"
>  #include "i915_utils.h"
> @@ -127,144 +128,6 @@ bool i915_error_injected(void);
>  	__i915_printk(i915, i915_error_injected() ? KERN_DEBUG : KERN_ERR, \
>  		      fmt, ##__VA_ARGS__)
>  
> -typedef struct {
> -	uint32_t val;
> -} uint_fixed_16_16_t;
> -
> -#define FP_16_16_MAX ({ \
> -	uint_fixed_16_16_t fp; \
> -	fp.val = UINT_MAX; \
> -	fp; \
> -})
> -
> -static inline bool is_fixed16_zero(uint_fixed_16_16_t val)
> -{
> -	if (val.val == 0)
> -		return true;
> -	return false;
> -}
> -
> -static inline uint_fixed_16_16_t u32_to_fixed16(uint32_t val)
> -{
> -	uint_fixed_16_16_t fp;
> -
> -	WARN_ON(val > U16_MAX);
> -
> -	fp.val = val << 16;
> -	return fp;
> -}
> -
> -static inline uint32_t fixed16_to_u32_round_up(uint_fixed_16_16_t fp)
> -{
> -	return DIV_ROUND_UP(fp.val, 1 << 16);
> -}
> -
> -static inline uint32_t fixed16_to_u32(uint_fixed_16_16_t fp)
> -{
> -	return fp.val >> 16;
> -}
> -
> -static inline uint_fixed_16_16_t min_fixed16(uint_fixed_16_16_t min1,
> -						 uint_fixed_16_16_t min2)
> -{
> -	uint_fixed_16_16_t min;
> -
> -	min.val = min(min1.val, min2.val);
> -	return min;
> -}
> -
> -static inline uint_fixed_16_16_t max_fixed16(uint_fixed_16_16_t max1,
> -						 uint_fixed_16_16_t max2)
> -{
> -	uint_fixed_16_16_t max;
> -
> -	max.val = max(max1.val, max2.val);
> -	return max;
> -}
> -
> -static inline uint_fixed_16_16_t clamp_u64_to_fixed16(uint64_t val)
> -{
> -	uint_fixed_16_16_t fp;
> -	WARN_ON(val > U32_MAX);
> -	fp.val = (uint32_t) val;
> -	return fp;
> -}
> -
> -static inline uint32_t div_round_up_fixed16(uint_fixed_16_16_t val,
> -					    uint_fixed_16_16_t d)
> -{
> -	return DIV_ROUND_UP(val.val, d.val);
> -}
> -
> -static inline uint32_t mul_round_up_u32_fixed16(uint32_t val,
> -						uint_fixed_16_16_t mul)
> -{
> -	uint64_t intermediate_val;
> -
> -	intermediate_val = (uint64_t) val * mul.val;
> -	intermediate_val = DIV_ROUND_UP_ULL(intermediate_val, 1 << 16);
> -	WARN_ON(intermediate_val > U32_MAX);
> -	return (uint32_t) intermediate_val;
> -}
> -
> -static inline uint_fixed_16_16_t mul_fixed16(uint_fixed_16_16_t val,
> -					     uint_fixed_16_16_t mul)
> -{
> -	uint64_t intermediate_val;
> -
> -	intermediate_val = (uint64_t) val.val * mul.val;
> -	intermediate_val = intermediate_val >> 16;
> -	return clamp_u64_to_fixed16(intermediate_val);
> -}
> -
> -static inline uint_fixed_16_16_t div_fixed16(uint32_t val, uint32_t d)
> -{
> -	uint64_t interm_val;
> -
> -	interm_val = (uint64_t)val << 16;
> -	interm_val = DIV_ROUND_UP_ULL(interm_val, d);
> -	return clamp_u64_to_fixed16(interm_val);
> -}
> -
> -static inline uint32_t div_round_up_u32_fixed16(uint32_t val,
> -						uint_fixed_16_16_t d)
> -{
> -	uint64_t interm_val;
> -
> -	interm_val = (uint64_t)val << 16;
> -	interm_val = DIV_ROUND_UP_ULL(interm_val, d.val);
> -	WARN_ON(interm_val > U32_MAX);
> -	return (uint32_t) interm_val;
> -}
> -
> -static inline uint_fixed_16_16_t mul_u32_fixed16(uint32_t val,
> -						     uint_fixed_16_16_t mul)
> -{
> -	uint64_t intermediate_val;
> -
> -	intermediate_val = (uint64_t) val * mul.val;
> -	return clamp_u64_to_fixed16(intermediate_val);
> -}
> -
> -static inline uint_fixed_16_16_t add_fixed16(uint_fixed_16_16_t add1,
> -					     uint_fixed_16_16_t add2)
> -{
> -	uint64_t interm_sum;
> -
> -	interm_sum = (uint64_t) add1.val + add2.val;
> -	return clamp_u64_to_fixed16(interm_sum);
> -}
> -
> -static inline uint_fixed_16_16_t add_fixed16_u32(uint_fixed_16_16_t add1,
> -						 uint32_t add2)
> -{
> -	uint64_t interm_sum;
> -	uint_fixed_16_16_t interm_add2 = u32_to_fixed16(add2);
> -
> -	interm_sum = (uint64_t) add1.val + interm_add2.val;
> -	return clamp_u64_to_fixed16(interm_sum);
> -}
> -
>  enum hpd_pin {
>  	HPD_NONE = 0,
>  	HPD_TV = HPD_NONE,     /* TV is known to be unreliable */
> diff --git a/drivers/gpu/drm/i915/i915_fixed.h b/drivers/gpu/drm/i915/i915_fixed.h
> new file mode 100644
> index 000000000000..c974e51c6d8b
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/i915_fixed.h
> @@ -0,0 +1,147 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright © 2018 Intel Corporation
> + */
> +
> +#ifndef _I915_FIXED_H_
> +#define _I915_FIXED_H_
> +
> +typedef struct {
> +	uint32_t val;
> +} uint_fixed_16_16_t;
> +
> +#define FP_16_16_MAX ({ \
> +	uint_fixed_16_16_t fp; \
> +	fp.val = UINT_MAX; \
> +	fp; \
> +})
> +
> +static inline bool is_fixed16_zero(uint_fixed_16_16_t val)
> +{
> +	if (val.val == 0)
> +		return true;
> +	return false;
> +}
> +
> +static inline uint_fixed_16_16_t u32_to_fixed16(uint32_t val)
> +{
> +	uint_fixed_16_16_t fp;
> +
> +	WARN_ON(val > U16_MAX);
> +
> +	fp.val = val << 16;
> +	return fp;
> +}
> +
> +static inline uint32_t fixed16_to_u32_round_up(uint_fixed_16_16_t fp)
> +{
> +	return DIV_ROUND_UP(fp.val, 1 << 16);
> +}
> +
> +static inline uint32_t fixed16_to_u32(uint_fixed_16_16_t fp)
> +{
> +	return fp.val >> 16;
> +}
> +
> +static inline uint_fixed_16_16_t min_fixed16(uint_fixed_16_16_t min1,
> +					     uint_fixed_16_16_t min2)
> +{
> +	uint_fixed_16_16_t min;
> +
> +	min.val = min(min1.val, min2.val);
> +	return min;
> +}
> +
> +static inline uint_fixed_16_16_t max_fixed16(uint_fixed_16_16_t max1,
> +					     uint_fixed_16_16_t max2)
> +{
> +	uint_fixed_16_16_t max;
> +
> +	max.val = max(max1.val, max2.val);
> +	return max;
> +}
> +
> +static inline uint_fixed_16_16_t clamp_u64_to_fixed16(uint64_t val)
> +{
> +	uint_fixed_16_16_t fp;
> +	WARN_ON(val > U32_MAX);
> +	fp.val = (uint32_t) val;
> +	return fp;
> +}
> +
> +static inline uint32_t div_round_up_fixed16(uint_fixed_16_16_t val,
> +					    uint_fixed_16_16_t d)
> +{
> +	return DIV_ROUND_UP(val.val, d.val);
> +}
> +
> +static inline uint32_t mul_round_up_u32_fixed16(uint32_t val,
> +						uint_fixed_16_16_t mul)
> +{
> +	uint64_t intermediate_val;
> +
> +	intermediate_val = (uint64_t) val * mul.val;
> +	intermediate_val = DIV_ROUND_UP_ULL(intermediate_val, 1 << 16);
> +	WARN_ON(intermediate_val > U32_MAX);
> +	return (uint32_t) intermediate_val;
> +}
> +
> +static inline uint_fixed_16_16_t mul_fixed16(uint_fixed_16_16_t val,
> +					     uint_fixed_16_16_t mul)
> +{
> +	uint64_t intermediate_val;
> +
> +	intermediate_val = (uint64_t) val.val * mul.val;
> +	intermediate_val = intermediate_val >> 16;
> +	return clamp_u64_to_fixed16(intermediate_val);
> +}
> +
> +static inline uint_fixed_16_16_t div_fixed16(uint32_t val, uint32_t d)
> +{
> +	uint64_t interm_val;
> +
> +	interm_val = (uint64_t)val << 16;
> +	interm_val = DIV_ROUND_UP_ULL(interm_val, d);
> +	return clamp_u64_to_fixed16(interm_val);
> +}
> +
> +static inline uint32_t div_round_up_u32_fixed16(uint32_t val,
> +						uint_fixed_16_16_t d)
> +{
> +	uint64_t interm_val;
> +
> +	interm_val = (uint64_t)val << 16;
> +	interm_val = DIV_ROUND_UP_ULL(interm_val, d.val);
> +	WARN_ON(interm_val > U32_MAX);
> +	return (uint32_t) interm_val;
> +}
> +
> +static inline uint_fixed_16_16_t mul_u32_fixed16(uint32_t val,
> +						 uint_fixed_16_16_t mul)
> +{
> +	uint64_t intermediate_val;
> +
> +	intermediate_val = (uint64_t) val * mul.val;
> +	return clamp_u64_to_fixed16(intermediate_val);
> +}
> +
> +static inline uint_fixed_16_16_t add_fixed16(uint_fixed_16_16_t add1,
> +					     uint_fixed_16_16_t add2)
> +{
> +	uint64_t interm_sum;
> +
> +	interm_sum = (uint64_t) add1.val + add2.val;
> +	return clamp_u64_to_fixed16(interm_sum);
> +}
> +
> +static inline uint_fixed_16_16_t add_fixed16_u32(uint_fixed_16_16_t add1,
> +						 uint32_t add2)
> +{
> +	uint64_t interm_sum;
> +	uint_fixed_16_16_t interm_add2 = u32_to_fixed16(add2);
> +
> +	interm_sum = (uint64_t) add1.val + interm_add2.val;
> +	return clamp_u64_to_fixed16(interm_sum);
> +}
> +
> +#endif /* _I915_FIXED_H_ */

-- 
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

      parent reply	other threads:[~2018-11-20 11:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-16 12:07 [PATCH v2 1/5] drm/i915: extract fixed point math to i915_fixed.h Jani Nikula
2018-11-16 12:07 ` [PATCH v2 2/5] drm/i915/fixed: prefer kernel types over stdint types Jani Nikula
2018-11-16 19:27   ` Rodrigo Vivi
2018-11-16 12:07 ` [PATCH v2 3/5] drm/i915/fixed: simplify FP_16_16_MAX definition Jani Nikula
2018-11-16 12:07 ` [PATCH v2 4/5] drm/i915/fixed: simplify is_fixed16_zero() Jani Nikula
2018-11-16 12:07 ` [PATCH v2 5/5] drm/i915/fixed: cosmetic cleanup Jani Nikula
2018-11-16 12:16 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [v2,1/5] drm/i915: extract fixed point math to i915_fixed.h Patchwork
2018-11-16 12:19 ` ✗ Fi.CI.SPARSE: " Patchwork
2018-11-16 12:47 ` ✓ Fi.CI.BAT: success " Patchwork
2018-11-16 23:18 ` ✓ Fi.CI.IGT: " Patchwork
2018-11-20 11:11 ` Jani Nikula [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ftvwf1h6.fsf@intel.com \
    --to=jani.nikula@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.