Do nvcc, gcc, clang and msvc “respect” the __restrict__ keyword within structs?

随声附和 提交于 2019-12-06 19:50:29
fetherolfjd

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.

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.

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.

Microsoft C++ AMP (with MSVC++ 2015)

__restrict__ on pointers which are struct members is officially unsupported (emphasis mine):

The following are not allowed:

  • Recursion.
  • Variables declared with the volatile keyword.
  • Virtual functions.
  • Pointers to functions.
  • Pointers to member functions.
  • Pointers in structures.
  • Pointers to pointers.
  • goto statements.
  • Labeled statements.
  • try, catch, or throw statements.
  • Global variables.
  • Static variables. Use tile_static Keyword instead.
  • dynamic_cast casts.
  • The typeid operator.
  • asm declarations.
  • Varargs.

Microsoft Visual C++ 2015

In general rather than AMP C++ code, it's much less clear what MSVC supports. We see an example of __restrict__ being used in a union declaration - so not just a modified on a paremeter of a function - but the semantics are different that you would have for use in a struct.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!