You are not logged in.

#1 2008-09-09 07:56:57

neok
Member
From: Cyprus
Registered: 2003-12-14
Posts: 190
Website

Need more info on __restrict

Hi,

I am currently working on a firewire video camera project and while comparing some functions that convert raw Bayer to RGB, I found that those who use the following construct:

void Bayer_to_RGB8( video_buffer_t *source, video_buffer_t *display )
{
  unsigned char *restrict bayer = source->buffer;
  unsigned char *restrict rgb = display->buffer;
  ......
are faster by about 15%+ than those that use source->buffer and display->buffer directly in the code. I looked up the keyword in google but only found some patchy explanations on the use of __restrict.

I would appreciate any info/links to a more detailed explanation on the proper way and place to use it to speed up code.

My thanks in advance.


Regards

Neoklis ... Ham Radio Call: 5B4AZ

Offline

#2 2008-09-12 03:52:25

joe
Member
From: Folsom, CA
Registered: 2004-07-27
Posts: 51
Website

Re: Need more info on __restrict

From what I understand, it makes a guarantee that bayer and rgb don't point to the same memory, so the compiler doesn't have to load rgb every time bayer is stored (modified).

-Joe

Last edited by joe (2008-09-12 03:52:37)

Offline

#3 2008-09-12 07:38:46

gnud
Member
Registered: 2005-11-27
Posts: 182

Re: Need more info on __restrict

'Programming in C' wrote:

Like the `register`modifier, `restrict` is an optimization hint for the compiler. As such, the caompiler can choose to ignore it. It is used to tell the compiler that a particular pointer is the only reference (either direct or indirect) to the value it points to throughout its scope. That is, the same value is not referenced by any other pointer or variable within that scope.

Offline

#4 2008-09-12 10:43:49

neok
Member
From: Cyprus
Registered: 2003-12-14
Posts: 190
Website

Re: Need more info on __restrict

neok wrote:

Hi,

I would appreciate any info/links to a more detailed explanation on the proper way and place to use it to speed up code.

My thanks in advance.

Ahh, my thanks for the replies, I can now possibly use this feature in one or two other programs I have written, to speed them up. Gaining 15-20% extra speed so simply sounds very nice! ;-)


Regards

Neoklis ... Ham Radio Call: 5B4AZ

Offline

Board footer

Powered by FluxBB