From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:42249) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qdkjy-0006nl-F4 for qemu-devel@nongnu.org; Mon, 04 Jul 2011 11:07:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qdkjw-0005gQ-MQ for qemu-devel@nongnu.org; Mon, 04 Jul 2011 11:07:14 -0400 Received: from mel.act-europe.fr ([194.98.77.210]:34816) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qdkjw-0005eZ-35 for qemu-devel@nongnu.org; Mon, 04 Jul 2011 11:07:12 -0400 Message-ID: <4E11D70E.4070808@adacore.com> Date: Mon, 04 Jul 2011 17:06:54 +0200 From: Fabien Chouteau MIME-Version: 1.0 References: <1309529621-27691-1-git-send-email-chouteau@adacore.com> <20110701152244.278e720b@schlenkerla.am.freescale.net> In-Reply-To: <20110701152244.278e720b@schlenkerla.am.freescale.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH V2] [PowerPC][RFC] booke timers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Scott Wood Cc: qemu-devel@nongnu.org On 01/07/2011 22:22, Scott Wood wrote: > On Fri, 1 Jul 2011 16:13:41 +0200 > Fabien Chouteau wrote: >> +static void booke_update_fixed_timer(CPUState *env, >> + uint8_t target_bit, >> + uint64_t *next, >> + struct QEMUTimer *timer) >> +{ >> + ppc_tb_t *tb_env = env->tb_env; >> + uint64_t lapse; >> + uint64_t tb; >> + uint64_t period = 1 << (target_bit + 1); >> + uint64_t now; >> + >> + now = qemu_get_clock_ns(vm_clock); >> + tb = cpu_ppc_get_tb(tb_env, now, tb_env->tb_offset); >> + >> + if (tb <= (1 << target_bit)) { >> + lapse = (1 << target_bit) - tb; >> + } else { >> + lapse = period - ((tb - (1 << target_bit)) % period); > > We know period is a power of two, so just do "& (period - 1)". > > That should let you get rid of the special case for > "tb <= (1 << target_bit)" as well. > Do you mean "lapse = period - ((tb - (1 << target_bit)) & (period - 1));" ? I don't see how this solves the "tb <= (1 << target_bit)" case. -- Fabien Chouteau