diff options
| author | Casey Connolly <[email protected]> | 2026-04-01 16:15:27 +0200 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-04-21 11:19:49 -0600 |
| commit | f1f4a1d1d8355b0fc6bfc82d9ca6741a8e92623b (patch) | |
| tree | e256f1b0603c842cb3d7ad5b5f529c4e7f816ad7 /include/linux/math64.h | |
| parent | 076265b75e61f56490003639b3d0a6483a9f507f (diff) | |
compat: math64: add abs_diff()
Add the abs_diff() macro, copied directly from Linux 6.18.
Signed-off-by: Casey Connolly <[email protected]>
Diffstat (limited to 'include/linux/math64.h')
| -rw-r--r-- | include/linux/math64.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/linux/math64.h b/include/linux/math64.h index eaa9fd5b968..70a7ee3ff1d 100644 --- a/include/linux/math64.h +++ b/include/linux/math64.h @@ -257,4 +257,23 @@ static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 divisor) } #endif /* mul_u64_u32_div */ +/** + * abs_diff - return absolute value of the difference between the arguments + * @a: the first argument + * @b: the second argument + * + * @a and @b have to be of the same type. With this restriction we compare + * signed to signed and unsigned to unsigned. The result is the subtraction + * the smaller of the two from the bigger, hence result is always a positive + * value. + * + * Return: an absolute value of the difference between the @a and @b. + */ +#define abs_diff(a, b) ({ \ + typeof(a) __a = (a); \ + typeof(b) __b = (b); \ + (void)(&__a == &__b); \ + __a > __b ? (__a - __b) : (__b - __a); \ +}) + #endif /* _LINUX_MATH64_H */ |
