GCC C++ 吗?编译器考虑 __restrict - 语句吗?

发布于 2024-09-15 11:33:16 字数 340 浏览 1 评论 0原文

我已经研究了在通过 GCC 编译器编译 C++ 代码时 __restricting 某些指针的影响。

事实证明,不仅运行时保持完全相同,而且可执行文件似乎也没有改变,字节大小与以前完全相同。

我的 GCC 版本是

gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux)

,虽然它在解析时接受这个 C++ 扩展,但在汇编代码时似乎没有考虑它。因此,要么是编译器不知道如何使用此语义信息,要么是完全禁用了处理此信息。

该代码执行大量数字运算,希望将其启用以用于测试目的。你能帮忙吗?

I've have investigating the effect of __restricting certain pointers in a C++-code, when compiling it via the GCC-compiler.

It turned that not only the run-time remains quite the same, but the executable doesn't seem to have changed, the size in bytes is exactly the same as before.

My GCC-version is

gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux)

and although it accepts this C++-extension when parsing, it does not seem to regard it when assembling the code. So there is either a reason, the compiler doesn't know how to use this semantic information, or processing this information is completly disabled.

The code performs a lot of number crunching, it would like to have it enabled for testing purposes. Can you help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看轻我的陪伴 2024-09-22 11:33:23

restrict 限定符基本上是用户帮助编译器执行某些与别名相关的优化的一种方法。仅当这些优化机会已经存在于代码中时它们才会产生影响,因此使用 restrict 只是在编译器之前必须使用“更安全”(非优化)代码生成的情况下启用它们。在其他情况下,restrict 根本没有任何效果。

因此,您在代码中添加了一些 restrict 限定符。但是它们中的任何一个是否在它们真正重要的上下文中使用,即它们实际上给了编译器更多的自由来优化代码?如果没有,您就不应期望代码发生更改。

restrict qualifiers are basically a way for the user to help the compiler to perform certain aliasing-related optimizations. They will only have an effect if these optimization opportunities are already present in the code, so using restrict simply enables them in situations when the compiler previously had to use a "safer" (non-optimizing) code generation. In other contexts restrict will have no effect at all.

So, you added some restrict qualifiers to your code. But was any of them used in the context where they actually matter, i.e. where they actually give the compiler more freedom to optimize the code? If not, you are not supposed to expect your code to change.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文