Operand Scan times

Andrew MacLeod amacleod@redhat.com
Fri Oct 19 18:58:00 GMT 2007


Andrew Haley wrote:
> Andrew MacLeod writes:
>  > Rask Ingemann Lambertsen wrote:
>  >  
>  > >> + /* Comparison function for qsort used in operand_build_sort_virtual.  */
>  > >>   
>  > >> ! static int
>  > >> ! operand_build_cmp (const void *p, const void *q)
>  > >>   {
>  > >> !   tree e1 = *((const tree *)p);
>  > >> !   tree e2 = *((const tree *)q);
>  > >> !   unsigned int u1,u2;
>  > >>   
>  > >> +   u1 = get_name_decl (e1);
>  > >> +   u2 = get_name_decl (e2);
>  > >> + 
>  > >> +   /* We want to sort in ascending order.  They can never be equal.  */
>  > >>   #ifdef ENABLE_CHECKING
>  > >> !   gcc_assert (u1 != u2);
>  > >>   #endif
>  > >> !   return (u1 > u2 ? 1 : -1);
>  > >>   }
>  > >>     
>  > >
>  > >    Where does it say that qsort() isn't allowed to to pass p == q or pass a
>  > > pointer to a copy of *p as q (*tmp = *p; operand_build_cmp (p, tmp);)?
>
>  > It doesn't say that anywhere about qsort().  Processing of virtual 
>  > operands should already have removed all duplicates, so the assert is to 
>  > verify that  the same name should never be in the list more than once at 
>  > this point, thus they can never be equal.
>
> I think you're missing the point, Andrew.  A qsort() implementation
> might pass a pointer to the same array element in p and q during
> partitioning.  In that case, u1 == u2.  Your assert is wrong.
>
>   
ah, That would be a pretty lame implementation, comparing the same 
element is a clear waste of time  :-)  Is it actually triggering somewhere?

I'm certainly not attached to the assert, but it is too bad we will have 
to waste cycles on every single call to the comparison function to check 
for the 'equal' case, which by rights should never happen.   More 
ammunition to supply our own qsort or equivilent in GCC I think so we 
can count on certain things.

Andrew



More information about the Gcc-patches mailing list