* Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields [not found] ` <m3r4t0565f.fsf@blackfin.pond.sub.org> @ 2012-07-08 11:37 ` Avi Kivity 2012-07-08 11:45 ` Blue Swirl 0 siblings, 1 reply; 2+ messages in thread From: Avi Kivity @ 2012-07-08 11:37 UTC (permalink / raw) To: Markus Armbruster; +Cc: Blue Swirl, Peter Maydell, qemu-devel, Jia Liu, patches On 06/28/2012 08:58 AM, Markus Armbruster wrote: >>> >>> Better code is an argument only if the effect can be demonstrated. >> >> I don't know even for which compilers or CPUs this is true so it's >> unlikely I could demonstrate it. However, googling finds a few >> articles in defense of this. > > Hearsay. Your honor, I rest my case :) On x86_64, conversion from unsigned to unsigned long takes zero instructions, but conversion from int to long takes one instruction. So expressions like a[i] are one instruction shorter if the index is unsigned. unsigned is also slightly safer from a security perspective, since you only need to consider overflow, not underflow. I used to be an int fan but I have been converted. My fingers still prefer int though. -- error compiling committee.c: too many arguments to function ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields 2012-07-08 11:37 ` [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields Avi Kivity @ 2012-07-08 11:45 ` Blue Swirl 0 siblings, 0 replies; 2+ messages in thread From: Blue Swirl @ 2012-07-08 11:45 UTC (permalink / raw) To: Avi Kivity; +Cc: qemu-devel, Peter Maydell, Markus Armbruster, Jia Liu, patches On Sun, Jul 8, 2012 at 11:37 AM, Avi Kivity <avi@redhat.com> wrote: > On 06/28/2012 08:58 AM, Markus Armbruster wrote: >>>> >>>> Better code is an argument only if the effect can be demonstrated. >>> >>> I don't know even for which compilers or CPUs this is true so it's >>> unlikely I could demonstrate it. However, googling finds a few >>> articles in defense of this. >> >> Hearsay. Your honor, I rest my case :) > > On x86_64, conversion from unsigned to unsigned long takes zero > instructions, but conversion from int to long takes one instruction. So > expressions like a[i] are one instruction shorter if the index is unsigned. > > unsigned is also slightly safer from a security perspective, since you > only need to consider overflow, not underflow. Q.E.D. Expect patches to convert bitops to unsigned shortly. > > I used to be an int fan but I have been converted. My fingers still > prefer int though. > > -- > error compiling committee.c: too many arguments to function > > ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-07-08 11:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1340653135-26749-1-git-send-email-peter.maydell@linaro.org>
[not found] ` <CAAu8pHuqj513DVNLXqsdD2Qg9+LwDHz6DzQxYn-HEnAA=0Unwg@mail.gmail.com>
[not found] ` <CAFEAcA-uHBFkfcwCtv0EKcJRNzYYf_jtTs1W9BECEeJo6gT+Xg@mail.gmail.com>
[not found] ` <CAAu8pHtcv6Z4Sa4FY53tA3zp3n8xBvQD_E1yYugaAVa-36eZow@mail.gmail.com>
[not found] ` <CAFEAcA8_BXHb8VPf8sqfJs39JF-CagaHj92tzA6ijtgnSVhmcA@mail.gmail.com>
[not found] ` <CAAu8pHtWt+aAaO-Vr_N5z7_qqzWknP+nRsxPg+iQAeoHdzmF4w@mail.gmail.com>
[not found] ` <m3zk7p2szw.fsf@blackfin.pond.sub.org>
[not found] ` <CAAu8pHv_CjT+bd_GA4eM9eG=1Sxz0EWF=nhSLTyixNjOXPMhTg@mail.gmail.com>
[not found] ` <m3r4t0565f.fsf@blackfin.pond.sub.org>
2012-07-08 11:37 ` [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields Avi Kivity
2012-07-08 11:45 ` Blue Swirl
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).