memcmp.S 2.7 KB

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