memcmp.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. MNOP || R0 = [P0++] || R1 = [I0++];
  58. CC = R0 == R1;
  59. IF !CC JUMP .Lquad_different;
  60. .Lquad_loop_e:
  61. NOP;
  62. P3 = I0; /* s2 */
  63. .Ltoo_small:
  64. CC = P2 == 0; /* Check zero count*/
  65. IF CC JUMP .Lfinished; /* very unlikely*/
  66. .Lbytes:
  67. LSETUP (.Lbyte_loop_s, .Lbyte_loop_e) LC0=P2;
  68. .Lbyte_loop_s:
  69. R1 = B[P3++](Z); /* *s2 */
  70. R0 = B[P0++](Z); /* *s1 */
  71. CC = R0 == R1;
  72. IF !CC JUMP .Ldifferent;
  73. .Lbyte_loop_e:
  74. NOP;
  75. .Ldifferent:
  76. R0 = R0 - R1;
  77. P3 = I1;
  78. RTS;
  79. .Lquad_different:
  80. /* We've read two quads which don't match.
  81. * Can't just compare them, because we're
  82. * a little-endian machine, so the MSBs of
  83. * the regs occur at later addresses in the
  84. * string.
  85. * Arrange to re-read those two quads again,
  86. * byte-by-byte.
  87. */
  88. P0 += -4; /* back up to the start of the */
  89. P3 = I0; /* quads, and increase the*/
  90. P2 += 4; /* remainder count*/
  91. P3 += -4;
  92. JUMP .Lbytes;
  93. .Lfinished:
  94. R0 = 0;
  95. P3 = I1;
  96. RTS;
  97. .size _memcmp,.-_memcmp