public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Laurent Vivier <lvivier@redhat.com>
Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, drjones@redhat.com,
	thuth@redhat.com, dgibson@redhat.com, pbonzini@redhat.com
Subject: Re: [kvm-unit-tests PATCH] powerpc: Add tests for RTAS
Date: Thu, 3 Mar 2016 17:03:09 +0100	[thread overview]
Message-ID: <20160303160309.GC2354@potion.brq.redhat.com> (raw)
In-Reply-To: <1457008099-29944-1-git-send-email-lvivier@redhat.com>

2016-03-03 13:28+0100, Laurent Vivier:
> By starting with get-time-of-day, set-time-of-day.
> 
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
> 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.

  parent reply	other threads:[~2016-03-03 16:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-03 12:28 [kvm-unit-tests PATCH] powerpc: Add tests for RTAS Laurent Vivier
2016-03-03 12:45 ` Paolo Bonzini
2016-03-03 13:02   ` Laurent Vivier
2016-03-03 16:03 ` Radim Krčmář [this message]
2016-03-03 16:29   ` Paolo Bonzini
2016-03-03 17:09     ` Radim Krčmář
2016-03-03 17:12       ` Paolo Bonzini
2016-03-03 17:17         ` Radim Krčmář
2016-03-03 16:54 ` Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160303160309.GC2354@potion.brq.redhat.com \
    --to=rkrcmar@redhat.com \
    --cc=dgibson@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox