Ticket #3281: ffs_posix_x86_opt.patch

File ffs_posix_x86_opt.patch, 3.0 KB (added by tqh, 15 years ago)

Final version?

  • src/system/libroot/posix/string/Jamfile

     
    44    bcmp.c
    55    bcopy.c
    66    bzero.c
    7     ffs.cpp
    87    memccpy.c
    98    memchr.c
    109    memcmp.c
  • src/system/libroot/posix/string/arch/ppc/Jamfile

     
    77MergeObject posix_string_arch_$(TARGET_ARCH).o :
    88    memcpy.c
    99    memset.c
     10    ffs.c
    1011;
  • src/system/libroot/posix/string/arch/m68k/Jamfile

     
    77MergeObject posix_string_arch_$(TARGET_ARCH).o :
    88    arch_string.S
    99    memset.c
     10    ffs.c
    1011;
  • src/system/libroot/posix/string/arch/x86/arch_string.S

     
    1616FUNCTION(memset):
    1717    jmp *(USER_COMMPAGE_ADDR + COMMPAGE_ENTRY_X86_MEMSET * 4)
    1818FUNCTION_END(memset)
     19
     20FUNCTION(ffs):
     21    bsf     4(%esp), %eax
     22    ret
     23FUNCTION_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
     9int
     10ffs(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 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 }