mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Mischa Jonker <Mischa.Jonker@synopsys.com>
Cc: "Vineet.Gupta1@synopsys.com" <Vineet.Gupta1@synopsys.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ARC: Fix __udelay parentheses
Date: Wed, 28 Aug 2013 12:01:47 -0700	[thread overview]
Message-ID: <1377716507.1928.57.camel@joe-AO722> (raw)
In-Reply-To: <E6BF041E97966E4DB955F0DF883AD2D684F1F601@de02wembxa.internal.synopsys.com>

On Wed, 2013-08-28 at 18:53 +0000, Mischa Jonker wrote:
> > > Make sure that usecs is casted to long long, to ensure that the (usecs
> > > * 4295 * HZ) multiplication is 64 bit.
> > >
> > > Initially, the (usecs * 4295 * HZ) part was done as a 32 bit
> > > multiplication, with the result casted to 64 bit. This led to some
> > > bits falling off.
> > >
> > > Signed-off-by: Mischa Jonker <mjonker@synopsys.com>
> > > ---
> > >  arch/arc/include/asm/delay.h |    4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/arch/arc/include/asm/delay.h
> > > b/arch/arc/include/asm/delay.h index 442ce5d..8d35fe1 100644
> > > --- a/arch/arc/include/asm/delay.h
> > > +++ b/arch/arc/include/asm/delay.h
> > > @@ -56,8 +56,8 @@ static inline void __udelay(unsigned long usecs)
> > >  	/* (long long) cast ensures 64 bit MPY - real or emulated
> > >  	 * HZ * 4295 is pre-evaluated by gcc - hence only 2 mpy ops
> > >  	 */
> > > -	loops = ((long long)(usecs * 4295 * HZ) *
> > > -		 (long long)(loops_per_jiffy)) >> 32;
> > > +	loops = (((long long) usecs) * 4295 * HZ *
> > > +		  (long long) loops_per_jiffy) >> 32;
> > 
> > Shouldn't this be unsigned long long or u64?
> Yes, it should, but that is not directly related to the issue:) 
> 
> > Why is it >> 32 again?
> > 
> > The comment above it doesn't seem to match the code.
> > 
> The original code explains about the >> 32:
> 
> /*
>  * Normal Math for computing loops in "N" usecs
>  *  -we have precomputed @loops_per_jiffy
>  *  -1 sec has HZ jiffies
>  * loops per "N" usecs = ((loops_per_jiffy * HZ / 1000000) * N)
>  *
>  * Approximate Division by multiplication:
>  *  -Mathematically if we multiply and divide a number by same value the
>  *   result remains unchanged:  In this case, we use 2^32
>  *  -> (loops_per_N_usec * 2^32 ) / 2^32
>  *  -> (((loops_per_jiffy * HZ / 1000000) * N) * 2^32) / 2^32
>  *  -> (loops_per_jiffy * HZ * N * 4295) / 2^32
>  *
>  *  -Divide by 2^32 is very simply right shift by 32
>  *  -We simply need to ensure that the multiply per above eqn happens in
>  *   64-bit precision (if CPU doesn't support it - gcc can emaulate it)
>  */

I don't see the loops_per_jiffy initial shift << 32.

> The problem is that the original code already _tried_ to cast to 64 bits (to ensure a 64 bit multiply), but only did so after the multiply (so 32 bit multiply).

I know that.  It's the use of a signed long long
vs the unsigned long long that I think wrong.

Why cast a unsigned to a signed?



  reply	other threads:[~2013-08-28 19:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-28 18:29 Mischa Jonker
2013-08-28 18:45 ` Joe Perches
2013-08-28 18:53   ` Mischa Jonker
2013-08-28 19:01     ` Joe Perches [this message]
2013-08-28 19:12       ` Mischa Jonker
2013-08-29  1:43         ` Joe Perches
2013-08-29  5:55 ` Vineet Gupta
2013-08-29  6:01   ` Joe Perches
2013-08-29  6:24     ` Vineet Gupta
2013-08-29  6:37       ` Joe Perches
2013-08-29  6:49         ` Vineet Gupta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1377716507.1928.57.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=Mischa.Jonker@synopsys.com \
    --cc=Vineet.Gupta1@synopsys.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®