memcmp.S 2.2 KB

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