Changeset 8e3f47b3 in mainline


Ignore:
Timestamp:
2005-10-04T22:06:07Z (19 years ago)
Author:
Sergey Bondari <bondari@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1084a784
Parents:
ce031f0
Message:

ia-32 memcmp inline

Location:
arch/ia32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • arch/ia32/include/memstr.h

    rce031f0 r8e3f47b3  
    3232extern void memsetw(__address dst, size_t cnt, __u16 x);
    3333extern void memsetb(__address dst, size_t cnt, __u8 x);
    34 
    35 extern int memcmp(__address src, __address dst, int cnt);
    3634
    3735/** Copy memory
     
    7270
    7371
     72/** Compare memory
     73 *
     74 * Compare a given number of bytes (3rd argument)
     75 * at memory locations defined by 1st and 2nd argument
     76 * for equality. If memory is equal, returns 0.
     77 *
     78 * @param pointer 1
     79 * @param pointer 2
     80 * @param number of bytes
     81 * @return 0 on match or non-zero if different
     82 */
     83static inline int memcmp(const void * mem1, const void * mem2, size_t cnt)
     84{
     85        __u32 d0, d1, d2;
     86        int ret;
     87       
     88        __asm__ (
     89                "repe cmpsb\n\t"
     90                "je 1f\n\t"
     91                "movl %3, %0\n\t"
     92                "addl $1, %0\n\t"
     93                "1:\n"
     94                : "=a" (ret), "=%S" (d0), "=&D" (d1), "=&c" (d2)
     95                : "0" (0), "1" (mem1), "2" (mem2), "3" (cnt)
     96        );
     97       
     98        return ret;
     99}
    74100
    75101#endif
  • arch/ia32/src/asm.S

    rce031f0 r8e3f47b3  
    4040.global memsetb
    4141.global memsetw
    42 .global memcmp
    43 
    4442
    4543## Turn paging on
     
    200198        pop %eax
    201199
    202         ret
    203 
    204 
    205 ## Compare memory regions for equality
    206 #
    207 # Compare a given number of bytes (3rd argument)
    208 # at memory locations defined by 1st and 2nd argument
    209 # for equality. If the bytes are equal, EAX contains 0.
    210 #
    211 SRC=12
    212 DST=16
    213 CNT=20
    214 memcmp:
    215         push %esi
    216         push %edi
    217 
    218         movl CNT(%esp),%ecx
    219         movl DST(%esp),%edi
    220         movl SRC(%esp),%esi
    221 
    222         repe cmpsb %es:(%edi),%ds:(%esi)
    223         movl %ecx,%eax          # %ecx contains the return value (zero on success)
    224 
    225         pop %edi
    226         pop %esi
    227        
    228200        ret
    229201
Note: See TracChangeset for help on using the changeset viewer.