From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2881 invoked from network); 28 Feb 2021 17:25:00 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 28 Feb 2021 17:25:00 -0000 Received: (qmail 20074 invoked by uid 550); 28 Feb 2021 17:24:58 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 20056 invoked from network); 28 Feb 2021 17:24:58 -0000 X-Virus-Scanned: by amavisd-new at kth.se X-KTH-Auth: maandree [2001:1ba8:120c:d700:5e2a:93e6:8546:53b5] DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kth.se; s=default; t=1614533086; bh=1+4MXj+QGMQXj8WSEvvX+UQqi7tNZH6xu60yPAcFGhA=; h=Date:From:To:Subject:In-Reply-To:References; b=Dl3GHfVsjZ9T50AcvDWtIyqA9d7sIYw+7aYRhZnMKRgLR+/l5a69aD9rZrFPq+niP u8DKkLy4jH+vnSiPFo4c7Jiim7rIaQt9HRmqkoCK0AZ8lftNudpF4yOpAKzX9EyrCo 5msTfvpzhwFqgTaDISxKD/wtPpKZhoi7TvMeM1uE= X-KTH-mail-from: maandree@kth.se X-KTH-rcpt-to: musl@lists.openwall.com Date: Sun, 28 Feb 2021 18:24:45 +0100 From: Mattias =?UTF-8?B?QW5kcsOpZQ==?= To: musl@lists.openwall.com Message-ID: <20210228182445.66f1de08.maandree@kth.se> In-Reply-To: <20210228170614.GF32655@brightrain.aerifal.cx> References: <20210228150912.1532943-1-maandree@kth.se> <20210228170614.GF32655@brightrain.aerifal.cx> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Awesomeness: 120 % User-Agent: Claws Mail X-Operating-System: GNU/Linux X-Clacks-Overhead: GNU Terry Pratchett MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [musl] [PATCH] Remove unnecessary if in __secs_to_tm On Sun, 28 Feb 2021 12:06:15 -0500 Rich Felker wrote: > On Sun, Feb 28, 2021 at 04:09:12PM +0100, Mattias Andr=C3=A9e wrote: > > Since years divisible by 100 but not by 400 are not leap years, > > q_cycles can at most be 24 (DAYS_PER_100Y / DAYS_PER_4Y =3D=3D 24). > > --- > > src/time/__secs_to_tm.c | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) > >=20 > > diff --git a/src/time/__secs_to_tm.c b/src/time/__secs_to_tm.c > > index 093d9021..2d0c0b2c 100644 > > --- a/src/time/__secs_to_tm.c > > +++ b/src/time/__secs_to_tm.c > > @@ -44,8 +44,7 @@ int __secs_to_tm(long long t, struct tm *tm) > > remdays -=3D c_cycles * DAYS_PER_100Y; > > =20 > > q_cycles =3D remdays / DAYS_PER_4Y; > > - if (q_cycles =3D=3D 25) q_cycles--; > > - remdays -=3D q_cycles * DAYS_PER_4Y; > > + remdays %=3D DAYS_PER_4Y; > > =20 > > remyears =3D remdays / 365; > > if (remyears =3D=3D 4) remyears--; =20 >=20 > I think you're right about the condition being impossible -- it looks > like the error in thinking was that, while 400Y and 4Y are strictly > larger than 4*100Y and 4*1Y respectively, 100Y is smaller than 25*4Y. >=20 > However, changing the -=3D to %=3D is not desirable. The point of the -=3D > has nothing to do with the edge case that can't happen; it's to avoid > a modulo operation. Since the divisor is a constant though maybe the > compiler can generate the same code for both, anyway..? >=20 > Rich For x86_64 `remdays %=3D DAYS_PER_4Y` just becomes a move. divmod in int r =3D 52, q; void divmod(void) { q =3D r / 111; r %=3D 111; } becomes movl r(%rip), %eax movl $111, %ecx cltd idivl %ecx movl %eax, q(%rip) movl %edx, r(%rip) ret `remdays -=3D q_cycles * DAYS_PER_4Y;` on the other hand becomes a move, a multiplication, and an addition. divmod in int r =3D 52, q; void divmod(void) { q =3D r / 111; r -=3D q * 111; } becomes movl r(%rip), %eax movl $111, %ecx cltd idivl %ecx movl %eax, q(%rip) imull $-111, %eax, %eax addl r(%rip), %eax movl %eax, r(%rip) ret So I would say %=3D is the better option, at least for x86_64. Of course, if you prefer, I will change it to use -=3D.