This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC Optimisation status update


On Tue, Jun 14, 2011 at 03:13:00PM +0300, Dimitrios Apostolou wrote:
> parsing overhead and the hex conversion (implemented suboptimally in

Can you back that up?  glibc conversion to hex representation is fairly
heavily optimized, see _itoa_word in stdio-common/_itoa.h.  In fact, I'd
say it is much better than your implementation.  The overhead
you may see almost certainly comes from the fact that printf family
have to handle lots of different stuff, including narrow/wide output,
optional groupping, localized digits and all kinds of other things.

> glibc) I changed the hottest callers with fwrite()/fputs() and
> implemented a puthexl() function for hex conversion:
> 
> static void puthexl (unsigned long value, FILE *f)
> {
>   static char hex_repr[16]= {'0', '1', '2', '3', '4', '5', '6', '7',
> 			     '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
>   static char buf[2 + 2*sizeof(value)]= "0x";
>   int i;
>   int j= 2;
> 
>   for (i = 8*sizeof(value)-4; i>=0; i-= 4)
>     {
>       char c= (value >> i) & 0xf;
>       if (c!=0 || j>2)
> 	{
> 	  buf[j]= hex_repr[(int)c];

Why not just "0123456789abcdef"[c] instead (and make c an int,
instead of char).  Furthermore, consider instead of filling from the beginning
filling from the end.  buf shouldn't be static.
Hardcoding CHAR_BIT to 8 is not portable.

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]