memcmp.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * File: memcmp.S
  3. *
  4. * Copyright 2004-2007 Analog Devices Inc.
  5. * Enter bugs at http://blackfin.uclinux.org/
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, see the file COPYING, or write
  19. * to the Free Software Foundation, Inc.,
  20. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. .align 2
  23. /*
  24. * C Library function MEMCMP
  25. * R0 = First Address
  26. * R1 = Second Address
  27. * R2 = count
  28. * Favours word aligned data.
  29. */
  30. .globl _memcmp;
  31. .type _memcmp, STT_FUNC;
  32. _memcmp:
  33. I1 = P3;
  34. P0 = R0; /* P0 = s1 address */
  35. P3 = R1; /* P3 = s2 Address */
  36. P2 = R2 ; /* P2 = count */
  37. CC = R2 <= 7(IU);
  38. IF CC JUMP .Ltoo_small;
  39. I0 = R1; /* s2 */
  40. R1 = R1 | R0; /* OR addresses together */
  41. R1 <<= 30; /* check bottom two bits */
  42. CC = AZ; /* AZ set if zero. */
  43. IF !CC JUMP .Lbytes ; /* Jump if addrs not aligned. */
  44. P1 = P2 >> 2; /* count = n/4 */
  45. R3 = 3;
  46. R2 = R2 & R3; /* remainder */
  47. P2 = R2; /* set remainder */
  48. LSETUP (.Lquad_loop_s , .Lquad_loop_e) LC0=P1;
  49. .Lquad_loop_s:
  50. NOP;
  51. R0 = [P0++];
  52. R1 = [I0++];
  53. CC = R0 == R1;
  54. IF !CC JUMP .Lquad_different;
  55. .Lquad_loop_e:
  56. NOP;
  57. P3 = I0; /* s2 */
  58. .Ltoo_small:
  59. CC = P2 == 0; /* Check zero count*/
  60. IF CC JUMP .Lfinished; /* very unlikely*/
  61. .Lbytes:
  62. LSETUP (.Lbyte_loop_s , .Lbyte_loop_e) LC0=P2;
  63. .Lbyte_loop_s:
  64. R1 = B[P3++](Z); /* *s2 */
  65. R0 = B[P0++](Z); /* *s1 */
  66. CC = R0 == R1;
  67. IF !CC JUMP .Ldifferent;
  68. .Lbyte_loop_e:
  69. NOP;
  70. .Ldifferent:
  71. R0 = R0 - R1;
  72. P3 = I1;
  73. RTS;
  74. .Lquad_different:
  75. /* We've read two quads which don't match.
  76. * Can't just compare them, because we're
  77. * a little-endian machine, so the MSBs of
  78. * the regs occur at later addresses in the
  79. * string.
  80. * Arrange to re-read those two quads again,
  81. * byte-by-byte.
  82. */
  83. P0 += -4; /* back up to the start of the */
  84. P3 = I0; /* quads, and increase the*/
  85. P2 += 4; /* remainder count*/
  86. P3 += -4;
  87. JUMP .Lbytes;
  88. .Lfinished:
  89. R0 = 0;
  90. P3 = I1;
  91. RTS;
  92. .size _memcmp, .-_memcmp