From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Date: Thu, 03 Mar 2016 16:29:30 +0000 Subject: Re: [kvm-unit-tests PATCH] powerpc: Add tests for RTAS Message-Id: <56D8666A.40508@redhat.com> List-Id: References: <1457008099-29944-1-git-send-email-lvivier@redhat.com> <20160303160309.GC2354@potion.brq.redhat.com> In-Reply-To: <20160303160309.GC2354@potion.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Laurent Vivier Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, drjones@redhat.com, thuth@redhat.com, dgibson@redhat.com On 03/03/2016 17:03, Radim Krčmář wrote: >> > 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? Even the Gregorian calendar only starts in 1583 though. :) This is just a utility function for mktime. I think it's okay. We should aim at making libcflat a minimal libc, and in that case we would move mktime to lib/. Putting stuff directly in tests is good enough (worse is better), but let's remember that duplicated code is not. Paolo > 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);