public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: Russell King - ARM Linux <linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>
Cc: Jan Weitzel <j.weitzel-guT5V/WYfQezQB+pC5nmwQ@public.gmane.org>,
	kaloz-p3rKhJxN3npAfugRpC6u6w@public.gmane.org,
	khc-9GfyWEdoJtJmR6Xm/wNWPw@public.gmane.org,
	tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org,
	eric.y.miao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
	rubini-9wsNiZum9E8@public.gmane.org,
	STEricsson_nomadik_linux-nkJGhpqTU55BDgjK7y7TUQ@public.gmane.org,
	ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org,
	kgene.kim-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	trivial-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH] ARM: type casts update_sched_clock cyc_to_sched_clock cyc_to_fixed_sched_clock
Date: Tue, 5 Apr 2011 13:12:57 +0200	[thread overview]
Message-ID: <20110405111257.GR13963@pengutronix.de> (raw)
In-Reply-To: <20110405090100.GC4699-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>

On Tue, Apr 05, 2011 at 10:01:00AM +0100, Russell King - ARM Linux wrote:
> On Tue, Apr 05, 2011 at 10:31:44AM +0200, Uwe Kleine-König wrote:
> > On Tue, Apr 05, 2011 at 08:56:22AM +0100, Russell King - ARM Linux wrote:
> > > On Tue, Apr 05, 2011 at 09:43:21AM +0200, Jan Weitzel wrote:
> > > > parameter "u32 mask" type cast befor inversion
> > s/befor/before/
> > 
> > > Nak.  I want a 32-bit all ones quantity.
> > > 
> > > unsigned long long vali = (unsigned short)~0;
> > > unsigned long long vall = ~(unsigned short)0;
> > > 
> > BTW, the definiton of vall is equivalent to 
> > 
> > 	unsigned long long valu = ~(unsigned int)0;
> > 
> > because ~ converts the unsigned short to unsigned int.
> 
> No.  The value gets promoted to int not unsigned int.
> 
> > > compiles to:
> > > 
> > > vali:
> > >         .word   65535
> > >         .word   0
> > > 
> > > vall:
> > >         .word   -1
> > >         .word   -1
> > I really wonder about that. If I take a value of 0xffffffff (i.e. a 32
> > bit wide int == ~0U) and assign that to an 64-bit unsigned long long I'd
> > expect it to get the value 0x00000000ffffffffULL, not
> > 0xffffffffffffffffULL. What's wrong?
> 
> See above.  int not unsigned int.  And it makes a difference:
> 
> unsigned long long vals = ~(int)0;
> unsigned long long valu = ~(unsigned int)0;
> 
> vals:
>         .word   -1
>         .word   -1
> valu:
>         .word   -1
>         .word   0
> 
ah, ok, makes sense and actually is consistent with my book.
(After knowing what I search I found it. The rules are:

 - A signed type of rank less than int
   -> int
 - An unsigned type of rank less than int,
   all of whose values can be represented in type int
   -> int
 - An unsigned type of rank less than int,
   all of whose values cannot be represented in type int
   -> unsigned int
).

So the maximal correct variant is (u32)(int)~0U or alternatively
(u32)(-1), right?

Thanks for your answer, best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

  parent reply	other threads:[~2011-04-05 11:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-05  7:43 [PATCH] ARM: type casts update_sched_clock cyc_to_sched_clock cyc_to_fixed_sched_clock Jan Weitzel
     [not found] ` <1301989401-11984-1-git-send-email-j.weitzel-guT5V/WYfQezQB+pC5nmwQ@public.gmane.org>
2011-04-05  7:56   ` Russell King - ARM Linux
2011-04-05  8:31     ` Uwe Kleine-König
     [not found]       ` <20110405083144.GN13963-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2011-04-05  9:01         ` Russell King - ARM Linux
     [not found]           ` <20110405090100.GC4699-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2011-04-05 11:12             ` Uwe Kleine-König [this message]
     [not found]               ` <20110405111257.GR13963-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2011-04-05 13:57                 ` Russell King - ARM Linux
2011-04-05 10:59         ` Jan Weitzel

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=20110405111257.GR13963@pengutronix.de \
    --to=u.kleine-koenig-bicnvbalz9megne8c9+irq@public.gmane.org \
    --cc=STEricsson_nomadik_linux-nkJGhpqTU55BDgjK7y7TUQ@public.gmane.org \
    --cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
    --cc=eric.y.miao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=j.weitzel-guT5V/WYfQezQB+pC5nmwQ@public.gmane.org \
    --cc=kaloz-p3rKhJxN3npAfugRpC6u6w@public.gmane.org \
    --cc=kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
    --cc=kgene.kim-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    --cc=khc-9GfyWEdoJtJmR6Xm/wNWPw@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
    --cc=linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=rubini-9wsNiZum9E8@public.gmane.org \
    --cc=tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org \
    --cc=trivial-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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