From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5858 invoked by alias); 3 Mar 2008 22:22:17 -0000 Received: (qmail 5846 invoked by uid 22791); 3 Mar 2008 22:22:16 -0000 X-Spam-Check-By: sourceware.org Received: from wr-out-0506.google.com (HELO wr-out-0506.google.com) (64.233.184.226) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 03 Mar 2008 22:21:58 +0000 Received: by wr-out-0506.google.com with SMTP id 60so660841wri.6 for ; Mon, 03 Mar 2008 14:21:56 -0800 (PST) Received: by 10.64.208.20 with SMTP id f20mr400771qbg.63.1204582913928; Mon, 03 Mar 2008 14:21:53 -0800 (PST) Received: by 10.65.213.9 with HTTP; Mon, 3 Mar 2008 14:21:53 -0800 (PST) Message-ID: <7f5fb9860803031421o50bd3405l5764d5f38d4600a5@mail.gmail.com> Date: Mon, 03 Mar 2008 22:22:00 -0000 From: "Carlos Alvarez" To: "Segher Boessenkool" Subject: Re: restricted pointers Cc: gcc-help@gcc.gnu.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <7f5fb9860803010647o52214838qf94bbdc06610c5b5@mail.gmail.com> Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-03/txt/msg00023.txt.bz2 Thank you for your response. I am already compiling with the -O3 option and the -std=c99 option in the case of c. I tried fixing the b[0] element but i obtained the same result. This is important for me because I am making scientific simulation software in c/c++ and I need it to be as fast as possible, and when I learned about the aliasing problem I wanted to know how to overcome it, for which I have to understand when does the problem presents and how to solve it. Would you happen to know any example in which the pointer aliasing problem is present and then can be overcame by restricted pointers in a manner that I can test it? Thank you again for your time, Best regards, Carlos Alvarez On Sun, Mar 2, 2008 at 4:38 PM, Segher Boessenkool wrote: > > void vecmult(int n, int * restrict a, int * restrict b, int * restrict > > c) > > { > > int i; > > for (i=0; i > a[i] = b[i] * c[i]; > > } > > } > > > > but the times with or without restrict are the same. Why isn't it > > improving performance, am I doing something wrong? > > Well, no matter what, the program will have to perform n reads of > elements of b[] and c[], and perform n writes to elements of a[]. > > You could try adding -O3 and/or some of the vectorisation options. > > Also, you could test something like > > > void vecmult(int n, int * restrict a, int * restrict b, int * restrict > c) > { > int i; > for (i=0; i a[i] = b[0] * c[i]; > } > } > > which has a much bigger opportunity for optimisation (no need to load > from b[0] more than once, only if there is a restrict on b[]). > > > Segher > >