memcmp.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #include <sysdep.h>
  12. /* int memcmp(const void *s1, const void *s2, size_t n);
  13. * R0 = First Address (s1)
  14. * R1 = Second Address (s2)
  15. * R2 = count (n)
  16. *
  17. * Favours word aligned data.
  18. */
  19. .text
  20. .align 2
  21. .weak _memcmp
  22. ENTRY(_memcmp)
  23. I1 = P3;
  24. P0 = R0; /* P0 = s1 address */
  25. P3 = R1; /* P3 = s2 Address */
  26. P2 = R2 ; /* P2 = count */
  27. CC = R2 <= 7(IU);
  28. IF CC JUMP .Ltoo_small;
  29. I0 = R1; /* s2 */
  30. R1 = R1 | R0; /* OR addresses together */
  31. R1 <<= 30; /* check bottom two bits */
  32. CC = AZ; /* AZ set if zero. */
  33. IF !CC JUMP .Lbytes ; /* Jump if addrs not aligned. */
  34. P1 = P2 >> 2; /* count = n/4 */
  35. R3 = 3;
  36. R2 = R2 & R3; /* remainder */
  37. P2 = R2; /* set remainder */
  38. LSETUP (.Lquad_loop_s, .Lquad_loop_e) LC0=P1;
  39. .Lquad_loop_s:
  40. #if !defined(__WORKAROUND_AVOID_DAG1)
  41. MNOP || R0 = [P0++] || R1 = [I0++];
  42. #else
  43. R0 = [P0++];
  44. R1 = [I0++];
  45. #endif
  46. CC = R0 == R1;
  47. IF !CC JUMP .Lquad_different;
  48. .Lquad_loop_e:
  49. NOP;
  50. P3 = I0; /* s2 */
  51. .Ltoo_small:
  52. CC = P2 == 0; /* Check zero count*/
  53. IF CC JUMP .Lfinished; /* very unlikely*/
  54. .Lbytes:
  55. LSETUP (.Lbyte_loop_s, .Lbyte_loop_e) LC0=P2;
  56. .Lbyte_loop_s:
  57. R1 = B[P3++](Z); /* *s2 */
  58. R0 = B[P0++](Z); /* *s1 */
  59. CC = R0 == R1;
  60. IF !CC JUMP .Ldifferent;
  61. .Lbyte_loop_e:
  62. NOP;
  63. .Ldifferent:
  64. R0 = R0 - R1;
  65. P3 = I1;
  66. RTS;
  67. .Lquad_different:
  68. /* We've read two quads which don't match.
  69. * Can't just compare them, because we're
  70. * a little-endian machine, so the MSBs of
  71. * the regs occur at later addresses in the
  72. * string.
  73. * Arrange to re-read those two quads again,
  74. * byte-by-byte.
  75. */
  76. P0 += -4; /* back up to the start of the */
  77. P3 = I0; /* quads, and increase the*/
  78. P2 += 4; /* remainder count*/
  79. P3 += -4;
  80. JUMP .Lbytes;
  81. .Lfinished:
  82. R0 = 0;
  83. P3 = I1;
  84. RTS;
  85. .size _memcmp,.-_memcmp
  86. libc_hidden_def (memcmp)
  87. #ifdef __UCLIBC_SUSV3_LEGACY__
  88. weak_alias (memcmp,bcmp)
  89. #endif