This is the mail archive of the
mailing list for the glibc project.
Re: [PATCH] strftime: support %q to output the quarter of year
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?