qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3 14/15] qcow2: small math optimization


From: Kevin Wolf
Subject: Re: [Qemu-devel] [PATCH v3 14/15] qcow2: small math optimization
Date: Tue, 23 Aug 2011 17:34:37 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20110707 Thunderbird/5.0

Am 23.08.2011 15:21, schrieb Frediano Ziglio:
> Signed-off-by: Frediano Ziglio <address@hidden>
> ---
>  block/qcow2-refcount.c |    5 +----
>  1 files changed, 1 insertions(+), 4 deletions(-)
> 
> diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
> index 2a915be..0f9a64a 100644
> --- a/block/qcow2-refcount.c
> +++ b/block/qcow2-refcount.c
> @@ -140,10 +140,7 @@ static unsigned int 
> next_refcount_table_size(BDRVQcowState *s,
>  static int in_same_refcount_block(BDRVQcowState *s, uint64_t offset_a,
>      uint64_t offset_b)
>  {
> -    uint64_t block_a = offset_a >> (2 * s->cluster_bits - REFCOUNT_SHIFT);
> -    uint64_t block_b = offset_b >> (2 * s->cluster_bits - REFCOUNT_SHIFT);
> -
> -    return (block_a == block_b);
> +    return ((offset_a ^ offset_b) >> (2 * s->cluster_bits - REFCOUNT_SHIFT)) 
> == 0;
>  }

Depending on whether the compiler is smart enough this will or will not
change performance. However, even if we assume that it's a slight
improvement, this is in a function that is hardly ever run and the
optimisation comes with a high cost in terms of readability.

I wouldn't do this.

Kevin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]