1/* memcmp.S 2 * Copyright (C) 2003-2007 Analog Devices Inc., All Rights Reserved. 3 * 4 * This file is subject to the terms and conditions of the GNU Library General 5 * Public License. See the file "COPYING.LIB" in the main directory of this 6 * archive for more details. 7 * 8 * Non-LGPL License also available as part of VisualDSP++ 9 * http://www.analog.com/processors/resources/crosscore/visualDspDevSoftware.html 10 */ 11 12#include <sysdep.h> 13 14/* int memcmp(const void *s1, const void *s2, size_t n); 15 * R0 = First Address (s1) 16 * R1 = Second Address (s2) 17 * R2 = count (n) 18 * 19 * Favours word aligned data. 20 */ 21 22.text 23 24.align 2 25 26.weak _memcmp 27ENTRY(_memcmp) 28 I1 = P3; 29 P0 = R0; /* P0 = s1 address */ 30 P3 = R1; /* P3 = s2 Address */ 31 P2 = R2 ; /* P2 = count */ 32 CC = R2 <= 7(IU); 33 IF CC JUMP .Ltoo_small; 34 I0 = R1; /* s2 */ 35 R1 = R1 | R0; /* OR addresses together */ 36 R1 <<= 30; /* check bottom two bits */ 37 CC = AZ; /* AZ set if zero. */ 38 IF !CC JUMP .Lbytes ; /* Jump if addrs not aligned. */ 39 40 P1 = P2 >> 2; /* count = n/4 */ 41 R3 = 3; 42 R2 = R2 & R3; /* remainder */ 43 P2 = R2; /* set remainder */ 44 45 LSETUP (.Lquad_loop_s, .Lquad_loop_e) LC0=P1; 46.Lquad_loop_s: 47#if !defined(__WORKAROUND_AVOID_DAG1) 48 MNOP || R0 = [P0++] || R1 = [I0++]; 49#else 50 R0 = [P0++]; 51 R1 = [I0++]; 52#endif 53 CC = R0 == R1; 54 IF !CC JUMP .Lquad_different; 55.Lquad_loop_e: 56 NOP; 57 58 P3 = I0; /* s2 */ 59.Ltoo_small: 60 CC = P2 == 0; /* Check zero count*/ 61 IF CC JUMP .Lfinished; /* very unlikely*/ 62 63.Lbytes: 64 LSETUP (.Lbyte_loop_s, .Lbyte_loop_e) LC0=P2; 65.Lbyte_loop_s: 66 R1 = B[P3++](Z); /* *s2 */ 67 R0 = B[P0++](Z); /* *s1 */ 68 CC = R0 == R1; 69 IF !CC JUMP .Ldifferent; 70.Lbyte_loop_e: 71 NOP; 72 73.Ldifferent: 74 R0 = R0 - R1; 75 P3 = I1; 76 RTS; 77 78.Lquad_different: 79 /* We've read two quads which don't match. 80 * Can't just compare them, because we're 81 * a little-endian machine, so the MSBs of 82 * the regs occur at later addresses in the 83 * string. 84 * Arrange to re-read those two quads again, 85 * byte-by-byte. 86 */ 87 P0 += -4; /* back up to the start of the */ 88 P3 = I0; /* quads, and increase the*/ 89 P2 += 4; /* remainder count*/ 90 P3 += -4; 91 JUMP .Lbytes; 92 93.Lfinished: 94 R0 = 0; 95 P3 = I1; 96 RTS; 97 98.size _memcmp,.-_memcmp 99 100libc_hidden_def (memcmp) 101 102#ifdef __UCLIBC_SUSV3_LEGACY__ 103weak_alias (memcmp,bcmp) 104#endif 105