memcmp.S 2.6 KB

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