Re: bug in xtime.h

2019-12-25 Thread Akim Demaille
Hi friends, > Le 22 déc. 2019 à 21:48, Paul Eggert a écrit : > > On 12/22/19 3:31 AM, Bruno Haible wrote: > >> diff --git a/lib/xtime.h b/lib/xtime.h >> index 77f1c30..5e0ae89 100644 >> --- a/lib/xtime.h >> +++ b/lib/xtime.h >> @@ -42,12 +42,13 @@ extern "C" { >> XTIME_INLINE xtime_t >> xtime_m

Re: bug in xtime.h

2019-12-24 Thread Paul Eggert
On 12/24/19 1:34 AM, Bruno Haible wrote: >> - (corr_quad + (corr_quad < 0)) / 25 - (corr_quad < 0) > Shouldn't that be parenthesized differently? > >- ((corr_quad + (corr_quad < 0)) / 25 - (corr_quad < 0)) Right you are. Thanks, I fixed that. I very much doubt whether

Re: bug in xtime.h

2019-12-24 Thread Bruno Haible
Paul Eggert wrote: > the remaining patches are for other instances of this idiom in Gnulib. These other instances use 'int', not 'long long'. The machine code is similar: === int sec1 (int t) { return (t < 0 ? (t + 1) / 1

Re: bug in xtime.h

2019-12-23 Thread Paul Eggert
On 12/23/19 12:38 AM, Bruno Haible wrote: > => I'm in favour of installing your new formula. Sure, I installed the attached. The first patch is for xtime.h, the remaining patches are for other instances of this idiom in Gnulib. >From 6ad341ee4a0cca1a8b1744bc269282aafd765868 Mon Sep 17 00:00:00 200

Re: bug in xtime.h

2019-12-23 Thread Bruno Haible
Hi Paul, Now you got me hooked :) > the following > code should be faster than the other options mentioned, as it should avoid > both > conditional branches and compilers' overoptimizations. > > return (t + (t < 0)) / 10 - (t < 0); The assembly code indeed shows no conditional jump a

Re: bug in xtime.h

2019-12-22 Thread Paul Eggert
Right you are; I should have measured. Though if speed's the deal, the following code should be faster than the other options mentioned, as it should avoid both conditional branches and compilers' overoptimizations. return (t + (t < 0)) / 10 - (t < 0);

Re: bug in xtime.h

2019-12-22 Thread Bruno Haible
Hi Paul, > > xtime_sec (xtime_t t) > > { > >return (t < 0 > > - ? (t + XTIME_PRECISION - 1) / XTIME_PRECISION - 1 > > + ? (t + 1) / XTIME_PRECISION - 1 > >: xtime_nonnegative_sec (t)); > > Thanks for pointing out the bug. We can simplify the fix further (and sp

Re: bug in xtime.h

2019-12-22 Thread Bruno Haible
Hi Paul, > > diff --git a/lib/xtime.h b/lib/xtime.h > > index 77f1c30..5e0ae89 100644 > > --- a/lib/xtime.h > > +++ b/lib/xtime.h > > @@ -42,12 +42,13 @@ extern "C" { > > XTIME_INLINE xtime_t > > xtime_make (xtime_t s, long int ns) > > { > > - const long int giga = 1000 * 1000 * 1000; > > - s

Re: bug in xtime.h

2019-12-22 Thread Paul Eggert
On 12/22/19 3:31 AM, Bruno Haible wrote: > diff --git a/lib/xtime.h b/lib/xtime.h > index 77f1c30..5e0ae89 100644 > --- a/lib/xtime.h > +++ b/lib/xtime.h > @@ -42,12 +42,13 @@ extern "C" { > XTIME_INLINE xtime_t > xtime_make (xtime_t s, long int ns) > { > - const long int giga = 1000 * 1000 *

bug in xtime.h

2019-12-22 Thread Bruno Haible
Hi Paul, This formula in xtime.h caught my attention: xtime_sec (xtime_t t) { return (t < 0 ? (t + XTIME_PRECISION - 1) / XTIME_PRECISION - 1 : xtime_nonnegative_sec (t)); } Let's look at its behaviour for t < 0. It looks wrong for two reasons: 1) This function is suppos