Skip to content

Commit

Permalink
vhdx: Simplify vhdx_set_shift_bits()
Browse files Browse the repository at this point in the history
For values which are powers of two (and we do assume all of these to
be), sizeof(x) * 8 - 1 - clz(x) == ctz(x). Therefore, use ctz().

Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 1450451066-13335-3-git-send-email-mreitz@redhat.com
Signed-off-by: Jeff Cody <jcody@redhat.com>
  • Loading branch information
XanClic authored and codyprime committed Feb 29, 2016
1 parent 939901d commit 04a3615
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions block/vhdx.c
Expand Up @@ -264,10 +264,10 @@ static void vhdx_region_unregister_all(BDRVVHDXState *s)

static void vhdx_set_shift_bits(BDRVVHDXState *s)
{
s->logical_sector_size_bits = 31 - clz32(s->logical_sector_size);
s->sectors_per_block_bits = 31 - clz32(s->sectors_per_block);
s->chunk_ratio_bits = 63 - clz64(s->chunk_ratio);
s->block_size_bits = 31 - clz32(s->block_size);
s->logical_sector_size_bits = ctz32(s->logical_sector_size);
s->sectors_per_block_bits = ctz32(s->sectors_per_block);
s->chunk_ratio_bits = ctz64(s->chunk_ratio);
s->block_size_bits = ctz32(s->block_size);
}

/*
Expand Down

0 comments on commit 04a3615

Please sign in to comment.