Home > Software design >  How to force g to inline STL functions
How to force g to inline STL functions

Time:02-15

Test Code:

#include <array>

int test(const std::array<int, 10> &arr) {
    return arr[9];
}

I want to make arr[0] as efficient as C style array, which means inline STL array [] operator function.

I have checked the generate assembly code:

$ g   --std=c  17  -c test.cpp && objdump -d -C test.o

test.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <test(std::array<int, 10ul> const&)>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 83 ec 10             sub    $0x10,%rsp
   8:   48 89 7d f8             mov    %rdi,0xfffffffffffffff8(%rbp)
   c:   48 8b 45 f8             mov    0xfffffffffffffff8(%rbp),%rax
  10:   be 09 00 00 00          mov    $0x9,%esi
  15:   48 89 c7                mov    %rax,%rdi
  18:   e8 00 00 00 00          callq  1d <test(std::array<int, 10ul> const&) 0x1d>
  1d:   8b 00                   mov    (%rax),           
  • Related