Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH 0/2] math128 - v2

1 view
Skip to first unread message

Peter Zijlstra

unread,
Apr 25, 2012, 7:28:50 AM4/25/12
to linux-...@vger.kernel.org, linux...@vger.kernel.org, Linus Torvalds, Andrew Morton, Juri Lelli, Andy Lutomirski
Take two of the math128 bits..

Changes since last time:
- Added gcc __int128 versions for where it works
- Added Andy's mul_u64_u32_shr() due to popular demand :-)
- Added {shl,shr}_u128 as requested by hpa (although I suspect he'll
use Andy's fancy function).
- Added a U128_INIT() constant initializer.
- Renamed mult_u128 to mul_u64_u64, hpa complaned the name was
misleading
- Fixed some of the code generation issues with add_u128 and
mul_u64_64.

I've also assumed we're all actually ok with adding this functionality,
so unless someone hollers I'll push this for inclusion.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Peter Zijlstra

unread,
Apr 25, 2012, 7:28:58 AM4/25/12
to linux-...@vger.kernel.org, linux...@vger.kernel.org, Linus Torvalds, Andrew Morton, Juri Lelli, Andy Lutomirski, Ingo Molnar, Thomas Gleixner, Peter Zijlstra
math128.patch

Peter Zijlstra

unread,
Apr 25, 2012, 7:29:15 AM4/25/12
to linux-...@vger.kernel.org, linux...@vger.kernel.org, Linus Torvalds, Andrew Morton, Juri Lelli, Andy Lutomirski, Ingo Molnar, Thomas Gleixner, H. Peter Anvin, Peter Zijlstra
math128-x86_64.patch

Jay Foad

unread,
Apr 25, 2012, 10:29:44 AM4/25/12
to linux-...@vger.kernel.org, Peter Zijlstra
> +#ifndef shl_u128
> +static inline u128 shl_u128(u128 x, unsigned int n)
> +{
> + u128 res;
> +
> + if (n < 64) {
> + res.hi = x.hi << n;
> + res.hi |= x.lo >> (64 - n);

This is undefined when n == 0.

> + res.lo = x.lo << n;
> + } else {
> + res.lo = 0;
> + res.hi = x.lo << (n - 64);
> + }
> +
> + return res;
> +}
> +#endif /* shl_u128 */
> +
> +#ifndef shr_u128
> +static inline u128 shr_u128(u128 x, unsigned int n)
> +{
> + u128 res;
> +
> + if (n < 64) {
> + res.lo = x.lo >> n;
> + res.lo |= x.hi << (64 - n);

Likewise.

> + res.hi = x.hi >> n;
> + } else {
> + res.hi = 0;
> + res.lo = x.hi >> (n - 64);
> + }
> +
> + return res;
> +}
> +#endif /* shr_u128 */

Jay.

Peter Zijlstra

unread,
Apr 25, 2012, 11:03:07 AM4/25/12
to Jay Foad, linux-...@vger.kernel.org
On Wed, 2012-04-25 at 15:29 +0100, Jay Foad wrote:
> > + res.hi |= x.lo >> (64 - n);
>
> This is undefined when n == 0.
>
>
Thanks, added a !n test.

Andy Lutomirski

unread,
Apr 25, 2012, 2:03:12 PM4/25/12
to Peter Zijlstra, linux-...@vger.kernel.org, linux...@vger.kernel.org, Linus Torvalds, Andrew Morton, Juri Lelli, Ingo Molnar, Thomas Gleixner, H. Peter Anvin
On Wed, Apr 25, 2012 at 4:15 AM, Peter Zijlstra <a.p.zi...@chello.nl> wrote:
> Cc: Ingo Molnar <mi...@kernel.org>
> Cc: Thomas Gleixner <tg...@linutronix.de>
> Cc: H. Peter Anvin <h...@zytor.com>
> Cc: Andrew Morton <ak...@linux-foundation.org>
> Cc: Linus Torvalds <torv...@linux-foundation.org>
> Signed-off-by: Peter Zijlstra <a.p.zi...@chello.nl>
> ---
>  arch/x86/include/asm/Kbuild    |    1 -
>  arch/x86/include/asm/math128.h |   39 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 39 insertions(+), 1 deletion(-)

> --- /dev/null
> +++ b/arch/x86/include/asm/math128.h
> @@ -0,0 +1,39 @@
> +#ifndef _ASM_MATH128_H
> +#define _ASM_MATH128_H
> +
> +#ifdef CONFIG_X86_64
> +
> +#ifdef __SIZEOF_INT128__
> +#define ARCH_HAS_INT128
> +#endif
> +
> +#ifndef ARCH_HAS_INT128
> +
> +static inline mul_u64_u64(u64 a, u64 b)

I think you're missing a return type and a 't'.

> +{
> +       u128 res;
> +
> +       asm("mulq %2"
> +               : "=a" (res.lo), "=d" (res.hi)
> +               :  "rm" (b), "0" (a));
> +
> +       return res;
> +}
> +#define mult_u64_u64 mult_u64_u64
> +
> +static inline add_u128(u128 a, u128 b)

Return type here, too.


--Andy

Peter Zijlstra

unread,
Apr 25, 2012, 2:11:01 PM4/25/12
to Andy Lutomirski, linux-...@vger.kernel.org, linux...@vger.kernel.org, Linus Torvalds, Andrew Morton, Juri Lelli, Ingo Molnar, Thomas Gleixner, H. Peter Anvin
On Wed, 2012-04-25 at 11:02 -0700, Andy Lutomirski wrote:
>
> > +static inline mul_u64_u64(u64 a, u64 b)
>
> I think you're missing a return type and a 't'.

argh, that's what you get for not actually compiling with an old enough
gcc :/

Fixed, thanks!
0 new messages