strings.inc 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. Processor dependent part of strings.pp, that can be shared with
  6. sysutils unit.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {$ASMMODE ATT}
  14. function strcopy(dest,source : pchar) : pchar;assembler;
  15. asm
  16. cld
  17. movl source,%edi
  18. orl %edi,%edi
  19. jz .LStrCopyNil
  20. movl $0xffffffff,%ecx
  21. xorb %al,%al
  22. repne
  23. scasb
  24. not %ecx
  25. movl dest,%edi
  26. movl source,%esi
  27. movl %ecx,%eax
  28. shrl $2,%ecx
  29. rep
  30. movsl
  31. movl %eax,%ecx
  32. andl $3,%ecx
  33. rep
  34. movsb
  35. .LStrCopyNil:
  36. movl dest,%eax
  37. end;
  38. function strecopy(dest,source : pchar) : pchar;assembler;
  39. asm
  40. cld
  41. movl source,%edi
  42. movl $0xffffffff,%ecx
  43. xorl %eax,%eax
  44. repne
  45. scasb
  46. not %ecx
  47. movl dest,%edi
  48. movl source,%esi
  49. movl %ecx,%eax
  50. shrl $2,%ecx
  51. rep
  52. movsl
  53. movl %eax,%ecx
  54. andl $3,%ecx
  55. rep
  56. movsb
  57. movl dest,%eax
  58. decl %edi
  59. movl %edi,%eax
  60. end ['EAX','ESI','EDI'];
  61. function strlcopy(dest,source : pchar;maxlen : longint) : pchar;assembler;
  62. asm
  63. movl source,%esi
  64. movl maxlen,%ecx
  65. movl dest,%edi
  66. orl %ecx,%ecx
  67. jz .LSTRLCOPY2
  68. cld
  69. .LSTRLCOPY1:
  70. lodsb
  71. stosb
  72. decl %ecx // Lower maximum
  73. jz .LSTRLCOPY2 // 0 reached ends
  74. orb %al,%al
  75. jnz .LSTRLCOPY1
  76. jmp .LSTRLCOPY3
  77. .LSTRLCOPY2:
  78. xorb %al,%al // If cutted
  79. stosb // add a #0
  80. .LSTRLCOPY3:
  81. movl dest,%eax
  82. end ['EAX','ECX','ESI','EDI'];
  83. function strlen(p : pchar) : longint;assembler;
  84. asm
  85. cld
  86. xorl %eax,%eax
  87. movl p,%edi
  88. orl %edi,%edi
  89. jz .LNil
  90. movl $0xffffffff,%ecx
  91. repne
  92. scasb
  93. movl $0xfffffffe,%eax
  94. subl %ecx,%eax
  95. .LNil:
  96. end ['EDI','ECX','EAX'];
  97. function strend(p : pchar) : pchar;assembler;
  98. asm
  99. cld
  100. xorl %eax,%eax
  101. movl p,%edi
  102. orl %edi,%edi
  103. jz .LStrEndNil
  104. movl $0xffffffff,%ecx
  105. xorl %eax,%eax
  106. repne
  107. scasb
  108. movl %edi,%eax
  109. decl %eax
  110. .LStrEndNil:
  111. end ['EDI','ECX','EAX'];
  112. function strcomp(str1,str2 : pchar) : longint;assembler;
  113. asm
  114. movl str2,%edi
  115. movl $0xffffffff,%ecx
  116. cld
  117. xorl %eax,%eax
  118. repne
  119. scasb
  120. not %ecx
  121. movl str2,%edi
  122. movl str1,%esi
  123. repe
  124. cmpsb
  125. movb -1(%esi),%al
  126. movzbl -1(%edi),%ecx
  127. subl %ecx,%eax
  128. end ['EAX','ECX','ESI','EDI'];
  129. function strlcomp(str1,str2 : pchar;l : longint) : longint;assembler;
  130. asm
  131. movl str2,%edi
  132. movl $0xffffffff,%ecx
  133. cld
  134. xorl %eax,%eax
  135. repne
  136. scasb
  137. not %ecx
  138. cmpl l,%ecx
  139. jl .LSTRLCOMP1
  140. movl l,%ecx
  141. .LSTRLCOMP1:
  142. movl str2,%edi
  143. movl str1,%esi
  144. repe
  145. cmpsb
  146. movb -1(%esi),%al
  147. movzbl -1(%edi),%ecx
  148. subl %ecx,%eax
  149. end ['EAX','ECX','ESI','EDI'];
  150. function stricomp(str1,str2 : pchar) : longint;assembler;
  151. asm
  152. movl str2,%edi
  153. movl $0xffffffff,%ecx
  154. cld
  155. xorl %eax,%eax
  156. repne
  157. scasb
  158. not %ecx
  159. movl str2,%edi
  160. movl str1,%esi
  161. .LSTRICOMP2:
  162. repe
  163. cmpsb
  164. jz .LSTRICOMP3 // If last reached then exit
  165. movzbl -1(%esi),%eax
  166. movzbl -1(%edi),%ebx
  167. cmpb $97,%al
  168. jb .LSTRICOMP1
  169. cmpb $122,%al
  170. ja .LSTRICOMP1
  171. subb $0x20,%al
  172. .LSTRICOMP1:
  173. cmpb $97,%bl
  174. jb .LSTRICOMP4
  175. cmpb $122,%bl
  176. ja .LSTRICOMP4
  177. subb $0x20,%bl
  178. .LSTRICOMP4:
  179. subl %ebx,%eax
  180. jz .LSTRICOMP2 // If still equal, compare again
  181. .LSTRICOMP3:
  182. end ['EAX','ECX','ESI','EDI'];
  183. function strlicomp(str1,str2 : pchar;l : longint) : longint;assembler;
  184. asm
  185. movl str2,%edi
  186. movl $0xffffffff,%ecx
  187. cld
  188. xorl %eax,%eax
  189. repne
  190. scasb
  191. not %ecx
  192. cmpl l,%ecx
  193. jl .LSTRLICOMP5
  194. movl l,%ecx
  195. .LSTRLICOMP5:
  196. movl str2,%edi
  197. movl str1,%esi
  198. .LSTRLICOMP2:
  199. repe
  200. cmpsb
  201. jz .LSTRLICOMP3 // If last reached, exit
  202. movzbl -1(%esi),%eax
  203. movzbl -1(%edi),%ebx
  204. cmpb $97,%al
  205. jb .LSTRLICOMP1
  206. cmpb $122,%al
  207. ja .LSTRLICOMP1
  208. subb $0x20,%al
  209. .LSTRLICOMP1:
  210. cmpb $97,%bl
  211. jb .LSTRLICOMP4
  212. cmpb $122,%bl
  213. ja .LSTRLICOMP4
  214. subb $0x20,%bl
  215. .LSTRLICOMP4:
  216. subl %ebx,%eax
  217. jz .LSTRLICOMP2
  218. .LSTRLICOMP3:
  219. end ['EAX','ECX','ESI','EDI'];
  220. function strscan(p : pchar;c : char) : pchar;assembler;
  221. asm
  222. xorl %eax,%eax
  223. movl p,%edi
  224. orl %edi,%edi
  225. jz .LSTRSCAN
  226. movl $0xffffffff,%ecx
  227. cld
  228. repne
  229. scasb
  230. not %ecx
  231. movb c,%al
  232. movl p,%edi
  233. repne
  234. scasb
  235. movl $0,%eax
  236. jnz .LSTRSCAN
  237. movl %edi,%eax
  238. decl %eax
  239. .LSTRSCAN:
  240. end;
  241. function strrscan(p : pchar;c : char) : pchar;assembler;
  242. asm
  243. xorl %eax,%eax
  244. movl p,%edi
  245. orl %edi,%edi
  246. jz .LSTRRSCAN
  247. movl $0xffffffff,%ecx
  248. cld
  249. xorb %al,%al
  250. repne
  251. scasb
  252. not %ecx
  253. movb c,%al
  254. movl p,%edi
  255. addl %ecx,%edi
  256. decl %edi
  257. std
  258. repne
  259. scasb
  260. cld
  261. movl $0,%eax
  262. jnz .LSTRRSCAN
  263. movl %edi,%eax
  264. incl %eax
  265. .LSTRRSCAN:
  266. end;
  267. function strupper(p : pchar) : pchar;assembler;
  268. asm
  269. movl p,%esi
  270. orl %esi,%esi
  271. jz .LStrUpperNil
  272. movl %esi,%edi
  273. .LSTRUPPER1:
  274. lodsb
  275. cmpb $97,%al
  276. jb .LSTRUPPER3
  277. cmpb $122,%al
  278. ja .LSTRUPPER3
  279. subb $0x20,%al
  280. .LSTRUPPER3:
  281. stosb
  282. orb %al,%al
  283. jnz .LSTRUPPER1
  284. .LStrUpperNil:
  285. movl p,%eax
  286. end;
  287. function strlower(p : pchar) : pchar;assembler;
  288. asm
  289. movl p,%esi
  290. orl %esi,%esi
  291. jz .LStrLowerNil
  292. movl %esi,%edi
  293. .LSTRLOWER1:
  294. lodsb
  295. cmpb $65,%al
  296. jb .LSTRLOWER3
  297. cmpb $90,%al
  298. ja .LSTRLOWER3
  299. addb $0x20,%al
  300. .LSTRLOWER3:
  301. stosb
  302. orb %al,%al
  303. jnz .LSTRLOWER1
  304. .LStrLowerNil:
  305. movl p,%eax
  306. end;
  307. {
  308. $Log$
  309. Revision 1.7 2000-02-09 16:59:29 peter
  310. * truncated log
  311. Revision 1.6 2000/01/07 16:41:33 daniel
  312. * copyright 2000
  313. Revision 1.5 1999/12/18 23:08:33 florian
  314. * bug 766 fixed
  315. }