如何在Linux上内联string.h函数? [英] How to inline string.h function on linux?
问题描述
我想优化一些代码,这样string.h中的所有函数都将被内联。我在x86_64上。
我试过-O3,-minline-all-stringops,当我做nm a.out时,它显示它正在调用glibc版本。
使用gcc -S进行检查,我看到了调用。
我错过了什么? string.h中有几十个#ifdef _SOME_SETTING_,而bits / string3.h显示了内联版本,但我不知道如何到达那里。
for例如:
$ cat test.c
#include< string.h>
main(){
char * a,* b;
strcpy(b,a);
}
/ *
编译时使用:
gcc -minline-all-stringops -O6 -I。 -S -o test.S test.c
产生:
$ b .file。test.c
.text
.p2align 4 ,, 15
.globl main
.type main,@function
main:
.LFB12:
.cfi_startproc
subq $ 8,%rsp
.cfi_def_cfa_offset 16
xorl%esi,%esi
xorl%edi,%edi
调用strcpy
addq $ 8,%rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE12:
.size main,.- main
.identGCC:(GNU)4.5.1 20100924(Red Hat 4.5.1-4)
.section .note.GNU-stack,,@ progbits
* /
如果函数实现不在头文件和单独的编译单元中,除非您有可以执行LTCG的编译器,否则不能内联。
$ b
听起来你需要自己编写实现。
I want to optimize some code such that all the functions in string.h will be inlined. I'm on x86_64.
I've tried -O3, -minline-all-stringops and when I do "nm a.out" it shows it is calling the glibc version.
Checking with gcc -S, I see the calls.
What am I missing? There are dozens of #ifdef _SOME_SETTING_ in string.h, and bits/string3.h shows the inline version, but I don't know how to get there.
for example:
$ cat test.c
#include <string.h>
main() {
char *a, *b;
strcpy(b,a);
}
/*
When compiled with:
gcc -minline-all-stringops -O6 -I. -S -o test.S test.c
Produces:
.file "test.c"
.text
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB12:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
xorl %esi, %esi
xorl %edi, %edi
call strcpy
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE12:
.size main, .-main
.ident "GCC: (GNU) 4.5.1 20100924 (Red Hat 4.5.1-4)"
.section .note.GNU-stack,"",@progbits
*/
If a function implementation is not in the header file and in a separate compilation unit, it cannot be inlined unless you have a compiler that can do LTCG.
Sounds like you'll need to write the implementation yourself.
这篇关于如何在Linux上内联string.h函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!