blob: 1d327c76f087d05bc098bf49b6f73bb7536663bc [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/* $OpenBSD: memcmp.S,v 1.4 2005/08/07 11:30:38 espie Exp $ */
2/*
3 * Written by J.T. Conklin <jtc@netbsd.org>.
4 * Public domain.
5 */
6
Elliott Hughes851e68a2014-02-19 16:53:20 -08007#include <private/bionic_asm.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08008
Haibo Huangb9244ff2018-08-11 10:12:13 -07009ENTRY(memcmp_generic)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080010 pushl %edi
11 pushl %esi
12 movl 12(%esp),%edi
13 movl 16(%esp),%esi
14 cld /* set compare direction forward */
15
16 movl 20(%esp),%ecx /* compare by words */
17 shrl $2,%ecx
18 repe
19 cmpsl
20 jne L5 /* do we match so far? */
21
22 movl 20(%esp),%ecx /* compare remainder by bytes */
23 andl $3,%ecx
24 repe
25 cmpsb
26 jne L6 /* do we match? */
27
28 xorl %eax,%eax /* we match, return zero */
29 popl %esi
30 popl %edi
31 ret
32
33L5: movl $4,%ecx /* We know that one of the next */
34 subl %ecx,%edi /* four pairs of bytes do not */
35 subl %ecx,%esi /* match. */
36 repe
37 cmpsb
38L6: movzbl -1(%edi),%eax /* Perform unsigned comparison */
39 movzbl -1(%esi),%edx
40 subl %edx,%eax
41 popl %esi
42 popl %edi
43 ret
Haibo Huangb9244ff2018-08-11 10:12:13 -070044END(memcmp_generic)