From ab25cb45dcf6997cbab61eee137ee0a7085b118f Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Fri, 17 Feb 2012 01:43:21 +0000 Subject: [PATCH] Micro-optimize scst_calc_block_shift() Replace a loop by a single instruction, namely bsr (bit scan reverse). From the disassembler output of scst_calc_block_shift() on an x86_64 system: 0x0000000000001493 <+35>: bsr %edx,%ecx Signed-off-by: Bart Van Assche git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4134 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 4e06d1c18..d30676f20 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -5377,19 +5377,14 @@ out_err: */ int scst_calc_block_shift(int sector_size) { - int block_shift = 0; - int t; + int block_shift; if (sector_size == 0) sector_size = 512; - t = sector_size; - while (1) { - if ((t & 1) != 0) - break; - t >>= 1; - block_shift++; - } + block_shift = ilog2(sector_size); + WARN_ON(1 << block_shift != sector_size); + if (block_shift < 9) { PRINT_ERROR("Wrong sector size %d", sector_size); block_shift = -1;