内在的memcmp [英] intrinsic memcmp
问题描述
根据 gcc文档,memcmp不是GCC的内在功能。如果你想在gcc下加速glibc的memcmp,你需要使用文档中定义的低级内在函数。但是,在互联网上搜索时,似乎很多人都觉得memcmp是内置函数。是为一些编译器而不是为其他人吗?
您的链接看起来是针对x86架构特定的内置函数,根据这 memcmp是作为独立于体系结构的gcc实现。
编辑:
用Cygwin编译下面的代码gcc版本3.3.1 for i686,-O2:
#include< stdlib.h>
struct foo {
int a;
int b;
};
$ b $ int func(struct foo * x,struct foo * y)
{
return memcmp(x,y,sizeof(struct foo));
$ b $ p
$ b产生以下输出(注意对memcmp()的调用被转换为一个8字节的repz cmpsb):
0:55 push%ebp
1:b9 08 00 00 00 mov $ 0x8,%ecx
6:89 e5 mov%esp,%ebp
8:fc cld
9:83 ec 08 sub $ 0x8,%esp
c:89 34 24 mov%esi,(%esp)
f:8b 75 08 mov 0x8(%ebp),%esi
12:89 7c 24 04 mov%edi,0x4(%esp)
16:8b 7d 0c mov 0xc(%ebp),%edi
19:f3 a6 repz cmpsb%es:(%edi),%ds:(%esi)
1b:0f 92 c0 setb% al
1e:8b 34 24 mov(%esp),%esi
21:8b 7c 24 04 mov 0x4(%esp),%edi
25:0f 97 c2 seta%dl
28:89 ec mov%ebp,%esp
2a: 5d pop%ebp
2b:28 c2 sub%al,%dl
2d:0f be c2 movsbl%dl,%eax
30:c3 ret
31:90 nop
According to the gcc docs, memcmp is not an intrinsic function of GCC. If you wanted to speed up glibc's memcmp under gcc, you would need to use the lower level intrinsics defined in the docs. However, when searching around the internet, it seems that many people have the impression that memcmp is a builtin function. Is it for some compilers and not for others?
解决方案 Your link appears to be for the x86 architecture-specific built-in functions, according to this memcmp is implemented as an architecture-independent built-in by gcc.
Edit:
Compiling the following code with Cygwin gcc version 3.3.1 for i686, -O2:
#include <stdlib.h>
struct foo {
int a;
int b;
} ;
int func(struct foo *x, struct foo *y)
{
return memcmp(x, y, sizeof (struct foo));
}
Produces the following output (note that the call to memcmp() is converted to an 8-byte "repz cmpsb"):
0: 55 push %ebp
1: b9 08 00 00 00 mov $0x8,%ecx
6: 89 e5 mov %esp,%ebp
8: fc cld
9: 83 ec 08 sub $0x8,%esp
c: 89 34 24 mov %esi,(%esp)
f: 8b 75 08 mov 0x8(%ebp),%esi
12: 89 7c 24 04 mov %edi,0x4(%esp)
16: 8b 7d 0c mov 0xc(%ebp),%edi
19: f3 a6 repz cmpsb %es:(%edi),%ds:(%esi)
1b: 0f 92 c0 setb %al
1e: 8b 34 24 mov (%esp),%esi
21: 8b 7c 24 04 mov 0x4(%esp),%edi
25: 0f 97 c2 seta %dl
28: 89 ec mov %ebp,%esp
2a: 5d pop %ebp
2b: 28 c2 sub %al,%dl
2d: 0f be c2 movsbl %dl,%eax
30: c3 ret
31: 90 nop
这篇关于内在的memcmp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!