C ++ method sizing

I have a .cpp file with various methods:

// test.cpp

// foo() is not inlined
void foo() {
  ...
}

I will compile it:

g++ test.cpp -o test.o -S

And now I want to determine, from consideration test.o, how many bytes of memory an instruction takes foo(). How can i do this?

I ask, because through careful profiling and experimentation, I decided that I had team cache failures, which led to significant slowdowns on some critical paths. Therefore, I would like to understand how many bytes are occupied by various methods to direct my efforts to reduce the size of the instruction set.

+4
source share
2 answers

-S , ISA . , :

$ cc -c example.c 
$ objdump -d example.o 

example.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <f>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   89 7d fc                mov    %edi,-0x4(%rbp)
   7:   8b 45 fc                mov    -0x4(%rbp),%eax
   a:   83 c0 03                add    $0x3,%eax
   d:   5d                      pop    %rbp
   e:   c3                      retq   

, 15 .

+4

, . - , .

g++ :

-Xlinker -Map=MyProject.txt
+4

All Articles