strcmp.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* strcmp.S
  2. * Copyright (C) 2003, 2005, 2006 Analog Devices Inc., All Rights Reserved.
  3. *
  4. * This file is subject to the terms and conditions of the GNU Library General
  5. * Public License. See the file "COPYING.LIB" in the main directory of this
  6. * archive for more details.
  7. *
  8. * Non-LGPL License also available as part of VisualDSP++
  9. * http://www.analog.com/processors/resources/crosscore/visualDspDevSoftware.html
  10. */
  11. /* Fast strcmp() for Blackfin.
  12. * When both strings are aligned, this processes four characters at
  13. * a time. Uses a hw loop with "very big" count to loop "forever",
  14. * until difference or a terminating zero is found.
  15. * Once the end-case word has been identified, breaks out of the
  16. * loop to check more carefully (same as the unaligned case).
  17. */
  18. #include <features.h>
  19. .text
  20. .align 2
  21. .global _strcmp
  22. .type _strcmp, STT_FUNC
  23. _strcmp:
  24. [--sp] = (R7:4);
  25. p1 = r0;
  26. p2 = r1;
  27. p0 = -1; // (need for loop counter init)
  28. // check if byte aligned
  29. r0 = r0 | r1; // check both pointers at same time
  30. r0 <<= 30; // dump all but last 2 bits
  31. cc = az; // are they zero?
  32. if !cc jump unaligned; // no; use unaligned code.
  33. // fall-thru for aligned case..
  34. // note that r0 is zero from the previous...
  35. // p0 set to -1
  36. lsetup (beginloop, endloop) lc0=p0;
  37. // pick up first words
  38. r1 = [p1++];
  39. r2 = [p2++];
  40. // make up mask: 0FF0FF
  41. r7 = 0xFF;
  42. r7.h = 0xFF;
  43. // loop : 9 cycles to check 4 characters
  44. cc = r1 == r2;
  45. beginloop:
  46. if !cc jump notequal4; // compare failure, exit loop
  47. // starting with 44332211
  48. // see if char 3 or char 1 is 0
  49. r3 = r1 & r7; // form 00330011
  50. // add to zero, and (r2 is free, reload)
  51. r6 = r3 +|+ r0 || r2 = [p2++] || nop;
  52. cc = az; // true if either is zero
  53. r3 = r1 ^ r3; // form 44002200 (4321^0301 => 4020)
  54. // (trick, saves having another mask)
  55. // add to zero, and (r1 is free, reload)
  56. r6 = r3 +|+ r0 || r1 = [p1++] || nop;
  57. cc |= az; // true if either is zero
  58. if cc jump zero4; // leave if a zero somewhere
  59. endloop:
  60. cc = r1 == r2;
  61. // loop exits
  62. notequal4: // compare failure on 4-char compare
  63. // address pointers are one word ahead;
  64. // faster to use zero4 exit code
  65. p1 += 4;
  66. p2 += 4;
  67. zero4: // one of the bytes in word 1 is zero
  68. // but we've already fetched the next word; so
  69. // backup two to look at failing word again
  70. p1 += -8;
  71. p2 += -8;
  72. // here when pointers are unaligned: checks one
  73. // character at a time. Also use at the end of
  74. // the word-check algorithm to figure out what happened
  75. unaligned:
  76. // R0 is non-zero from before.
  77. // p0 set to -1
  78. r0 = 0 (Z);
  79. r1 = B[p1++] (Z);
  80. r2 = B[p2++] (Z);
  81. lsetup (beginloop1, endloop1) lc0=p0;
  82. beginloop1:
  83. cc = r1; // first char must be non-zero
  84. // chars must be the same
  85. r3 = r2 - r1 (NS) || r1 = B[p1++] (Z) || nop;
  86. cc &= az;
  87. r3 = r0 - r2; // second char must be non-zero
  88. cc &= an;
  89. if !cc jump exitloop1;
  90. endloop1:
  91. r2 = B[p2++] (Z);
  92. exitloop1: // here means we found a zero or a difference.
  93. // we have r2(N), p2(N), r1(N+1), p1(N+2)
  94. r1=B[p1+ -2] (Z);
  95. r0 = r1 - r2;
  96. (r7:4) = [sp++];
  97. rts;
  98. .size _strcmp,.-_strcmp
  99. libc_hidden_def (strcmp)
  100. #ifndef __UCLIBC_HAS_LOCALE__
  101. strong_alias (strcmp,strcoll)
  102. libc_hidden_def (strcoll)
  103. #endif