strcmp.S 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ! Copyright (C) 2013 Imagination Technologies Ltd.
  2. ! Licensed under LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  3. #include <features.h>
  4. .text
  5. .global _strcmp
  6. .type _strcmp,function
  7. !D1Ar1 s1
  8. !D0Ar2 s2
  9. _strcmp:
  10. TST D1Ar1,#3
  11. TSTZ D0Ar2,#3
  12. MOVT D1Re0,#0x0101
  13. ADD D1Re0,D1Re0,#0x0101
  14. BNZ $Lstrcmp_slow
  15. GETD D1Ar3,[D1Ar1+#4++] ! Load 32-bits from s1
  16. GETD D1Ar5,[D0Ar2+#4++] ! Load 32-bits from s2
  17. LSL D0FrT,D1Re0,#7 ! D0FrT = 0x80808080
  18. $Lstrcmp4_loop:
  19. SUB D0Re0,D1Ar3,D1Re0 ! D1Re0 = 0x01010101
  20. MOV D0Ar6,D1Ar3
  21. SUBS D0Ar4,D1Ar3,D1Ar5 ! Calculate difference
  22. XOR D0Ar6,D0Ar6,#-1
  23. GETD D1Ar3,[D1Ar1+#4++] ! Load 32-bits from s1
  24. AND D0Re0,D0Re0,D0Ar6
  25. ANDSZ D0Ar6,D0Re0,D0FrT ! D0FrT = 0x80808080
  26. GETD D1Ar5,[D0Ar2+#4++] ! Load 32-bits from s2
  27. BZ $Lstrcmp4_loop
  28. AND D0Ar6, D0Re0, D0FrT ! D0FrT = 0x80808080
  29. !
  30. ! Either they are different or they both contain a NULL + junk
  31. !
  32. $Lstrcmp4_end:
  33. LSLS D0Re0,D0Ar4,#24 ! Was Byte[0] the same?
  34. LSLSZ D0Ar2,D0Ar6,#24 ! Yes: AND they where not zero?
  35. LSLSZ D0Re0,D0Ar4,#16 ! Yes: Was Byte[1] the same?
  36. LSLSZ D0Ar2,D0Ar6,#16 ! Yes: AND they where not zero?
  37. LSLSZ D0Re0,D0Ar4,#8 ! Tes: Was Byte[2] the same?
  38. LSLSZ D0Ar2,D0Ar6,#8 ! Yes: AND they where not zero?
  39. MOVZ D0Re0,D0Ar4 ! Yes: Must by Byte[3] thats the result
  40. ASR D0Re0,D0Re0,#24 ! Sign extend result to integer
  41. MOV PC,D1RtP
  42. !
  43. ! Misaligned case, byte at a time
  44. !
  45. $Lstrcmp_slow:
  46. GETB D1Ar3,[D1Ar1++] ! Load char from s1
  47. GETB D1Ar5,[D0Ar2++] ! Load char from s2
  48. CMP D1Ar3,#1 ! Null -> C and NZ, rest -> NC (\1->Z)
  49. CMPNC D1Ar3,D1Ar5 ! NOT Null: Same -> Z, else -> NZ
  50. BZ $Lstrcmp_slow ! NOT Null and Same: Loop
  51. SUB D0Re0,D1Ar3,D1Ar5 ! Generate result
  52. MOV PC,D1RtP
  53. .size _strcmp,.-_strcmp
  54. libc_hidden_def(strcmp)
  55. #ifndef __UCLIBC_HAS_LOCALE__
  56. strong_alias(strcmp,strcoll)
  57. libc_hidden_def(strcoll)
  58. #endif