[PATCH] strftime: support %q to output the quarter of year

Paul Eggert eggert@cs.ucla.edu
Fri Nov 4 04:12:00 GMT 2016


Pádraig Brady wrote:

> +          DO_NUMBER (1, tp->tm_mon / 3 + 1);

I couldn't resist puzzling this one out. We can assume 0 <= tp->tm_mon < 12, so 
this should be a tad more efficient:

    DO_NUMBER (1, ((tp->tm_mon * 11) >> 5) + 1);

With gcc 6.2.0 -O2 x86-64, the former uses imull with 6 insns, the latter just 
leal with 4 insns. Perhaps GCC should be smart enough to figure this out on its 
own, but what would be the fun of that?



More information about the Libc-alpha mailing list