Re: gcc extension in get_user_pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 19 May 2003, Jan Hudec wrote:

> On Fri, May 16, 2003 at 05:33:58PM -0400, Ed L Cashin wrote:
> >    x ? : y
> > .. is the same as
> >    x ? x : y
> >
<snip/>
> > is there some better reason than being one character shorter -- like
> > maybe better asm gets produced when the extension is used?
>
> I would bet it's used because it's two characters less to type... and
> perhaps because anyone who wrote it is used to it and it's more readable
> for them.

You got me curious, so I checked.  With the kernel optimisations of -O2
then there's no difference.  Hence I'd go with the above suggestion that
it's just something that the author felt comfortable with.

(BTW, I'm Australian, so I can spell "optimisation" with an 's' ;-)



Without optimisation then the generated assembler *is* different.

  y = x ? x : 2;

When x is on the stack (at 8(%ebp)) then this translates to:

        movl 8(%ebp),%eax
	cmpl $0,8(%ebp)
	jne .L3
	movl $2,%eax
.L3:


...and the result is in %eax.  Whereas, the expression
  y = x ? : 2;
results in:

        movl 8(%ebp),%edx
	movl %edx,%eax
	testl %edx,%edx
	jne .L3
	movl $2,%eax
.L3:


However, under -O2 then both notations give:

	movl 8(%ebp),%eax
	testl %eax,%eax
	jne .L3
	movl $2,%eax
.L3:




Regards,
Paul Gearon

Software Engineer                Telephone:   +61 7 3876 2188
Plugged In Software              Fax:         +61 7 3876 4899
http://www.PIsoftware.com        PGP Key available via finger

Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum
immane mittam.
(Translation from latin: "I have a catapult. Give me all the money,
or I will fling an enormous rock at your head.")


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux