Re: [PATCH 1/2] math128: Introduce {mult,add,cmp}_u128

From: Jay Foad
Date: Wed Apr 25 2012 - 10:29:33 EST


> +#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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/