Changeset 113 for trunk


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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/x86_64/core/hal_acpi.c

    r89 r113  
    3333#include <core.h>
    3434#include <cluster.h>
    35 
    36 /* XXX XXX libk XXX XXX */
    37 int memcmp(char *s1, char *s2, size_t n)
    38 {
    39         size_t i;
    40         for(i = 0; i < n; i++) {
    41                 if (s1[i] != s2[i])
    42                         return 1;
    43         }
    44         return 0;
    45 }
    4635
    4736/* -------------------------------------------------------------------------- */
  • 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
  • trunk/kernel/libk/memcpy.h

    r11 r113  
    2727/*******************************************************************************************
    2828 * This function copies a source buffer to a destination buffer.
    29  * There is no alignment constraint, but the performances are improved if th buffers
    30  * are both aligned on a 32 bits word boundary. 
     29 * There is no alignment constraint, but the performance is improved if the buffers
     30 * are both aligned on a 32 bits word boundary.
    3131 *******************************************************************************************
    3232 * @ dst     : pointer on destination buffer.
     
    3737void * memcpy( void       * dst,
    3838               const void * src,
    39                uint32_t     size ); 
     39               uint32_t     size );
    4040
    4141/*******************************************************************************************
    42  * This function set a constant value in each byte of a target buffer.
     42 * This function sets a constant value in each byte of a target buffer.
    4343 *******************************************************************************************
    4444 * @ dst     : pointer on destination buffer.
    45  * @ val     : constant value (casted to uint8_t).
     45 * @ val     : constant value (cast to uint8_t).
    4646 * @ size    : number of bytes.
    4747 * @ return pointer on destination buffer.
    4848 ******************************************************************************************/
    49 void * memset( void     * dst, 
     49void * memset( void     * dst,
    5050               uint32_t   val,
    51                uint32_t size); 
     51               uint32_t size);
    5252
     53/*******************************************************************************************
     54 * TODO
     55 ******************************************************************************************/
     56int memcmp( const void * s1,
     57            const void * s2,
     58            uint32_t     n);
     59
Note: See TracChangeset for help on using the changeset viewer.