[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH V2] [PowerPC][RFC] booke timers
From: |
Fabien Chouteau |
Subject: |
Re: [Qemu-devel] [PATCH V2] [PowerPC][RFC] booke timers |
Date: |
Tue, 05 Jul 2011 18:41:13 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110516 Lightning/1.0b2 Mnenhy/0.8.3 Thunderbird/3.1.10 |
On 05/07/2011 18:02, Scott Wood wrote:
> On Mon, 4 Jul 2011 17:06:54 +0200
> Fabien Chouteau <address@hidden> wrote:
>
>> On 01/07/2011 22:22, Scott Wood wrote:
>>> On Fri, 1 Jul 2011 16:13:41 +0200
>>> Fabien Chouteau <address@hidden> 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));" ?
>
> Yes.
>
> Or more simply:
>
> lapse = period - ((tb - period) & (period - 1));
>
Are you sure? Note that period != (1 << target_bit).
>> I don't see how this solves the "tb <= (1 << target_bit)" case.
>
> Actually, since everything is unsigned the special case shouldn't be needed
> regardless.
You're right about this one, it's tricky though :)
--
Fabien Chouteau