lkml.org 
[lkml]   [2012]   [Sep]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/4] lib: vsprintf: Optimize division by 10 for small integers.
>> +/* See comment in put_dec_full9 for choice of constants */
>> static noinline_for_stack
>> char *put_dec_full4(char *buf, unsigned q)
>> {
>> unsigned r;
>> - r = (q * 0xcccd) >> 19;
>> + r = (q * 0xccd) >> 15;
>> *buf++ = (q - 10 * r) + '0';
>> - q = (r * 0x199a) >> 16;
>> + q = (r * 0xcd) >> 11;

> I would use 16-bit shifts instead of smaller ones.
> There may be CPUs on which "get upper half of 32-bit reg"
> operation is cheaper or smaller than a shift.

Good point, but wouldn't those CPUs *also* have multi-cycle multiply,
or have to synthesize it out of shift-and-add, in which case smaller
constants would save even more cycles?

I'm thinking original MC68010 here, which I'm not sure is even
meaningful any more. ColdFire has single-cycle shifts.

Can you think of a processor where that would actually be
an improvement?


\
 
 \ /
  Last update: 2012-09-24 14:01    [W:0.176 / U:1.992 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site