From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126084 invoked by alias); 4 Dec 2018 09:03:30 -0000 Mailing-List: contact newlib-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-cvs-owner@sourceware.org Received: (qmail 126066 invoked by uid 10080); 4 Dec 2018 09:03:29 -0000 Date: Tue, 04 Dec 2018 09:03:00 -0000 Message-ID: <20181204090329.126064.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Sebastian Huber To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] When converting ns,us,ms to sbt, return the ceil() X-Act-Checkin: newlib-cygwin X-Git-Author: imp X-Git-Refname: refs/heads/master X-Git-Oldrev: 68b1d72e1d966064e15ad40faf8dfd2d99438ca3 X-Git-Newrev: 7bf8fc0987838fc435e251183410ed16bfb36c95 X-SW-Source: 2018-q4/txt/msg00037.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7bf8fc0987838fc435e251183410ed16bfb36c95 commit 7bf8fc0987838fc435e251183410ed16bfb36c95 Author: imp Date: Thu Nov 15 16:02:13 2018 +0000 When converting ns,us,ms to sbt, return the ceil() of the result rather than the floor(). Returning the floor means that sbttoX(Xtosbt(y)) != y for almost all values of y. In practice, this results in a difference of at most 1 in the lsb of the sbintime_t. This difference is meaningless for all current users of these functions, but is important for the newly introduced sysctl conversion routines which implicitly rely on the transformation being idempotent. Sponsored by: Netflix, Inc Diff: --- newlib/libc/include/sys/time.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/newlib/libc/include/sys/time.h b/newlib/libc/include/sys/time.h index e5023ae..5182dc1 100644 --- a/newlib/libc/include/sys/time.h +++ b/newlib/libc/include/sys/time.h @@ -171,6 +171,10 @@ sbttobt(sbintime_t _sbt) * Decimal<->sbt conversions. Multiplying or dividing by SBT_1NS results in * large roundoff errors which sbttons() and nstosbt() avoid. Millisecond and * microsecond functions are also provided for completeness. + * + * These functions return the smallest sbt larger or equal to the number of + * seconds requested so that sbttoX(Xtosbt(y)) == y. The 1 << 32 - 1 term added + * transforms the >> 32 from floor() to ceil(). */ static __inline int64_t sbttons(sbintime_t _sbt) @@ -183,7 +187,7 @@ static __inline sbintime_t nstosbt(int64_t _ns) { - return ((_ns * (((uint64_t)1 << 63) / 500000000)) >> 32); + return ((_ns * (((uint64_t)1 << 63) / 500000000) + (1ull << 32) - 1) >> 32); } static __inline int64_t @@ -197,7 +201,7 @@ static __inline sbintime_t ustosbt(int64_t _us) { - return ((_us * (((uint64_t)1 << 63) / 500000)) >> 32); + return ((_us * (((uint64_t)1 << 63) / 500000) + (1ull << 32) - 1) >> 32); } static __inline int64_t @@ -211,7 +215,7 @@ static __inline sbintime_t mstosbt(int64_t _ms) { - return ((_ms * (((uint64_t)1 << 63) / 500)) >> 32); + return ((_ms * (((uint64_t)1 << 63) / 500) + (1ull << 32) - 1) >> 32); } /*-