linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* some quesion about assembly when calling fork
@ 2009-09-16 14:23 loody
  2009-09-16 14:30 ` Ben Dooks
  2009-09-16 14:38 ` Alessandro Rubini
  0 siblings, 2 replies; 3+ messages in thread
From: loody @ 2009-09-16 14:23 UTC (permalink / raw)
  To: linux-arm-kernel

Dear all:
i copy the assembly code as below, I use uclibc.

       if ((pid = fork()) < 0) {
    84b4:       ebffffb5        bl      8390 <.text-0x48>
    84b8:       e1a03000        mov     r3, r0
    84bc:       e50b3010        str     r3, [fp, #-16]    xx1
    84c0:       e51b3010        ldr     r3, [fp, #-16]    xx2
    84c4:       e3530000        cmp     r3, #0  ; 0x0
    84c8:       aa000002        bge     84d8 <main+0x3c>
                printf("fork error");
    84cc:       e59f0040        ldr     r0, [pc, #64]   ; 8514 <.text
+0x13c>
    84d0:       ebffffba        bl      83c0 <.text-0x18>
    84d4:       ea00000b        b       8508 <main+0x6c>

why we store r3 and ld it back at the same place in xx1 and xx2.
does that have any relationship with fork?
appreciate your help,
miloody

^ permalink raw reply	[flat|nested] 3+ messages in thread

* some quesion about assembly when calling fork
  2009-09-16 14:23 some quesion about assembly when calling fork loody
@ 2009-09-16 14:30 ` Ben Dooks
  2009-09-16 14:38 ` Alessandro Rubini
  1 sibling, 0 replies; 3+ messages in thread
From: Ben Dooks @ 2009-09-16 14:30 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Sep 16, 2009 at 10:23:40PM +0800, loody wrote:
> Dear all:
> i copy the assembly code as below, I use uclibc.
> 
>        if ((pid = fork()) < 0) {
>     84b4:       ebffffb5        bl      8390 <.text-0x48>
>     84b8:       e1a03000        mov     r3, r0
>     84bc:       e50b3010        str     r3, [fp, #-16]    xx1
>     84c0:       e51b3010        ldr     r3, [fp, #-16]    xx2
>     84c4:       e3530000        cmp     r3, #0  ; 0x0
>     84c8:       aa000002        bge     84d8 <main+0x3c>
>                 printf("fork error");
>     84cc:       e59f0040        ldr     r0, [pc, #64]   ; 8514 <.text
> +0x13c>
>     84d0:       ebffffba        bl      83c0 <.text-0x18>
>     84d4:       ea00000b        b       8508 <main+0x6c>
> 
> why we store r3 and ld it back at the same place in xx1 and xx2.
> does that have any relationship with fork?
> appreciate your help,

It is possible that the compiler is not being told to optimise enough
and that it is failing to spot that it can fold those together, or that
it think there is somewhere else in the code that could branch back
here.

-- 
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* some quesion about assembly when calling fork
  2009-09-16 14:23 some quesion about assembly when calling fork loody
  2009-09-16 14:30 ` Ben Dooks
@ 2009-09-16 14:38 ` Alessandro Rubini
  1 sibling, 0 replies; 3+ messages in thread
From: Alessandro Rubini @ 2009-09-16 14:38 UTC (permalink / raw)
  To: linux-arm-kernel

>        if ((pid = fork()) < 0) {
>     84b4:       ebffffb5        bl      8390 <.text-0x48>
>     84b8:       e1a03000        mov     r3, r0
>     84bc:       e50b3010        str     r3, [fp, #-16]    xx1
>     84c0:       e51b3010        ldr     r3, [fp, #-16]    xx2
>     84c4:       e3530000        cmp     r3, #0  ; 0x0

You are not optimizing. So the compiler follows the statements
literally: first it stores the result of fork in pid. Then loads pid to
compare with zero.

If you optimize, I'm sure it won't even copy r0 to r3 before comparing.

/alessandro

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-09-16 14:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-16 14:23 some quesion about assembly when calling fork loody
2009-09-16 14:30 ` Ben Dooks
2009-09-16 14:38 ` Alessandro Rubini

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).