strcmp.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  4. */
  5. /* This is optimized primarily for the ARC700.
  6. It would be possible to speed up the loops by one cycle / word
  7. respective one cycle / byte by forcing double source 1 alignment, unrolling
  8. by a factor of two, and speculatively loading the second word / byte of
  9. source 1; however, that would increase the overhead for loop setup / finish,
  10. and strcmp might often terminate early. */
  11. #include <linux/linkage.h>
  12. ENTRY_CFI(strcmp)
  13. or r2,r0,r1
  14. bmsk_s r2,r2,1
  15. brne r2,0,.Lcharloop
  16. mov_s r12,0x01010101
  17. ror r5,r12
  18. .Lwordloop:
  19. ld.ab r2,[r0,4]
  20. ld.ab r3,[r1,4]
  21. nop_s
  22. sub r4,r2,r12
  23. bic r4,r4,r2
  24. and r4,r4,r5
  25. brne r4,0,.Lfound0
  26. breq r2,r3,.Lwordloop
  27. #ifdef __LITTLE_ENDIAN__
  28. xor r0,r2,r3 ; mask for difference
  29. sub_s r1,r0,1
  30. bic_s r0,r0,r1 ; mask for least significant difference bit
  31. sub r1,r5,r0
  32. xor r0,r5,r1 ; mask for least significant difference byte
  33. and_s r2,r2,r0
  34. and_s r3,r3,r0
  35. #endif /* LITTLE ENDIAN */
  36. cmp_s r2,r3
  37. mov_s r0,1
  38. j_s.d [blink]
  39. bset.lo r0,r0,31
  40. .balign 4
  41. #ifdef __LITTLE_ENDIAN__
  42. .Lfound0:
  43. xor r0,r2,r3 ; mask for difference
  44. or r0,r0,r4 ; or in zero indicator
  45. sub_s r1,r0,1
  46. bic_s r0,r0,r1 ; mask for least significant difference bit
  47. sub r1,r5,r0
  48. xor r0,r5,r1 ; mask for least significant difference byte
  49. and_s r2,r2,r0
  50. and_s r3,r3,r0
  51. sub.f r0,r2,r3
  52. mov.hi r0,1
  53. j_s.d [blink]
  54. bset.lo r0,r0,31
  55. #else /* BIG ENDIAN */
  56. /* The zero-detection above can mis-detect 0x01 bytes as zeroes
  57. because of carry-propagateion from a lower significant zero byte.
  58. We can compensate for this by checking that bit0 is zero.
  59. This compensation is not necessary in the step where we
  60. get a low estimate for r2, because in any affected bytes
  61. we already have 0x00 or 0x01, which will remain unchanged
  62. when bit 7 is cleared. */
  63. .balign 4
  64. .Lfound0:
  65. lsr r0,r4,8
  66. lsr_s r1,r2
  67. bic_s r2,r2,r0 ; get low estimate for r2 and get ...
  68. bic_s r0,r0,r1 ; <this is the adjusted mask for zeros>
  69. or_s r3,r3,r0 ; ... high estimate r3 so that r2 > r3 will ...
  70. cmp_s r3,r2 ; ... be independent of trailing garbage
  71. or_s r2,r2,r0 ; likewise for r3 > r2
  72. bic_s r3,r3,r0
  73. rlc r0,0 ; r0 := r2 > r3 ? 1 : 0
  74. cmp_s r2,r3
  75. j_s.d [blink]
  76. bset.lo r0,r0,31
  77. #endif /* ENDIAN */
  78. .balign 4
  79. .Lcharloop:
  80. ldb.ab r2,[r0,1]
  81. ldb.ab r3,[r1,1]
  82. nop_s
  83. breq r2,0,.Lcmpend
  84. breq r2,r3,.Lcharloop
  85. .Lcmpend:
  86. j_s.d [blink]
  87. sub r0,r2,r3
  88. END_CFI(strcmp)