Ticket #3281: ffs_posix_x86_opt.patch
File ffs_posix_x86_opt.patch, 3.0 KB (added by , 15 years ago) |
---|
-
src/system/libroot/posix/string/Jamfile
4 4 bcmp.c 5 5 bcopy.c 6 6 bzero.c 7 ffs.cpp8 7 memccpy.c 9 8 memchr.c 10 9 memcmp.c -
src/system/libroot/posix/string/arch/ppc/Jamfile
7 7 MergeObject posix_string_arch_$(TARGET_ARCH).o : 8 8 memcpy.c 9 9 memset.c 10 ffs.c 10 11 ; -
src/system/libroot/posix/string/arch/m68k/Jamfile
7 7 MergeObject posix_string_arch_$(TARGET_ARCH).o : 8 8 arch_string.S 9 9 memset.c 10 ffs.c 10 11 ; -
src/system/libroot/posix/string/arch/x86/arch_string.S
16 16 FUNCTION(memset): 17 17 jmp *(USER_COMMPAGE_ADDR + COMMPAGE_ENTRY_X86_MEMSET * 4) 18 18 FUNCTION_END(memset) 19 20 FUNCTION(ffs): 21 bsf 4(%esp), %eax 22 ret 23 FUNCTION_END(ffs) -
src/system/libroot/posix/string/arch/generic/ffs.c
1 /* 2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include <strings.h> 7 8 // find first (least significant) set bit 9 int 10 ffs(int value) 11 { 12 if (!value) 13 return 0; 14 15 // ToDo: This can certainly be optimized (e.g. by binary search). Or not 16 // unlikely there's a single assembler instruction... 17 for (int i = 1; i <= (int)sizeof(value) * 8; i++, value >>= 1) { 18 if (value & 1) 19 return i; 20 } 21 22 // never gets here 23 return 0; 24 } -
src/system/libroot/posix/string/ffs.cpp
1 /*2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.3 * Distributed under the terms of the MIT License.4 */5 6 #include <strings.h>7 8 // find first (least significant) set bit9 int10 ffs(int value)11 {12 if (!value)13 return 0;14 15 // ToDo: This can certainly be optimized (e.g. by binary search). Or not16 // unlikely there's a single assembler instruction...17 for (int i = 1; i <= (int)sizeof(value) * 8; i++, value >>= 1) {18 if (value & 1)19 return i;20 }21 22 // never gets here23 return 0;24 }