From 532d4a24e2013262dfa41fd85c06a9715c99abf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 24 Oct 2022 21:03:42 +0200 Subject: New upstream version 4.7 --- src/tc-time.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'src/tc-time.c') diff --git a/src/tc-time.c b/src/tc-time.c index e842e77..e86ed67 100644 --- a/src/tc-time.c +++ b/src/tc-time.c @@ -5,6 +5,7 @@ * modify it under the terms of the WTF Public License version 2 or * (at your option) any later version. */ +#include #include #include #include @@ -36,10 +37,12 @@ static const struct timespec pairs[] = { }; /* - * Variant that uses full 64 bit division and is thus slower on - * a handful of hardware. + * The playing fields it not level at all! + * HX_timespec_add_DIVQ benefits from inlining and near jumps, + * while HX_timespec_add has to go via PLT, and also has the PIC tax. + * It is actually worse by 7% on i7-8250U/-m64. */ -static struct timespec *HX_timespec_add_FDIV(struct timespec *r, +static struct timespec *HX_timespec_add_DIVQ(struct timespec *r, const struct timespec *a, const struct timespec *b) { long long p, q; @@ -105,6 +108,20 @@ HX_timespec_mulf_S(struct timespec *r, const struct timespec *a, double f) return r; } +static void test_basic(void) +{ + struct timeval a = {1, 769298}, b = {2, 430520}, c; + struct timespec p = {1, 769298000}, q = {2, 430520000}, r; + HX_timeval_sub(&c, &b, &a); + HX_timespec_sub(&r, &q, &p); + printf(HX_TIMEVAL_FMT "\n", HX_TIMEVAL_EXP(&c)); + printf(HX_TIMESPEC_FMT "\n", HX_TIMESPEC_EXP(&r)); + assert(c.tv_sec == 0); + assert(c.tv_usec == 661222); + assert(r.tv_sec == 0); + assert(r.tv_nsec == 661222000); +} + static void test_same(void) { static const struct timespec zero = {0, 0}; @@ -205,9 +222,9 @@ static void test_add(void) for (a = pairs; a < pairs + ARRAY_SIZE(pairs); ++a) { for (b = pairs; b < pairs + ARRAY_SIZE(pairs); ++b) { HX_timespec_add(&r, a, b); - print_op2(&r, a, "+N", b); - HX_timespec_add_FDIV(&s, a, b); - print_op2(&r, a, "+F", b); + print_op2(&r, a, "+L", b); + HX_timespec_add_DIVQ(&s, a, b); + print_op2(&r, a, "+Q", b); if (r.tv_sec != s.tv_sec || r.tv_nsec != s.tv_nsec) abort(); HX_timespec_sub(&r, a, b); @@ -288,7 +305,7 @@ static void test_adds(void) { printf("# Test addition speed\n"); test_adds_1("normal: ", HX_timespec_add); - test_adds_1("fulldiv: ", HX_timespec_add_FDIV); + test_adds_1("div64: ", HX_timespec_add_DIVQ); printf("\n"); } @@ -335,11 +352,10 @@ static void test_mul(void) static void test_muls_1i(const char *text, mul_func_t fn) { struct timespec r, s, start, delta; - unsigned int i; printf("%s", text); clock_gettime(clock_id, &start); - for (i = 0; i < step_mul; ++i) { + for (time_t i = 0; i < step_mul; ++i) { r.tv_sec = -i; r.tv_nsec = -i / 4; (*fn)(&s, &r, 7); @@ -352,11 +368,10 @@ static void test_muls_1i(const char *text, mul_func_t fn) static void test_muls_1f(const char *text, mulf_func_t fn) { struct timespec r, s, start, delta; - unsigned int i; printf("%s", text); clock_gettime(clock_id, &start); - for (i = 0; i < step_mul; ++i) { + for (time_t i = 0; i < step_mul; ++i) { r.tv_sec = -i; r.tv_nsec = -i / 4; (*fn)(&s, &r, 7); @@ -382,6 +397,7 @@ int main(void) if (HX_init() <= 0) abort(); + test_basic(); test_same(); test_neg(); test_add(); -- cgit v1.2.3 From bfef0924f58eab930bdd826ac0132786abc32220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 29 Jan 2023 16:17:51 +0100 Subject: New upstream version 4.10 --- src/tc-time.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/tc-time.c') diff --git a/src/tc-time.c b/src/tc-time.c index e86ed67..5097cde 100644 --- a/src/tc-time.c +++ b/src/tc-time.c @@ -1,10 +1,4 @@ -/* - * Copyright Jan Engelhardt, 2012 - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the WTF Public License version 2 or - * (at your option) any later version. - */ +// SPDX-License-Identifier: MIT #include #include #include @@ -27,7 +21,7 @@ static const int NANOSECOND = 1000000000; static const long long NANOSECOND_LL = 1000000000; static const unsigned int clock_id = CLOCK_THREAD_CPUTIME_ID; static const unsigned int step = 1000; -static const unsigned int step_mul = 10000000; +static const long step_mul = 10000000; static const struct timespec pairs[] = { {-1, 700000000}, {-1, 400000000}, {-1, 0}, -- cgit v1.2.3