* [PATCH v3 1/1] drm/i915: Move abs_diff() to math.h
@ 2023-07-24 8:25 Andy Shevchenko
2023-07-24 8:34 ` Philipp Zabel
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Andy Shevchenko @ 2023-07-24 8:25 UTC (permalink / raw)
To: Jani Nikula, Imre Deak, Andy Shevchenko, Jiri Slaby,
Greg Kroah-Hartman, Ilpo Järvinen, Alexey Dobriyan,
intel-gfx, dri-devel, linux-kernel, linux-serial, linux-fbdev
Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Daniel Vetter, Philipp Zabel, Helge Deller,
Stephen Boyd, Nikita Shubin, Nikita Shubin via B4 Relay,
Andi Shyti
abs_diff() belongs to math.h. Move it there.
This will allow others to use it.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org> # tty/serial
---
v3: added tag (Jiri), removed space after a cast (fdo CI)
drivers/gpu/drm/i915/display/intel_dpll_mgr.c | 1 +
drivers/gpu/drm/i915/display/intel_dpll_mgr.h | 7 -------
drivers/gpu/ipu-v3/ipu-image-convert.c | 15 +++++++--------
drivers/tty/serial/omap-serial.c | 7 +------
drivers/video/fbdev/core/svgalib.c | 7 +------
include/linux/math.h | 7 +++++++
6 files changed, 17 insertions(+), 27 deletions(-)
diff --git a/drivers/gpu/drm/i915/display/intel_dpll_mgr.c b/drivers/gpu/drm/i915/display/intel_dpll_mgr.c
index 6b2d8a1e2aa9..290e856fe9e9 100644
--- a/drivers/gpu/drm/i915/display/intel_dpll_mgr.c
+++ b/drivers/gpu/drm/i915/display/intel_dpll_mgr.c
@@ -21,6 +21,7 @@
* DEALINGS IN THE SOFTWARE.
*/
+#include <linux/math.h>
#include <linux/string_helpers.h>
#include "i915_reg.h"
diff --git a/drivers/gpu/drm/i915/display/intel_dpll_mgr.h b/drivers/gpu/drm/i915/display/intel_dpll_mgr.h
index ba62eb5d7c51..04e6810954b2 100644
--- a/drivers/gpu/drm/i915/display/intel_dpll_mgr.h
+++ b/drivers/gpu/drm/i915/display/intel_dpll_mgr.h
@@ -29,13 +29,6 @@
#include "intel_wakeref.h"
-/*FIXME: Move this to a more appropriate place. */
-#define abs_diff(a, b) ({ \
- typeof(a) __a = (a); \
- typeof(b) __b = (b); \
- (void) (&__a == &__b); \
- __a > __b ? (__a - __b) : (__b - __a); })
-
enum tc_port;
struct drm_i915_private;
struct intel_atomic_state;
diff --git a/drivers/gpu/ipu-v3/ipu-image-convert.c b/drivers/gpu/ipu-v3/ipu-image-convert.c
index af1612044eef..841316582ea9 100644
--- a/drivers/gpu/ipu-v3/ipu-image-convert.c
+++ b/drivers/gpu/ipu-v3/ipu-image-convert.c
@@ -7,7 +7,10 @@
#include <linux/interrupt.h>
#include <linux/dma-mapping.h>
+#include <linux/math.h>
+
#include <video/imx-ipu-image-convert.h>
+
#include "ipu-prv.h"
/*
@@ -543,7 +546,7 @@ static void find_best_seam(struct ipu_image_convert_ctx *ctx,
unsigned int in_pos;
unsigned int in_pos_aligned;
unsigned int in_pos_rounded;
- unsigned int abs_diff;
+ unsigned int diff;
/*
* Tiles in the right row / bottom column may not be allowed to
@@ -575,15 +578,11 @@ static void find_best_seam(struct ipu_image_convert_ctx *ctx,
(in_edge - in_pos_rounded) % in_burst)
continue;
- if (in_pos < in_pos_aligned)
- abs_diff = in_pos_aligned - in_pos;
- else
- abs_diff = in_pos - in_pos_aligned;
-
- if (abs_diff < min_diff) {
+ diff = abs_diff(in_pos, in_pos_aligned);
+ if (diff < min_diff) {
in_seam = in_pos_rounded;
out_seam = out_pos;
- min_diff = abs_diff;
+ min_diff = diff;
}
}
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 82d35dbbfa6c..9be63a1f1f0c 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -222,16 +222,11 @@ static inline int calculate_baud_abs_diff(struct uart_port *port,
unsigned int baud, unsigned int mode)
{
unsigned int n = port->uartclk / (mode * baud);
- int abs_diff;
if (n == 0)
n = 1;
- abs_diff = baud - (port->uartclk / (mode * n));
- if (abs_diff < 0)
- abs_diff = -abs_diff;
-
- return abs_diff;
+ return abs_diff(baud, port->uartclk / (mode * n));
}
/*
diff --git a/drivers/video/fbdev/core/svgalib.c b/drivers/video/fbdev/core/svgalib.c
index 9e01322fabe3..2cba158888ea 100644
--- a/drivers/video/fbdev/core/svgalib.c
+++ b/drivers/video/fbdev/core/svgalib.c
@@ -14,6 +14,7 @@
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/fb.h>
+#include <linux/math.h>
#include <linux/svga.h>
#include <asm/types.h>
#include <asm/io.h>
@@ -372,12 +373,6 @@ EXPORT_SYMBOL(svga_get_caps);
* F_VCO = (F_BASE * M) / N
* F_OUT = F_VCO / (2^R)
*/
-
-static inline u32 abs_diff(u32 a, u32 b)
-{
- return (a > b) ? (a - b) : (b - a);
-}
-
int svga_compute_pll(const struct svga_pll *pll, u32 f_wanted, u16 *m, u16 *n, u16 *r, int node)
{
u16 am, an, ar;
diff --git a/include/linux/math.h b/include/linux/math.h
index 449a29b73f6d..4459d1786f77 100644
--- a/include/linux/math.h
+++ b/include/linux/math.h
@@ -157,6 +157,13 @@ __STRUCT_FRACT(u32)
__builtin_types_compatible_p(typeof(x), unsigned type), \
({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
+#define abs_diff(a, b) ({ \
+ typeof(a) __a = (a); \
+ typeof(b) __b = (b); \
+ (void)(&__a == &__b); \
+ __a > __b ? (__a - __b) : (__b - __a); \
+})
+
/**
* reciprocal_scale - "scale" a value into range [0, ep_ro)
* @val: value
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/1] drm/i915: Move abs_diff() to math.h
2023-07-24 8:25 [PATCH v3 1/1] drm/i915: Move abs_diff() to math.h Andy Shevchenko
@ 2023-07-24 8:34 ` Philipp Zabel
2023-07-25 12:51 ` [Intel-gfx] " Andi Shyti
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Philipp Zabel @ 2023-07-24 8:34 UTC (permalink / raw)
To: Andy Shevchenko, Jani Nikula, Imre Deak, Jiri Slaby,
Greg Kroah-Hartman, Ilpo Järvinen, Alexey Dobriyan,
intel-gfx, dri-devel, linux-kernel, linux-serial, linux-fbdev
Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Daniel Vetter, Helge Deller, Stephen Boyd,
Nikita Shubin, Nikita Shubin via B4 Relay, Andi Shyti
On Mo, 2023-07-24 at 11:25 +0300, Andy Shevchenko wrote:
> abs_diff() belongs to math.h. Move it there.
> This will allow others to use it.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Jiri Slaby <jirislaby@kernel.org> # tty/serial
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> # gpu/ipu-v3
regards
Philipp
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Intel-gfx] [PATCH v3 1/1] drm/i915: Move abs_diff() to math.h
2023-07-24 8:25 [PATCH v3 1/1] drm/i915: Move abs_diff() to math.h Andy Shevchenko
2023-07-24 8:34 ` Philipp Zabel
@ 2023-07-25 12:51 ` Andi Shyti
2023-07-25 17:10 ` Greg Kroah-Hartman
2023-07-31 10:29 ` Jani Nikula
3 siblings, 0 replies; 5+ messages in thread
From: Andi Shyti @ 2023-07-25 12:51 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jani Nikula, Imre Deak, Jiri Slaby, Greg Kroah-Hartman,
Ilpo Järvinen, Alexey Dobriyan, intel-gfx, dri-devel,
linux-kernel, linux-serial, linux-fbdev, Philipp Zabel,
Nikita Shubin, Stephen Boyd, Helge Deller, Andi Shyti,
Daniel Vetter, Rodrigo Vivi, David Airlie,
Nikita Shubin via B4 Relay
Hi Andy,
On Mon, Jul 24, 2023 at 11:25:11AM +0300, Andy Shevchenko wrote:
> abs_diff() belongs to math.h. Move it there.
> This will allow others to use it.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Jiri Slaby <jirislaby@kernel.org> # tty/serial
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Thanks,
Andi
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/1] drm/i915: Move abs_diff() to math.h
2023-07-24 8:25 [PATCH v3 1/1] drm/i915: Move abs_diff() to math.h Andy Shevchenko
2023-07-24 8:34 ` Philipp Zabel
2023-07-25 12:51 ` [Intel-gfx] " Andi Shyti
@ 2023-07-25 17:10 ` Greg Kroah-Hartman
2023-07-31 10:29 ` Jani Nikula
3 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2023-07-25 17:10 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jani Nikula, Imre Deak, Jiri Slaby, Ilpo Järvinen,
Alexey Dobriyan, intel-gfx, dri-devel, linux-kernel, linux-serial,
linux-fbdev, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin, David Airlie, Daniel Vetter, Philipp Zabel,
Helge Deller, Stephen Boyd, Nikita Shubin,
Nikita Shubin via B4 Relay, Andi Shyti
On Mon, Jul 24, 2023 at 11:25:11AM +0300, Andy Shevchenko wrote:
> abs_diff() belongs to math.h. Move it there.
> This will allow others to use it.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Jiri Slaby <jirislaby@kernel.org> # tty/serial
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/1] drm/i915: Move abs_diff() to math.h
2023-07-24 8:25 [PATCH v3 1/1] drm/i915: Move abs_diff() to math.h Andy Shevchenko
` (2 preceding siblings ...)
2023-07-25 17:10 ` Greg Kroah-Hartman
@ 2023-07-31 10:29 ` Jani Nikula
3 siblings, 0 replies; 5+ messages in thread
From: Jani Nikula @ 2023-07-31 10:29 UTC (permalink / raw)
To: Andy Shevchenko, Imre Deak, Andy Shevchenko, Jiri Slaby,
Greg Kroah-Hartman, Ilpo Järvinen, Alexey Dobriyan,
intel-gfx, dri-devel, linux-kernel, linux-serial, linux-fbdev
Cc: Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Daniel Vetter, Philipp Zabel, Helge Deller, Stephen Boyd,
Nikita Shubin, Nikita Shubin via B4 Relay, Andi Shyti
On Mon, 24 Jul 2023, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> abs_diff() belongs to math.h. Move it there.
> This will allow others to use it.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Jiri Slaby <jirislaby@kernel.org> # tty/serial
> ---
> v3: added tag (Jiri), removed space after a cast (fdo CI)
> drivers/gpu/drm/i915/display/intel_dpll_mgr.c | 1 +
> drivers/gpu/drm/i915/display/intel_dpll_mgr.h | 7 -------
Acked-by: Jani Nikula <jani.nikula@intel.com>
for merging the i915 parts via whichever tree is most convenient for
you.
> drivers/gpu/ipu-v3/ipu-image-convert.c | 15 +++++++--------
> drivers/tty/serial/omap-serial.c | 7 +------
> drivers/video/fbdev/core/svgalib.c | 7 +------
> include/linux/math.h | 7 +++++++
> 6 files changed, 17 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_dpll_mgr.c b/drivers/gpu/drm/i915/display/intel_dpll_mgr.c
> index 6b2d8a1e2aa9..290e856fe9e9 100644
> --- a/drivers/gpu/drm/i915/display/intel_dpll_mgr.c
> +++ b/drivers/gpu/drm/i915/display/intel_dpll_mgr.c
> @@ -21,6 +21,7 @@
> * DEALINGS IN THE SOFTWARE.
> */
>
> +#include <linux/math.h>
> #include <linux/string_helpers.h>
>
> #include "i915_reg.h"
> diff --git a/drivers/gpu/drm/i915/display/intel_dpll_mgr.h b/drivers/gpu/drm/i915/display/intel_dpll_mgr.h
> index ba62eb5d7c51..04e6810954b2 100644
> --- a/drivers/gpu/drm/i915/display/intel_dpll_mgr.h
> +++ b/drivers/gpu/drm/i915/display/intel_dpll_mgr.h
> @@ -29,13 +29,6 @@
>
> #include "intel_wakeref.h"
>
> -/*FIXME: Move this to a more appropriate place. */
> -#define abs_diff(a, b) ({ \
> - typeof(a) __a = (a); \
> - typeof(b) __b = (b); \
> - (void) (&__a == &__b); \
> - __a > __b ? (__a - __b) : (__b - __a); })
> -
> enum tc_port;
> struct drm_i915_private;
> struct intel_atomic_state;
> diff --git a/drivers/gpu/ipu-v3/ipu-image-convert.c b/drivers/gpu/ipu-v3/ipu-image-convert.c
> index af1612044eef..841316582ea9 100644
> --- a/drivers/gpu/ipu-v3/ipu-image-convert.c
> +++ b/drivers/gpu/ipu-v3/ipu-image-convert.c
> @@ -7,7 +7,10 @@
>
> #include <linux/interrupt.h>
> #include <linux/dma-mapping.h>
> +#include <linux/math.h>
> +
> #include <video/imx-ipu-image-convert.h>
> +
> #include "ipu-prv.h"
>
> /*
> @@ -543,7 +546,7 @@ static void find_best_seam(struct ipu_image_convert_ctx *ctx,
> unsigned int in_pos;
> unsigned int in_pos_aligned;
> unsigned int in_pos_rounded;
> - unsigned int abs_diff;
> + unsigned int diff;
>
> /*
> * Tiles in the right row / bottom column may not be allowed to
> @@ -575,15 +578,11 @@ static void find_best_seam(struct ipu_image_convert_ctx *ctx,
> (in_edge - in_pos_rounded) % in_burst)
> continue;
>
> - if (in_pos < in_pos_aligned)
> - abs_diff = in_pos_aligned - in_pos;
> - else
> - abs_diff = in_pos - in_pos_aligned;
> -
> - if (abs_diff < min_diff) {
> + diff = abs_diff(in_pos, in_pos_aligned);
> + if (diff < min_diff) {
> in_seam = in_pos_rounded;
> out_seam = out_pos;
> - min_diff = abs_diff;
> + min_diff = diff;
> }
> }
>
> diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
> index 82d35dbbfa6c..9be63a1f1f0c 100644
> --- a/drivers/tty/serial/omap-serial.c
> +++ b/drivers/tty/serial/omap-serial.c
> @@ -222,16 +222,11 @@ static inline int calculate_baud_abs_diff(struct uart_port *port,
> unsigned int baud, unsigned int mode)
> {
> unsigned int n = port->uartclk / (mode * baud);
> - int abs_diff;
>
> if (n == 0)
> n = 1;
>
> - abs_diff = baud - (port->uartclk / (mode * n));
> - if (abs_diff < 0)
> - abs_diff = -abs_diff;
> -
> - return abs_diff;
> + return abs_diff(baud, port->uartclk / (mode * n));
> }
>
> /*
> diff --git a/drivers/video/fbdev/core/svgalib.c b/drivers/video/fbdev/core/svgalib.c
> index 9e01322fabe3..2cba158888ea 100644
> --- a/drivers/video/fbdev/core/svgalib.c
> +++ b/drivers/video/fbdev/core/svgalib.c
> @@ -14,6 +14,7 @@
> #include <linux/kernel.h>
> #include <linux/string.h>
> #include <linux/fb.h>
> +#include <linux/math.h>
> #include <linux/svga.h>
> #include <asm/types.h>
> #include <asm/io.h>
> @@ -372,12 +373,6 @@ EXPORT_SYMBOL(svga_get_caps);
> * F_VCO = (F_BASE * M) / N
> * F_OUT = F_VCO / (2^R)
> */
> -
> -static inline u32 abs_diff(u32 a, u32 b)
> -{
> - return (a > b) ? (a - b) : (b - a);
> -}
> -
> int svga_compute_pll(const struct svga_pll *pll, u32 f_wanted, u16 *m, u16 *n, u16 *r, int node)
> {
> u16 am, an, ar;
> diff --git a/include/linux/math.h b/include/linux/math.h
> index 449a29b73f6d..4459d1786f77 100644
> --- a/include/linux/math.h
> +++ b/include/linux/math.h
> @@ -157,6 +157,13 @@ __STRUCT_FRACT(u32)
> __builtin_types_compatible_p(typeof(x), unsigned type), \
> ({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
>
> +#define abs_diff(a, b) ({ \
> + typeof(a) __a = (a); \
> + typeof(b) __b = (b); \
> + (void)(&__a == &__b); \
> + __a > __b ? (__a - __b) : (__b - __a); \
> +})
> +
> /**
> * reciprocal_scale - "scale" a value into range [0, ep_ro)
> * @val: value
--
Jani Nikula, Intel Open Source Graphics Center
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-07-31 10:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-24 8:25 [PATCH v3 1/1] drm/i915: Move abs_diff() to math.h Andy Shevchenko
2023-07-24 8:34 ` Philipp Zabel
2023-07-25 12:51 ` [Intel-gfx] " Andi Shyti
2023-07-25 17:10 ` Greg Kroah-Hartman
2023-07-31 10:29 ` Jani Nikula
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).