memcmp.S 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright 2004-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the Clear BSD license or the GPL-2 (or later)
  5. */
  6. #include <linux/linkage.h>
  7. /* int memcmp(const void *s1, const void *s2, size_t n);
  8. * R0 = First Address (s1)
  9. * R1 = Second Address (s2)
  10. * R2 = count (n)
  11. *
  12. * Favours word aligned data.
  13. */
  14. .text
  15. .align 2
  16. ENTRY(_memcmp)
  17. I1 = P3;
  18. P0 = R0; /* P0 = s1 address */
  19. P3 = R1; /* P3 = s2 Address */
  20. P2 = R2 ; /* P2 = count */
  21. CC = R2 <= 7(IU);
  22. IF CC JUMP .Ltoo_small;
  23. I0 = R1; /* s2 */
  24. R1 = R1 | R0; /* OR addresses together */
  25. R1 <<= 30; /* check bottom two bits */
  26. CC = AZ; /* AZ set if zero. */
  27. IF !CC JUMP .Lbytes ; /* Jump if addrs not aligned. */
  28. P1 = P2 >> 2; /* count = n/4 */
  29. R3 = 3;
  30. R2 = R2 & R3; /* remainder */
  31. P2 = R2; /* set remainder */
  32. LSETUP (.Lquad_loop_s, .Lquad_loop_e) LC0=P1;
  33. .Lquad_loop_s:
  34. #if ANOMALY_05000202
  35. R0 = [P0++];
  36. R1 = [I0++];
  37. #else
  38. MNOP || R0 = [P0++] || R1 = [I0++];
  39. #endif
  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. ENDPROC(_memcmp)