public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] math128 - v2
@ 2012-04-25 11:15 Peter Zijlstra
  2012-04-25 11:15 ` [PATCH 1/2] math128: Introduce {mult,add,cmp}_u128 Peter Zijlstra
  2012-04-25 11:15 ` [PATCH 2/2] math128, x86_64: Implement {mult,add}_u128 in 64bit asm Peter Zijlstra
  0 siblings, 2 replies; 8+ messages in thread
From: Peter Zijlstra @ 2012-04-25 11:15 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: 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.


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] math128: Introduce {mult,add,cmp}_u128
@ 2012-04-25 14:29 Jay Foad
  2012-04-25 15:02 ` Peter Zijlstra
  0 siblings, 1 reply; 8+ messages in thread
From: Jay Foad @ 2012-04-25 14:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: 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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-04-25 18:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-25 11:15 [PATCH 0/2] math128 - v2 Peter Zijlstra
2012-04-25 11:15 ` [PATCH 1/2] math128: Introduce {mult,add,cmp}_u128 Peter Zijlstra
2012-04-25 12:50   ` Peter Zijlstra
2012-04-25 11:15 ` [PATCH 2/2] math128, x86_64: Implement {mult,add}_u128 in 64bit asm Peter Zijlstra
2012-04-25 18:02   ` Andy Lutomirski
2012-04-25 18:10     ` Peter Zijlstra
  -- strict thread matches above, loose matches on Subject: below --
2012-04-25 14:29 [PATCH 1/2] math128: Introduce {mult,add,cmp}_u128 Jay Foad
2012-04-25 15:02 ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox