Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #32878
| From | Melzzzzz <mel@zzzzz.com> |
|---|---|
| Newsgroups | comp.lang.c++, comp.lang.c |
| Subject | Re: Why compiler is able to vectorize on int but not on unsigned |
| Date | 2014-12-05 11:29 +0100 |
| Organization | albasani.net |
| Message-ID | <20141205112941.0e3ba566@maxa-pc> (permalink) |
| References | (1 earlier) <87a934k4b0.fsf@dpt-info.u-strasbg.fr> <547F52D5.8020900@verizon.net> <8761drjfdq.fsf@dpt-info.u-strasbg.fr> <20141205100724.53b8f315@maxa-pc> <87y4qmigap.fsf@dpt-info.u-strasbg.fr> |
Cross-posted to 2 groups.
On Fri, 05 Dec 2014 10:42:22 +0100
Alain Ketterlin <alain@dpt-info.u-strasbg.fr> wrote:
> Melzzzzz <mel@zzzzz.com> writes:
>
> [...]
> >> Also, in the version of Melzzzzz if the parameters were "real"
> >> plain arrays but the size were passed in as a size_t (instead of
> >> unsigned, as it should I think), the same would happen. (And this
> >> make the cross-posting to comp.lang.c not completely irrelevant.)
> >
> > You are absolutely right. If I change function
> > to:
> > int testNormal(const int* ghs, const int* lhs,size_t sz) {
> > int max = 0;
> > int tempMax;
> > for (unsigned k = 0; k < sz; k++) {
> > tempMax = lhs[k] + ghs[k];
> > if (max < tempMax) {
> > max = tempMax;
> > }
> > }
> > return max;
> > }
> >
> > it *does not* vectorize as well!
> [...]
> > Your explanation fits what happens with the code. It has to do
> > with unsigned is smaller then size_t and can overflow.
>
> Good, we have understood something. BTW, if you are using vectors, you
> can probably keep using size() as the bound, and use a counter of type
> vector<int>::size_type (size_t in C):
>
> for ( vector<int>::size_type k = 0 ; k<ghs.size() ; k++ )
> ....
Yes, that is definitely. Compilers are now able to vectorize.
So for int, it worked because compilers assume undefined behavior
on overflow, but on unsigned, behavior is defined, so
it restricts optimizations?
So moral is that one has to be careful what to use for index variable ;)
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
Why compiler is able to vectorize on int but not on unsigned Melzzzzz <mel@zzzzz.com> - 2014-12-03 11:19 +0100
Re: Why compiler is able to vectorize on int but not on unsigned James Kuyper <jameskuyper@verizon.net> - 2014-12-03 08:02 -0500
Re: Why compiler is able to vectorize on int but not on unsigned jacob navia <jacob@spamsink.net> - 2014-12-03 14:57 +0100
Re: Why compiler is able to vectorize on int but not on unsigned Tim Prince <tprince@computer.org> - 2014-12-03 09:23 -0500
Re: Why compiler is able to vectorize on int but not on unsigned James Kuyper <jameskuyper@verizon.net> - 2014-12-03 10:03 -0500
Re: Why compiler is able to vectorize on int but not on unsigned Victor Bazarov <v.bazarov@comcast.invalid> - 2014-12-03 09:24 -0500
Re: Why compiler is able to vectorize on int but not on unsigned Richard Heathfield <invalid@see.sig.invalid> - 2014-12-03 14:36 +0000
Re: Why compiler is able to vectorize on int but not on unsigned Melzzzzz <mel@zzzzz.com> - 2014-12-03 16:03 +0100
Re: Why compiler is able to vectorize on int but not on unsigned Victor Bazarov <v.bazarov@comcast.invalid> - 2014-12-03 10:27 -0500
Re: Why compiler is able to vectorize on int but not on unsigned Melzzzzz <mel@zzzzz.com> - 2014-12-03 16:43 +0100
Re: Why compiler is able to vectorize on int but not on unsigned red floyd <no.spam@its.invalid> - 2014-12-03 08:59 -0800
Re: Why compiler is able to vectorize on int but not on unsigned Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2014-12-03 18:53 +0100
Re: Why compiler is able to vectorize on int but not on unsigned James Kuyper <jameskuyper@verizon.net> - 2014-12-03 13:13 -0500
Re: Why compiler is able to vectorize on int but not on unsigned Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2014-12-04 22:04 +0100
Re: Why compiler is able to vectorize on int but not on unsigned Melzzzzz <mel@zzzzz.com> - 2014-12-05 10:07 +0100
Re: Why compiler is able to vectorize on int but not on unsigned Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2014-12-05 10:42 +0100
Re: Why compiler is able to vectorize on int but not on unsigned Melzzzzz <mel@zzzzz.com> - 2014-12-05 11:29 +0100
csiph-web