lkml.org 
[lkml]   [2012]   [Apr]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 1/2] math128: Introduce {mult,add,cmp}_u128
From
> +#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.


\
 
 \ /
  Last update: 2012-04-25 16:33    [W:0.060 / U:0.540 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site