>From f29bc5f35e5871452270c742f1784d9422f95c62 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 23 Dec 2019 23:47:37 -0800 Subject: [PATCH 2/4] mktime: tweak division performance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * config/srclist.txt: Do not sync mktime.c for now. * lib/mktime.c (shr, ydhms_diff): Redo with neither ‘%’ nor conditional branches. --- ChangeLog | 5 +++++ config/srclist.txt | 2 +- lib/mktime.c | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f6a705a7a..1f7eb19b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2019-12-23 Paul Eggert + mktime: tweak division performance + * config/srclist.txt: Do not sync mktime.c for now. + * lib/mktime.c (shr, ydhms_diff): + Redo with neither ‘%’ nor conditional branches. + gethrxtime: improve xtime_sec performance Performanced analyzed by Bruno Haible in: https://lists.gnu.org/r/bug-gnulib/2019-12/msg00200.html diff --git a/config/srclist.txt b/config/srclist.txt index 55d574ab3..9a7b9597d 100644 --- a/config/srclist.txt +++ b/config/srclist.txt @@ -59,7 +59,7 @@ $LIBCSRC posix/regex_internal.c lib $LIBCSRC posix/regex_internal.h lib $LIBCSRC posix/regexec.c lib $LIBCSRC time/timegm.c lib -$LIBCSRC time/mktime.c lib +#$LIBCSRC time/mktime.c lib $LIBCSRC time/mktime-internal.h lib # diff --git a/lib/mktime.c b/lib/mktime.c index 11b0d5353..81c9ca1fc 100644 --- a/lib/mktime.c +++ b/lib/mktime.c @@ -141,7 +141,7 @@ shr (long_int a, int b) long_int one = 1; return (-one >> 1 == -1 ? a >> b - : a / (one << b) - (a % (one << b) < 0)); + : (a + (a < 0)) / (one << b) - (a < 0)); } /* Bounds for the intersection of __time64_t and long_int. */ @@ -211,8 +211,8 @@ ydhms_diff (long_int year1, long_int yday1, int hour1, int min1, int sec1, Take care to avoid integer overflow here. */ int a4 = shr (year1, 2) + shr (TM_YEAR_BASE, 2) - ! (year1 & 3); int b4 = shr (year0, 2) + shr (TM_YEAR_BASE, 2) - ! (year0 & 3); - int a100 = a4 / 25 - (a4 % 25 < 0); - int b100 = b4 / 25 - (b4 % 25 < 0); + int a100 = (a4 + (a4 < 0)) / 25 - (a4 < 0); + int b100 = (b4 + (b4 < 0)) / 25 - (b4 < 0); int a400 = shr (a100, 2); int b400 = shr (b100, 2); int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400); -- 2.17.1