Ignore:
Timestamp:
Jun 30, 2017, 11:03:08 AM (7 years ago)
Author:
max@…
Message:

add memcmp in libk; these mem* functions should probably be hal-
specific, for better performance

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/memcpy.c

    r11 r113  
    2828void * memcpy( void       * dst,
    2929               const void * src,
    30                uint32_t     size) 
     30               uint32_t     size)
    3131{
    3232    uint32_t       * wdst = dst;
     
    3636    if (!((uint32_t) wdst & 3) && !((uint32_t) wsrc & 3) )
    3737    {
    38         while (size > 3) 
     38        while (size > 3)
    3939        {
    4040            *wdst++ = *wsrc++;
     
    4747
    4848    // byte per byte for last bytes (or not aligned)
    49     while (size--) 
     49    while (size--)
    5050    {
    5151        *cdst++ = *csrc++;
     
    5555
    5656//////////////////////////////
    57 void * memset( void     * dst, 
     57void * memset( void     * dst,
    5858               uint32_t   val,
    59                uint32_t   size) 
     59               uint32_t   size)
    6060{
    6161    // build 8 bits and 32 bits values
     
    8686}
    8787
     88//////////////////////////////
     89int memcmp( const void * s1,
     90            const void * s2,
     91            uint32_t     n)
     92{
     93    const uint8_t * cs1 = s1;
     94    const uint8_t * cs2 = s2;
     95
     96    while (n > 0)
     97    {
     98        if (*cs1++ != *cs2++)
     99            return (*--cs1 - *--cs2);
     100        n--;
     101    }
     102    return 0;
     103}
     104
Note: See TracChangeset for help on using the changeset viewer.