当__builtin_memcpy被libc的memcpy替换时 [英] When __builtin_memcpy is replaced with libc's memcpy

查看:659
本文介绍了当__builtin_memcpy被libc的memcpy替换时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GCC中有一个C99 / posix memcpy 函数的版本: __ builtin_memcpy

There is a version of C99/posix memcpy function in GCC: __builtin_memcpy.

有时它可以被GCC替换为memcpy的内联版本,在其他情况下,它被调用libc的memcpy替代。例如。有人指出此处

Sometimes it can be replaced by GCC to inline version of memcpy and in other cases it is replaced by call to libc's memcpy. E.g. it was noted here:


最后,在编译器注意事项中,__builtin_memcpy可以回退到发出memcpy函数调用。

Finally, on a compiler note, __builtin_memcpy can fall back to emitting a memcpy function call.

什么是逻辑在这个选择?在其他gcc兼容的编译器,如clang / llvm,intel c ++编译器,PCC,suncc(oracle studio)中,其逻辑是否相同?

What is the logic in this selection? Is it logic the same in other gcc-compatible compilers, like clang/llvm, intel c++ compiler, PCC, suncc (oracle studio)?

当我更喜欢使用__builtin_memcpy而不是普通的memcpy时?

When I should prefer of using __builtin_memcpy over plain memcpy?

推荐答案

我已用内置的更换前一段时间试验和我发现,在< string.h中> 功能仅更换时的源参数的大小可以是在编译时已知。在这种情况下,对 libc 的调用直接由展开的代码替换。

I had been experimenting with the builtin replacement some time ago and I found out that the <string.h> functions are only replaced when the size of the source argument can be known at compile time. In which case the call to libc is replaced directly by unrolled code.

除非用 -fno-builtins -ansi -std = c89 或类似的东西,你使用 __ builtin _ 前缀还是没有关系。

Unless you compile with -fno-builtins, -ansi, -std=c89 or something similar, it actually doesn't matter wether you use the __builtin_ prefix or not.

虽然很难理解,该deciedes是否发射库调用或代码块的代码似乎是 here

Although it's hard to follow, the code that deciedes whether to emit a library call or a chunk of code seems to be here.

这篇关于当__builtin_memcpy被libc的memcpy替换时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆