memcmp.S 2.4 KB

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