Do nvcc,gcc,clang和msvc“respect” struct中的__restrict__关键字? [英] Do nvcc, gcc, clang and msvc "respect" the __restrict__ keyword within structs?

查看:293
本文介绍了Do nvcc,gcc,clang和msvc“respect” struct中的__restrict__关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有

struct s {
    int* __restrict__ p1;
    double v;
};

void foo(int* __restrict__ p2, struct s my_s) { /* ... */ }

下面列出的C ++编译器在这种情况下关注 __ restrict __ 关键字,并假设通过 p2 不能影响通过 p1 的访问?显然这是编译器依赖的,因为 restrict 不是一个C ++关键字。

Do the C++ compilers listed below respect the __restrict__ keywords in this case, and assume memory accesses through p2 cannot affect accesses through p1? Obviously this is compiler-dependent, since restrict is not a C++ keyword.

回答gcc 4.9.x和nVIDIA CUDA 7.5的nvcc(当编译设备代码时,当然,而不是当转发到主机编译器)。有关当前版本的clang,gcc和msvc ++的解答也很有趣。

I'm mainly interested in the answer for gcc 4.9.x and nVIDIA CUDA 7.5's nvcc (when compiling device code of course, not when forwarding to a host compiler). An answer regarding current versions of clang, gcc and msvc++ would also be interesting.

推荐答案

GCC 似乎表明是的,但我想象下,所有人都在脑海里关于这些类型的事情,并可能完全忽略关键字存在的事实。

GCC seems to indicate yes, but I would imagine under the hood it's being all brainy about these types of things and may completely ignore the fact that the keyword is present.

我也愿意打赌,如果您使用和不使用restrict关键字分析方法,没有什么区别。

I'd also be willing to bet that if you profile your method with and without the restrict keywords, there'd be little to no difference.

如果你这样做,我很想知道结果。

If you do this I'd love to know the results.

回答,可能有趣的阅读。

There's also this answer which may be interesting to read.

最后,还有博客似乎表明nvcc支持关键字。

Lastly, there's this blog which seems to indicate the nvcc supports the keyword.

现在我真的很好奇的分析你的代码的结果。

Now I'm really curious about the results of profiling your code.

这篇关于Do nvcc,gcc,clang和msvc“respect” struct中的__restrict__关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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