restrict-qualifier Questions

5

Solved

Has anyone ever seen any numbers/analysis on whether or not use of the C/C++ restrict keyword in gcc/g++ actual provides any significant performance boost in reality (and not just in theory)? I've...
Impressment asked 27/12, 2009 at 8:4

1

One of the major uses of restrict keyword that was added to C99 is to allow compilers to load something into a register and assume that the register will mirror the state of the variable thus loade...

2

Solved

I am exploring how different implementations of simple loops in C99 auto-vectorize based upon the function signature. Here is my code: /* #define PRAGMA_SIMD _Pragma("simd") */ #define PRAGMA_SIM...

1

Solved

Does the following method respect the "restrict" contract? void fun(int* restrict foo) { int* bar = foo + 32; for (int i = 0; i < 32; ++i) *bar = 0; } My guess is no, but I need some clari...
Protectionism asked 25/10, 2014 at 20:45

2

The whole point of restrict is to promise accesses through one pointer don't alias another. That said, there are examples where overlapping memory addresses wouldn't imply aliasing. For example: i...
Pill asked 19/9, 2014 at 20:0

1

Solved

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 ...
Downhill asked 19/9, 2014 at 19:20

3

Solved

If dot_product is declared as float dot_product(const float* restrict a, const float* restrict b, unsigned n); would calling it with dot_product(x, x, x_len) be "undefined", according to the...
Kropp asked 18/12, 2013 at 9:16

0

I wonder if it is possible to tailor strict aliasing requirements to specifically designed cases, while still preserving strict aliasing in general or -O2/-O3 optimization respectively. To be more...
Misdate asked 6/9, 2013 at 21:46

3

Solved

Are the types of these two declarations compatible types? void f(char *, char *); void f(char *restrict, char *restrict); or similarly: void g(char *); void g(char *const); I'm having a hard ...
Capitalize asked 13/8, 2013 at 17:38

2

Solved

Most definitions of restrict say that it's a promise from the programmer to the compiler that for the lifetime of the pointer, the pointer is the only way that object is accessed. This allows the c...
Heat asked 5/8, 2013 at 13:21

1

Solved

Here is how strtol has to be declared according to § 7.22.1.4 from C11 (n1570): #include <stdlib.h> long int strtol (const char *restrict nptr, char **restrict endptr, int base); As far...
Quicksand asked 14/2, 2013 at 16:39

1

Solved

From C11 draft: C11 (n1570), § K.3.5.1.1 The tmpfile_s function errno_t tmpfile_s(FILE * restrict * restrict streamptr); What is the purpose of the restrict qualifier here? Because there is...
Stacistacia asked 15/12, 2012 at 15:28

2

By using the restrict keyword like this: int f(int* restrict a, int* restrict b); I can instruct the compiler that arrays a and b do not overlap. Say I have a structure: struct s{ (...) int* ip...
Abfarad asked 9/11, 2012 at 11:22

2

Solved

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’ test...
Creath asked 31/10, 2012 at 9:42

2

Solved

I can't see any difference of code by gcc for restrict pointers. file1 void test (int *a, int *b, int *c) { while (*a) { *c++ = *a++ + *b++; } } file2 void test (int *restrict a, int *res...
Palpable asked 1/10, 2012 at 20:16

1

The restrict keyword's behavior is defined in C99 by 6.7.3.1: Let D be a declaration of an ordinary identifier that provides a means of designating an object P as a restrict-qualified pointer t...
Hagiographa asked 4/9, 2012 at 1:19

4

Solved

I came across these two sections in C11 standard referring to the restrict qualifier: 1# 6.7.3-8 An object that is accessed through a restrict-qualified pointer has a special association wi...
Laux asked 31/8, 2012 at 18:23

1

typedef struct { void * field1; } s1; void func1(void) { s1 my_s1; s1 * __restrict my_s1_ptr = &my_s1; *((int*)((char*)my_s1_ptr->field1 + 4)) = 0; *((int*)((char*)my_s1_ptr->field1...

1

Solved

I have tried to use restrict qualified pointers, and I have encountered a problem. The program below is just a simple one only to present the problem. The calc_function uses three pointers, which ...
Discriminant asked 15/7, 2012 at 20:40

2

Solved

Smart pointers are pointers underneath, so is there any way of defining a shared_ptr parameter to a function as not aliasing another shared_ptr, or another pointer of any sort? Or is this, for som...
Leven asked 29/1, 2012 at 0:25

1

Solved

I can see practical use for a const volatile qualified variable, like const volatile uint64_t seconds_since_1970; if an underlying hardware mechanism updates the value every second, but the var...
Exobiology asked 24/1, 2012 at 15:17

3

Solved

i'm doing some code now and got some problem using restrict keyword. typedef int* pt; int foo(pt a, pt b) { ... /* stuff */ } What if I want to make a and b restricted? The code below failed: ...
Computerize asked 13/11, 2010 at 23:38

2

Solved

Suppose I have large array which I calculate an index into and pass to a second function. As a simple example, something like: void foo(float* array, float c, unsigned int n) { for (unsigned int ...
Inculpable asked 4/10, 2010 at 16:19

2

Solved

I'm a little confused about the rules regarding restricted pointers. Maybe someone out there can help me out. Is it legal to define nested restricted pointers as follows: int* restrict a; int* r...
Northward asked 27/9, 2010 at 3:31

1

Solved

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* __restri...
Rosemaryrosemond asked 1/5, 2010 at 3:51

© 2022 - 2024 — McMap. All rights reserved.