mirror of
https://github.com/SCST-project/scst.git
synced 2026-05-17 10:41:26 +00:00
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 <bvanassche@acm.org> git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4134 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user