From mboxrd@z Thu Jan 1 00:00:00 1970 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Subject: Re: [kvm-unit-tests PATCH] powerpc: Add tests for RTAS Date: Thu, 3 Mar 2016 17:03:09 +0100 Message-ID: <20160303160309.GC2354@potion.brq.redhat.com> References: <1457008099-29944-1-git-send-email-lvivier@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, drjones@redhat.com, thuth@redhat.com, dgibson@redhat.com, pbonzini@redhat.com To: Laurent Vivier Return-path: Received: from mx1.redhat.com ([209.132.183.28]:53202 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751272AbcCCQDS (ORCPT ); Thu, 3 Mar 2016 11:03:18 -0500 Content-Disposition: inline In-Reply-To: <1457008099-29944-1-git-send-email-lvivier@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 2016-03-03 13:28+0100, Laurent Vivier: > By starting with get-time-of-day, set-time-of-day. > > Signed-off-by: Laurent Vivier > --- > diff --git a/powerpc/rtas.c b/powerpc/rtas.c > +#define DAYS(y,m,d) (365UL * (y) + ((y) / 4) - ((y) / 100) + ((y) / 400) + \ > + 367UL * (m) / 12 + \ > + (d)) This function is hard to (re)use. What about putting the "month -= 2" block together with DAYS to give a better estimate of the amount of days in the gregorian calendar? static inline unsigned long days(int year, int month, int day) { month -= 2; if (month <= 0) { month += 12; year -= 1; } return DAYS(year, month, day); } (Or replacing it with an obvious, but slower/bigger implementation? :]) > + /* Put February at end of the year to avoid leap day this year */ > + > + month -= 2; > + if (month <= 0) { > + month += 12; > + year -= 1; > + } > + > + /* compute epoch: substract DAYS(since_March(1-1-1970)) */ > + > + epoch = DAYS(year, month, day) - DAYS(1969, 11, 1); You'd then be able to write epoch = days(year, month, day) - days(1970, 1, 1); instead of the obscure chunk of code.