strcmp.S 3.2 KB

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