strings.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. Processor dependent part of strings.pp, that can be shared with
  5. sysutils unit.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$ASMMODE ATT}
  13. {$ifndef FPC_UNIT_HAS_STRICOMP}
  14. {$define FPC_UNIT_HAS_STRICOMP}
  15. function stricomp(str1,str2 : PAnsiChar) : longint; assembler; nostackframe;
  16. { eax = str1, edx = str2 }
  17. asm
  18. push %ebx
  19. push %esi
  20. sub %eax, %edx { edx = str2 - str1 }
  21. lea -1(%eax), %esi { esi = str1 (-1), frees eax to use for str1^ for easier subtraction }
  22. .balign 16
  23. .LLoop:
  24. add $1, %esi
  25. movzbl (%esi), %eax { eax = str1^ }
  26. movzbl (%esi,%edx), %ebx { ebx = str2^ }
  27. test %eax, %eax
  28. jz .LSub
  29. cmp %ebx, %eax { Shortcut uppercasing if already equal. }
  30. je .LLoop
  31. lea -97(%eax), %ecx
  32. cmp $25, %ecx
  33. ja .LEaxUppercased
  34. sub $32, %eax
  35. .LEaxUppercased:
  36. lea -97(%ebx), %ecx
  37. cmp $25, %ecx
  38. ja .LEbxUppercased
  39. sub $32, %ebx
  40. .LEbxUppercased:
  41. cmp %ebx, %eax
  42. je .LLoop
  43. .LSub:
  44. sub %ebx, %eax
  45. pop %esi
  46. pop %ebx
  47. end;
  48. {$endif FPC_UNIT_HAS_STRICOMP}
  49. {$ifndef FPC_UNIT_HAS_STRLICOMP}
  50. {$define FPC_UNIT_HAS_STRLICOMP}
  51. function strlicomp(str1,str2 : PAnsiChar;l : sizeint) : longint; assembler; nostackframe;
  52. { eax = str1, edx = str2, ecx = L }
  53. asm
  54. push %ebx
  55. push %esi
  56. push %edi
  57. sub %eax, %edx { edx = str2 - str1 }
  58. lea -1(%eax), %esi { esi = str1 (-1), frees eax to use for str1^ for easier subtraction }
  59. .balign 16
  60. .LLoop:
  61. sub $1, %ecx
  62. jl .LNothing
  63. add $1, %esi
  64. movzbl (%esi), %eax { eax = str1^ }
  65. movzbl (%esi,%edx), %ebx { ebx = str2^ }
  66. test %eax, %eax
  67. jz .LSub
  68. cmp %ebx, %eax { Shortcut uppercasing if already equal. }
  69. je .LLoop
  70. lea -97(%eax), %edi
  71. cmp $25, %edi
  72. ja .LEaxUppercased
  73. sub $32, %eax
  74. .LEaxUppercased:
  75. lea -97(%ebx), %edi
  76. cmp $25, %edi
  77. ja .LEbxUppercased
  78. sub $32, %ebx
  79. .LEbxUppercased:
  80. cmp %ebx, %eax
  81. je .LLoop
  82. .LSub:
  83. sub %ebx, %eax
  84. pop %edi
  85. pop %esi
  86. pop %ebx
  87. ret
  88. .LNothing:
  89. xor %eax, %eax
  90. pop %edi
  91. pop %esi
  92. pop %ebx
  93. end;
  94. {$endif FPC_UNIT_HAS_STRLICOMP}
  95. {$ifndef FPC_UNIT_HAS_STRUPPER}
  96. {$define FPC_UNIT_HAS_STRUPPER}
  97. function strupper(p : PAnsiChar) : PAnsiChar; assembler; nostackframe;
  98. { eax = p }
  99. asm
  100. mov %eax, %ecx
  101. sub $1, %eax
  102. .balign 16
  103. .LLoop:
  104. inc %eax
  105. movzbl (%eax), %edx
  106. test %edx, %edx
  107. jz .LDone
  108. .LCheckLetterInEdx:
  109. sub $97, %edx
  110. cmp $25, %edx
  111. ja .LLoop
  112. add $(97 - 32), %edx
  113. mov %dl, (%eax)
  114. inc %eax { duplicate loop start instead of jmp .LLoop }
  115. movzbl (%eax), %edx
  116. test %edx, %edx
  117. jnz .LCheckLetterInEdx
  118. .LDone:
  119. mov %ecx, %eax
  120. end;
  121. {$endif FPC_UNIT_HAS_STRUPPER}
  122. {$ifndef FPC_UNIT_HAS_STRLOWER}
  123. {$define FPC_UNIT_HAS_STRLOWER}
  124. function strlower(p : PAnsiChar) : PAnsiChar; assembler; nostackframe;
  125. { eax = p }
  126. asm
  127. mov %eax, %ecx
  128. sub $1, %eax
  129. .balign 16
  130. .LLoop:
  131. inc %eax
  132. movzbl (%eax), %edx
  133. test %edx, %edx
  134. jz .LDone
  135. .LCheckLetterInEdx:
  136. sub $65, %edx
  137. cmp $25, %edx
  138. ja .LLoop
  139. add $(65 + 32), %edx
  140. mov %dl, (%eax)
  141. inc %eax { duplicate loop start instead of jmp .LLoop }
  142. movzbl (%eax), %edx
  143. test %edx, %edx
  144. jnz .LCheckLetterInEdx
  145. .LDone:
  146. mov %ecx, %eax
  147. end;
  148. {$endif FPC_UNIT_HAS_STRLOWER}