This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: std min error during optimization
- From: TRaj <tryitn1 at gmail dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-help at gcc dot gnu dot org
- Date: Fri, 24 Jul 2009 10:11:16 +0530
- Subject: Re: std min error during optimization
- References: <b74b36da0907232036x6282340bh4c31e34915a7aa80@mail.gmail.com> <b74b36da0907232039me8530e6y75c7ae3f87b02ef9@mail.gmail.com>
The bug is in my code. Someone has pointed out the error. Please
ignore the message.
On Fri, Jul 24, 2009 at 9:09 AM, TRaj<tryitn1@gmail.com> wrote:
> hi,
> ??I'm not subscribed to this list. Please add me to your replies.
> ??i've this code at?http://codepad.org/L1Ko85ff?or below which gives
> different answers 8 and 9 (last line) ?based on optimization (-O2) and
> -O0 on my g++ cygwin (3.4).
>
> When i redefine the min by mymin
> #define mymin(a,b) ((a<b)?(a):(b)) it gives me 8 but when i replace it
> with std:min it gives me 9 ?at -O0 on gcc 4.3.
> Am i doing something wrong in the below code ?
>
> #include<cstdio>
> #include<iostream>
> #include<sstream>
> #include<cmath>
> #include<cstring>
> #include<cstdlib>
> #include<cassert>
> #include<ctime>
> #include<algorithm>
> #include<iterator>
> #include<iostream>
> #include<cctype>
> #include<string>
> #include<vector>
> #include<map>
> #include<set>
> #include<queue>
> #include<list>
> using namespace std;
>
>
>
>
> const int N=7;
> int done[1<<12],gdo2[1<<12];
> const int INF=1000000;
>
> int g(int mask,int lvl){
> ?assert(mask<(1<<N));
>
> ? printf("MASK=%d\n",mask);
>
> ? ? ? ?if(gdo2[mask]) return gdo2[mask];
>
> ? ? ? ?if(lvl==N){
> ? ? ? ? ? ? ? ?if(done[mask]) return INF;
> ? ? ? ? ? ? ? ? return mask;
> ? ? ? ? }
> ? ? ? ? int ans=INF,i;
> ? ? ? ? if(done[mask]==0) ans=mask;
> ? ? ? ?for(i=0;i<N;i++)
> ? ? ? ? ? ? ? ?if((mask&(1<<i))){
> ? ? ? ? ? ? ? ? ? ? ? ?ans=min(ans,min(g(mask^(1<<i) ,lvl+1),g(mask,lvl+1)));
> ? ? ? ? ? ? ? ?}
>
> ? ? ? ?return gdo2[mask]=ans;
>
> }
>
> int main(){
>
> ? ? ? ?done[0]=done[1]=done[3]=done[2]=done[6]=done[4]=done[5]=done[7]=done[15]=1;
>
> ? ? ? ? ? ? cout <<g(15,0)<<endl;
>
> ? ? ? ?return 0;
> }
>