View Single Post

  #25  
Old 08-22-2008, 08:17 AM
Default Re: Questions about Minix

"Erik van der Kouwe" few.vu.nl> wrote:
> Storing in a variable is not the same thing as storing in memory. With
> a good compiler and optimization enabled it would be stored in a
> register:




> This should produce something like this:




Your statement holds theoretical merit, as it is indeed possible to
optimize away the memory access by keeping variable pid in a register.
However, gcc -S produces this assembly code:

run_script:
pushl %ebp
movl %esp, %ebp
subl $40, %esp
call fork
movl %eax, -4(%ebp)
cmpl $0, -4(%ebp)
jns .L2
movl $-1, -20(%ebp)
jmp .L4
..L2:
cmpl $0, -4(%ebp)
jne .L5
movl $0, 8(%esp)
movl $.LC0, 4(%esp)
movl $.LC1, (%esp)
call execl
movl $1, (%esp)
call exit
..L5:
movl $0, -20(%ebp)
..L4:
movl -20(%ebp), %eax
leave
ret

You can see right after the "call fork" that the contents of eax (return
register) are stored 4 bytes under the base pointer, i.e. on the stack.
I don't have access to a Minix box right here, but I would be highly
surprised if ACK does this optimization when GCC does not. So, it could be
done, but you'd need compiler support for it. I still say we go for the
paging, if we're going to do anything

Regards,

Jens

--
Jens de Smit
Student Computer Science | Vrije Universiteit Amsterdam
jfdsmit@few.vu.nl | http://www.few.vu.nl/~jfdsmit
"[In the end, people] get furious at IT that the goddamn magic isn't working"
-- Stewart Dean
Reply With Quote