memcmp.S 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * File: memcmp.S
  3. *
  4. * Copyright 2004-2007 Analog Devices Inc.
  5. * Enter bugs at http://blackfin.uclinux.org/
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. .align 2
  10. /*
  11. * C Library function MEMCMP
  12. * R0 = First Address
  13. * R1 = Second Address
  14. * R2 = count
  15. * Favours word aligned data.
  16. */
  17. .globl _memcmp;
  18. .type _memcmp, STT_FUNC;
  19. _memcmp:
  20. I1 = P3;
  21. P0 = R0; /* P0 = s1 address */
  22. P3 = R1; /* P3 = s2 Address */
  23. P2 = R2 ; /* P2 = count */
  24. CC = R2 <= 7(IU);
  25. IF CC JUMP .Ltoo_small;
  26. I0 = R1; /* s2 */
  27. R1 = R1 | R0; /* OR addresses together */
  28. R1 <<= 30; /* check bottom two bits */
  29. CC = AZ; /* AZ set if zero. */
  30. IF !CC JUMP .Lbytes ; /* Jump if addrs not aligned. */
  31. P1 = P2 >> 2; /* count = n/4 */
  32. R3 = 3;
  33. R2 = R2 & R3; /* remainder */
  34. P2 = R2; /* set remainder */
  35. LSETUP (.Lquad_loop_s , .Lquad_loop_e) LC0=P1;
  36. .Lquad_loop_s:
  37. NOP;
  38. R0 = [P0++];
  39. R1 = [I0++];
  40. CC = R0 == R1;
  41. IF !CC JUMP .Lquad_different;
  42. .Lquad_loop_e:
  43. NOP;
  44. P3 = I0; /* s2 */
  45. .Ltoo_small:
  46. CC = P2 == 0; /* Check zero count*/
  47. IF CC JUMP .Lfinished; /* very unlikely*/
  48. .Lbytes:
  49. LSETUP (.Lbyte_loop_s , .Lbyte_loop_e) LC0=P2;
  50. .Lbyte_loop_s:
  51. R1 = B[P3++](Z); /* *s2 */
  52. R0 = B[P0++](Z); /* *s1 */
  53. CC = R0 == R1;
  54. IF !CC JUMP .Ldifferent;
  55. .Lbyte_loop_e:
  56. NOP;
  57. .Ldifferent:
  58. R0 = R0 - R1;
  59. P3 = I1;
  60. RTS;
  61. .Lquad_different:
  62. /* We've read two quads which don't match.
  63. * Can't just compare them, because we're
  64. * a little-endian machine, so the MSBs of
  65. * the regs occur at later addresses in the
  66. * string.
  67. * Arrange to re-read those two quads again,
  68. * byte-by-byte.
  69. */
  70. P0 += -4; /* back up to the start of the */
  71. P3 = I0; /* quads, and increase the*/
  72. P2 += 4; /* remainder count*/
  73. P3 += -4;
  74. JUMP .Lbytes;
  75. .Lfinished:
  76. R0 = 0;
  77. P3 = I1;
  78. RTS;
  79. .size _memcmp, .-_memcmp