memcpy

Nathan Myers ncm-nospam@cantrip.org
Thu Feb 20 02:32:00 GMT 2003


On Wed, Feb 19, 2003 at 04:47:28PM -0800, Richard Henderson wrote:
> [ re: http://gcc.gnu.org/ml/libstdc++/2003-02/msg00056.html ]
> 
> 
> ... our inliner is happy to do constant propagation, but *only* if the
> argument itself is marked constant.  I.e.
> 
>   inline void foo(void * const x, const void * const y, size_t const s)
>   {     memcpy(x, y, s);   }
> 
> instead of
> 
>   inline void foo(void * x, const void * y, size_t s)
>   {     memcpy(x, y, s);   }

Cool!  But why would the optimizer *care* whether s is const, but
not x and y?  Well, we can declare it

  inline void foo(void * const x, const void * const y, size_t s)

if we have to.  But it seems to me the compiler would be freer the 
other way, allowed to clobber the registers that x, y, and s are 
(were) in.

> I don't know if you're allowed to make this change at will 
> though, since it probably affects name mangling?

Constness on value-parameters doesn't affect anything in the interface.  
We're totally free to make this change.

Nathan Myers
ncm-nospam@cantrip.org



More information about the Libstdc++ mailing list