Cooler_

GCC optimize , test INC ,DEC...

Dec 24th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.39 KB | None | 0 0
  1. Teste para ver o uso de DEC e INC
  2.  
  3.  
  4. seguinte code compilei
  5.  
  6. gcc test2.c -o test2
  7. depois
  8. gcc test2.c -o test2 -O3
  9. lembrando http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
  10.  
  11. ---
  12. cooler@coolerlabs:~$ cat test2.c
  13. #include <stdio.h>
  14.  
  15. int
  16. main()
  17. {
  18.  int x=10;
  19.  
  20.  while(x)
  21.  {
  22.   puts("ola");
  23.   x--;
  24.  }
  25.  
  26.  return 0;
  27. }
  28. ---
  29.  
  30. então com "objdump -D test2" olhando o "main()"
  31.  
  32.  
  33. dump do code sem nenhuma otimização, não vi manifestação do DEC nem do INC
  34. acho que o esperado era "DEC" já que usamos "x--".
  35. ---
  36. 080483d4 <main>:
  37.  80483d4:   55                      push   %ebp
  38.  80483d5:   89 e5                   mov    %esp,%ebp
  39.  80483d7:   83 e4 f0                and    $0xfffffff0,%esp
  40.  80483da:   83 ec 20                sub    $0x20,%esp
  41.  80483dd:   c7 44 24 1c 0a 00 00    movl   $0xa,0x1c(%esp)
  42.  80483e4:   00
  43.  80483e5:   eb 11                   jmp    80483f8 <main+0x24>
  44.  80483e7:   c7 04 24 e0 84 04 08    movl   $0x80484e0,(%esp)
  45.  80483ee:   e8 fd fe ff ff          call   80482f0 <puts@plt>
  46.  80483f3:   83 6c 24 1c 01          subl   $0x1,0x1c(%esp)
  47.  80483f8:   83 7c 24 1c 00          cmpl   $0x0,0x1c(%esp)
  48.  80483fd:   75 e8                   jne    80483e7 <main+0x13>
  49.  80483ff:   b8 00 00 00 00          mov    $0x0,%eax
  50.  8048404:   c9                      leave  
  51.  8048405:   c3                      ret    
  52.  8048406:   90                      nop
  53.  8048407:   90                      nop
  54.  8048408:   90                      nop
  55.  8048409:   90                      nop
  56.  804840a:   90                      nop
  57.  804840b:   90                      nop
  58.  804840c:   90                      nop
  59.  804840d:   90                      nop
  60.  804840e:   90                      nop
  61.  804840f:   90                      nop
  62. ---
  63.  
  64.  
  65.  
  66. De cara nota-se loop unrolling, ou seja não vemos CMP nem JMP
  67. chamou o puts() e passou argumento 10vezes... uso do XOR em eax...
  68. ---
  69. 08048320 <main>:
  70.  8048320:   55                      push   %ebp
  71.  8048321:   89 e5                   mov    %esp,%ebp
  72.  8048323:   83 e4 f0                and    $0xfffffff0,%esp
  73.  8048326:   83 ec 10                sub    $0x10,%esp
  74.  8048329:   c7 04 24 30 85 04 08    movl   $0x8048530,(%esp)
  75.  8048330:   e8 bb ff ff ff          call   80482f0 <puts@plt>
  76.  8048335:   c7 04 24 30 85 04 08    movl   $0x8048530,(%esp)
  77.  804833c:   e8 af ff ff ff          call   80482f0 <puts@plt>
  78.  8048341:   c7 04 24 30 85 04 08    movl   $0x8048530,(%esp)
  79.  8048348:   e8 a3 ff ff ff          call   80482f0 <puts@plt>
  80.  804834d:   c7 04 24 30 85 04 08    movl   $0x8048530,(%esp)
  81.  8048354:   e8 97 ff ff ff          call   80482f0 <puts@plt>
  82.  8048359:   c7 04 24 30 85 04 08    movl   $0x8048530,(%esp)
  83.  8048360:   e8 8b ff ff ff          call   80482f0 <puts@plt>
  84.  8048365:   c7 04 24 30 85 04 08    movl   $0x8048530,(%esp)
  85.  804836c:   e8 7f ff ff ff          call   80482f0 <puts@plt>
  86.  8048371:   c7 04 24 30 85 04 08    movl   $0x8048530,(%esp)
  87.  8048378:   e8 73 ff ff ff          call   80482f0 <puts@plt>
  88.  804837d:   c7 04 24 30 85 04 08    movl   $0x8048530,(%esp)
  89.  8048384:   e8 67 ff ff ff          call   80482f0 <puts@plt>
  90.  8048389:   c7 04 24 30 85 04 08    movl   $0x8048530,(%esp)
  91.  8048390:   e8 5b ff ff ff          call   80482f0 <puts@plt>
  92.  8048395:   c7 04 24 30 85 04 08    movl   $0x8048530,(%esp)
  93.  804839c:   e8 4f ff ff ff          call   80482f0 <puts@plt>
  94.  80483a1:   31 c0                   xor    %eax,%eax
  95.  80483a3:   c9                      leave  
  96.  80483a4:   c3                      ret    
  97.  80483a5:   90                      nop
  98.  80483a6:   90                      nop
  99.  80483a7:   90                      nop
  100. ---
Advertisement
Add Comment
Please, Sign In to add comment