restrict keyword use?

Discuss topics related to development here.
Post Reply
User avatar
Narann
Posts: 154
Joined: Mon Jun 16, 2014 4:25 pm
Contact:

restrict keyword use?

Post by Narann » Fri Nov 21, 2014 10:51 am

I just kown about restrict keywork that help compiler to know more about the currently used pointers.

As I know cen64 use a lot of pointers I was wondering if there is some places manipulating pointers where such keyword could improve performance.

User avatar
MarathonMan
Site Admin
Posts: 692
Joined: Fri Oct 04, 2013 4:49 pm

Re: restrict keyword use?

Post by MarathonMan » Sat Nov 22, 2014 12:35 pm

I haven't looked into this yet for two reasons:
  • I haven't found cases in which the use of restrict generates more-optimal assembly.
  • I don't think that MSVC supports it, so it'd need to be macro'd to cen64_restrict.
Feel free to prove it's ability to generate better code, though -- if you can, I'll be more than happy to merge and start using it more aggressively. :D

User avatar
Narann
Posts: 154
Joined: Mon Jun 16, 2014 4:25 pm
Contact:

Re: restrict keyword use?

Post by Narann » Sat Nov 22, 2014 1:59 pm

I think it's another "specialisation" flag: You just specify to the compiler the given pointer will we the only one that will access/modify the given memory adress (or adress+n).

From my perspective it can be considered as another "const correctness like" as doing so, you will also make your code more explicit and avoid future potential memory overwrite.

For gcc it's __restrict__, for Visual C++ it's __restrict.

User avatar
MarathonMan
Site Admin
Posts: 692
Joined: Fri Oct 04, 2013 4:49 pm

Re: restrict keyword use?

Post by MarathonMan » Sat Nov 22, 2014 3:13 pm

Narann wrote:For gcc it's __restrict__, for Visual C++ it's __restrict.
gcc is C99-conformant, so you can just use the standardized restrict keyword.

While I agree that it's "correct", adding restrict to all pointers is a little over the top. I think it is usually common practice to only use the restrict keyword where it could have an impact on the code generated. At least, I have not seen restrict used excessively in any FOSS project that I have stumbled upon...

User avatar
Narann
Posts: 154
Joined: Mon Jun 16, 2014 4:25 pm
Contact:

Re: restrict keyword use?

Post by Narann » Sat Nov 22, 2014 3:44 pm

As you wish. It was FYI. :)

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests