ghaerr / elks

Embeddable Linux Kernel Subset - Linux for 8086
Other
999 stars 108 forks source link

[libc] Rewrite vfprintf.c and tiny_printf.c to use __divmod for speed #2012

Closed ghaerr closed 2 weeks ago

ghaerr commented 2 weeks ago

More in a series of speeding up numeric-to-string conversions in the C library. This PR adds the fast __divmod calculation to vfprintf/sprintf/printf.c and tiny_printf.c.

Although few on faster systems are likely to notice speed improvements, those with 8086/8088 CPUs may start to see a difference when running ANSI sequence intensive terminal applications like sl, ttyclock, matrix and the like. This is because for every cursor position as well as any color sequence, a number has to get converted to a string through these routines, and then converted back to the same number by the ANSI console driver. It wasn't realized until recently how much time these conversions were taking on systems with very slow DIV instructions - all 8086/8088s and early CPUs.

The ANSI console speedups are coming next, then it might be worth measuring any speedups. @Vutshi, hopefully this will help your older system run sl and ttyclock much quicker than before, but we will see!