Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[PATCH] speed up on find_first_bit for i386 (let compiler do the work)

Avoid using "rep scas", just let the compiler select a sequence of
regular instructions.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Steven Rostedt and committed by
Linus Torvalds
cd85c8b4 79a88102

+24 -30
+24 -30
include/asm-i386/bitops.h
··· 311 311 int find_next_zero_bit(const unsigned long *addr, int size, int offset); 312 312 313 313 /** 314 + * __ffs - find first bit in word. 315 + * @word: The word to search 316 + * 317 + * Undefined if no bit exists, so code should check against 0 first. 318 + */ 319 + static inline unsigned long __ffs(unsigned long word) 320 + { 321 + __asm__("bsfl %1,%0" 322 + :"=r" (word) 323 + :"rm" (word)); 324 + return word; 325 + } 326 + 327 + /** 314 328 * find_first_bit - find the first set bit in a memory region 315 329 * @addr: The address to start the search at 316 330 * @size: The maximum size to search ··· 334 320 */ 335 321 static inline int find_first_bit(const unsigned long *addr, unsigned size) 336 322 { 337 - int d0, d1; 338 - int res; 339 - 340 - /* This looks at memory. Mark it volatile to tell gcc not to move it around */ 341 - __asm__ __volatile__( 342 - "xorl %%eax,%%eax\n\t" 343 - "repe; scasl\n\t" 344 - "jz 1f\n\t" 345 - "leal -4(%%edi),%%edi\n\t" 346 - "bsfl (%%edi),%%eax\n" 347 - "1:\tsubl %%ebx,%%edi\n\t" 348 - "shll $3,%%edi\n\t" 349 - "addl %%edi,%%eax" 350 - :"=a" (res), "=&c" (d0), "=&D" (d1) 351 - :"1" ((size + 31) >> 5), "2" (addr), "b" (addr) : "memory"); 352 - return res; 323 + int x = 0; 324 + do { 325 + if (*addr) 326 + return __ffs(*addr) + x; 327 + addr++; 328 + if (x >= size) 329 + break; 330 + x += (sizeof(*addr)<<3); 331 + } while (1); 332 + return x; 353 333 } 354 334 355 335 /** ··· 365 357 __asm__("bsfl %1,%0" 366 358 :"=r" (word) 367 359 :"r" (~word)); 368 - return word; 369 - } 370 - 371 - /** 372 - * __ffs - find first bit in word. 373 - * @word: The word to search 374 - * 375 - * Undefined if no bit exists, so code should check against 0 first. 376 - */ 377 - static inline unsigned long __ffs(unsigned long word) 378 - { 379 - __asm__("bsfl %1,%0" 380 - :"=r" (word) 381 - :"rm" (word)); 382 360 return word; 383 361 } 384 362