[Top] [All Lists]

Re: Fwd: about udelay in mips

To: loody <>
Subject: Re: Fwd: about udelay in mips
From: Ian Lance Taylor <>
Date: Thu, 27 Jan 2011 13:35:14 -0800
Cc: Sergei Shtylyov <>, gcc-help <>, Linux MIPS Mailing List <>
Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed;; s=beta; t=1296164121; bh=6lBbDGwCP9nCuKjZD+SzFVJruIQ=; h=From:To:Cc:Subject:References:Date:In-Reply-To:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; b=vWKlsFy2rZnzOmEL9PhYkgfOPqOlL058tfb1OTY1rO7JwTp7OsaStiBwbjQcVUJmQ g116b8oz5XrzrC+4m7aLQ==
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed;; s=beta; h=domainkey-signature:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type :content-transfer-encoding; bh=H045wxJqKdfLCFcLgGgbmOjTHaafT5TTkK+DCnaXn3o=; b=WK+YXQpE69whJCW2cPY/mJMrT9ro3OpGtWEw9+dY0tHS9XR7lH1t5OAmQif0HltUe6 86xtgDCSUW+ZBokzKKrw==
Domainkey-signature: a=rsa-sha1; c=nofws;; s=beta; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type:content-transfer-encoding; b=HfJZambmbuos4tL/13Uz3uR+T8ELDmhPv308on4R90fQt5D9m49TF/f7STY5A1jGBM TpJPErkatEbPXORBOpNg==
In-reply-to: <> (loody's message of "Thu, 27 Jan 2011 20:28:34 +0800")
Original-recipient: rfc822;
References: <> <> <> <> <> <> <> <>
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
loody <> 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


<Prev in Thread] Current Thread [Next in Thread>