1/* Copyright (c) 2010  Jan Waclawek
2
3   based on libc/pmstring/memcmp_P.S which is
4   Copyright (c) 2002, 2007 Marek Michalkiewicz
5   Copyright (c) 2007  Dmitry Xmelkov
6   and on exteded program memory routines, which are
7   Copyright (c) 2006, Carlos Lamas
8
9   All rights reserved.
10
11   Redistribution and use in source and binary forms, with or without
12   modification, are permitted provided that the following conditions are met:
13
14   * Redistributions of source code must retain the above copyright
15     notice, this list of conditions and the following disclaimer.
16   * Redistributions in binary form must reproduce the above copyright
17     notice, this list of conditions and the following disclaimer in
18     the documentation and/or other materials provided with the
19     distribution.
20   * Neither the name of the copyright holders nor the names of
21     contributors may be used to endorse or promote products derived
22     from this software without specific prior written permission.
23
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  POSSIBILITY OF SUCH DAMAGE. */
35
36/* $Id: memcmp_PF.S 2503 2016-02-07 22:59:47Z joerg_wunsch $ */
37
38#if !defined(__AVR_TINY__)
39
40#if !defined(__DOXYGEN__)
41
42#include "macros.inc"
43
44#define s1_b1 r25
45#define s1_b0 r24
46#define s2_b3 r23
47#define s2_b2 r22
48#define s2_b1 r21
49#define s2_b0 r20
50#define len_b1 r19
51#define len_b0 r18
52
53#define ret_b1 r25
54#define ret_b0 r24
55
56/* the conditional caters for pre-1.6.8 libc and standalone use */
57#ifdef ASSEMBLY_CLIB_SECTION
58  ASSEMBLY_CLIB_SECTION
59#else
60  .text
61#endif
62  .global _U(memcmp_PF)
63  .type _U(memcmp_PF), @function
64_U(memcmp_PF):
65  X_movw  ZL, s2_b0
66  LPM_R0_ZPLUS_INIT s2_b2
67  X_movw  XL, s1_b0
68
69  rjmp  2f
70
711:
72  ld    ret_b0, X+
73  LPM_R0_ZPLUS_NEXT s2_b2
74  sub   ret_b0, r0
75  brne  3f
762:
77  subi  len_b0, lo8(1)
78  sbci  len_b1, hi8(1)
79  brsh  1b
80
81  sub   ret_b0, ret_b0
823:
83  sbc   ret_b1, ret_b1
84  ret
85
86  .size _U(memcmp_PF), . - _U(memcmp_PF)
87
88#endif /* not __DOXYGEN__ */
89
90#endif /* !defined(__AVR_TINY__) */
91