restrict-qualifier

What is the syntax for using the restrict keyword for a 2d array function parameter?

喜夏-厌秋 提交于 2020-07-16 08:21:12
问题 I have an array declared in my main function: float A[n][n]; My goal is to pass it to a function with the restrict keyword: void func(int n, float restrict A[][n]) I tried the syntax above, but I am not getting the optimization in running time that I am expecting. I have also seen this syntax for 1d arrays: void func(int n, float A[restrict]) 回答1: The pointer can be restrict. All below forms are equivalent: void func(int n, float A[restrict n][n]); void func(int n, float A[restrict][n]); void

What is the syntax for using the restrict keyword for a 2d array function parameter?

折月煮酒 提交于 2020-07-16 08:21:08
问题 I have an array declared in my main function: float A[n][n]; My goal is to pass it to a function with the restrict keyword: void func(int n, float restrict A[][n]) I tried the syntax above, but I am not getting the optimization in running time that I am expecting. I have also seen this syntax for 1d arrays: void func(int n, float A[restrict]) 回答1: The pointer can be restrict. All below forms are equivalent: void func(int n, float A[restrict n][n]); void func(int n, float A[restrict][n]); void

Combining __restrict__ and __attribute__((aligned(32)))

允我心安 提交于 2020-03-26 04:29:25
问题 I want to ensure that gcc knows: The pointers refer to non-overlapping chunks of memory The pointers have 32 byte alignments Is the following the correct? template<typename T, typename T2> void f(const T* __restrict__ __attribute__((aligned(32))) x, T2* __restrict__ __attribute__((aligned(32))) out) {} Thanks. Update: I try to use one read and lots of write to saturate the cpu ports for writing. I hope that would make the performance gain by aligned moves more significant. But the assembly

Can I `__restrict__ this` somehow?

三世轮回 提交于 2020-01-11 11:34:11
问题 I've been watching Mike Acton's talk on Data-oriented design in C++ in CppCon 2014, and he gives this example: int Foo::Bar(int count) { int value = 0; for (int i = 0; i < count; i++) { if (m_someDataMemberOfFoo) value++ } return value; } And explains how some compilers keep re-reading m_someDataMemberOfFoo in every iteration, perhaps because its value might change due to concurrent access. Regardless of whether it's appropriate for the compiler to do so - can one tell the compiler to

C/C++ __restrict type

本秂侑毒 提交于 2020-01-10 18:26:08
问题 Is there a way to define using typedef integral/float type which implies no aliasng? something equivalent to (but primitive construct): template < typename T > struct restrict { T* __restrict data; }; as related question, is it possible to ask gcc what it determines alias/no alias of pointer is? 回答1: As noted in the comments, many newer C++ compilers do support the C99 implementation of the restrict type qualifier. Since restrict is not a reserved keyword in C++, the compilers generally use _

C/C++ __restrict type

拜拜、爱过 提交于 2020-01-10 18:25:14
问题 Is there a way to define using typedef integral/float type which implies no aliasng? something equivalent to (but primitive construct): template < typename T > struct restrict { T* __restrict data; }; as related question, is it possible to ask gcc what it determines alias/no alias of pointer is? 回答1: As noted in the comments, many newer C++ compilers do support the C99 implementation of the restrict type qualifier. Since restrict is not a reserved keyword in C++, the compilers generally use _

Can unsafe type punning be fixed by marking a variable volatile?

泪湿孤枕 提交于 2020-01-02 05:28:11
问题 In zwol's answer to Is it legal to implement inheritance in C by casting pointers between one struct that is a subset of another rather than first member? he gives an example of why a simple typecast between similar structs isn't safe, and in the comments there is a sample environment in which it behaves unexpectedly: compiling the following with gcc on -O2 causes it to print "x=1.000000 some=2.000000" #include <stddef.h> #include <stdio.h> #include <stdlib.h> struct base { double some; char

C++ restrict Semantics

走远了吗. 提交于 2020-01-02 04:50:22
问题 I'm in the process of updating performance critical libraries to use restrict, as implemented in C++11 by g++ and MSVC with the keyword __restrict . This seems to be the most-standard-extension, so I'll use restrict and __restrict interchangeably. restrict is a C99 keyword, but nevertheless compilers have defined important uses for it in C++. This post intends to be a "question" asking about what each C++-specific use is and what it means, followed by a CW answer answering it. Feel free to

__restrict in g++ and MSVC with Array Syntax

随声附和 提交于 2019-12-24 04:41:13
问题 I'm in the process of updating performance critical libraries to use restrict , as implemented in C++11 by g++ and MSVC with the keyword __restrict . There are a lot of routines and functions that look something like: void f(float a[],float b[]); In the above example, f is a routine whose arguments should be restricted. Unfortunately, as far as I can tell, this is impossible while maintaining that syntax. Now, clearly this can be rewritten using pointers as: void f(float*__restrict a,float*_

errors as i use the restrict qualifier

China☆狼群 提交于 2019-12-22 07:05:04
问题 When I compile the following program I get errors : gcc tester.c -o tester tester.c: In function ‘main’: tester.c:7:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ptr_X’ tester.c:7:17: error: ‘ptr_X’ undeclared (first use in this function) tester.c:7:17: note: each undeclared identifier is reported only once for each function it appears in tester.c:10:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ptr_Y’ tester.c:10:17: error: ‘ptr_Y’ undeclared