From: Ian Lance Taylor <iant@google.com>
To: loody <miloody@gmail.com>
Cc: Sergei Shtylyov <sshtylyov@mvista.com>,
gcc-help <gcc-help@gcc.gnu.org>,
Linux MIPS Mailing List <linux-mips@linux-mips.org>
Subject: Re: Fwd: about udelay in mips
Date: Thu, 27 Jan 2011 13:35:14 -0800 [thread overview]
Message-ID: <mcrlj26owrx.fsf@google.com> (raw)
In-Reply-To: <AANLkTimdXa9WS7WLuKgD4iOCXcwvi5gPf5fQ2_eMsiW_@mail.gmail.com> (loody's message of "Thu, 27 Jan 2011 20:28:34 +0800")
loody <miloody@gmail.com> writes:
>> Probably because in 2.6.30 you only cast the result of 32-bit multiplies
>> to 64 bits. In the 2.6.33 kernel, the mutliplies are 64-bit as the
>> 0x000010c7ull constant is 64-bit...
>
>>> void __udelay(unsigned long us)
>>> {
>>> unsigned int lpj = current_cpu_data.udelay_val;
>>>
>>> __delay(((unsigned long long)(us * 0x000010c7 * HZ * lpj)) >> 32);
> so that means (us * 0x000010c7 * HZ * lpj) is calculated at 32-bits and finally
> (unsigned long long) cast it as 64-bits?
> if i remember correctly, "64bit cast to 32-bits" is possible get 0
> value, since high bits cast out.
> But how 34-bits cast to 64-bits will make the value as 0 if original
> low 32-bits value is non-zero?
I don't know the type of HZ. But assuming it is a constant, then the
rules of C are that the expression
us * 0x000010c7 * HZ * lpj
gets evaluated in the type "unsigned long". The fact that you then cast
that "unsigned long" value to "unsigned long long" does not cause the
multiplication to be done in the type "unsigned long long".
You need to write something like
(unsigned long long) us * 0x000010c7 * HZ * (unsigned long long) lpj
to get the multiplication to be done in the "unsigned long long" type.
This questoin has nothing to do with gcc, by the way, it's a C language
question.
Ian
next prev parent reply other threads:[~2011-01-27 21:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-13 10:02 about udelay in mips loody
2011-01-14 5:31 ` wu zhangjin
2011-01-16 14:38 ` loody
2011-01-16 14:38 ` loody
2011-01-16 15:08 ` Geert Uytterhoeven
2011-01-16 16:34 ` wu zhangjin
[not found] ` <AANLkTi=zfr5YuwBCcvH2Jas50UxnUtvzp_CDyN25sT5h@mail.gmail.com>
2011-01-19 14:23 ` loody
2011-01-19 14:23 ` loody
2011-01-27 9:20 ` Fwd: " loody
2011-01-27 11:28 ` Sergei Shtylyov
2011-01-27 12:28 ` loody
2011-01-27 21:35 ` Ian Lance Taylor [this message]
2011-01-27 21:42 ` Maciej W. Rozycki
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=mcrlj26owrx.fsf@google.com \
--to=iant@google.com \
--cc=gcc-help@gcc.gnu.org \
--cc=linux-mips@linux-mips.org \
--cc=miloody@gmail.com \
--cc=sshtylyov@mvista.com \
/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