strings.inc 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999 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 dest,%edi
  64. movl source,%esi
  65. movl maxlen,%ecx
  66. cld
  67. .LSTRLCOPY1:
  68. lodsb
  69. stosb
  70. decl %ecx // Lower maximum
  71. jz .LSTRLCOPY2 // 0 reached ends
  72. orb %al,%al
  73. jnz .LSTRLCOPY1
  74. jmp .LSTRLCOPY3
  75. .LSTRLCOPY2:
  76. xorb %al,%al // If cutted
  77. stosb // add a #0
  78. .LSTRLCOPY3:
  79. movl dest,%eax
  80. end ['EAX','ECX','ESI','EDI'];
  81. function strlen(p : pchar) : longint;assembler;
  82. asm
  83. cld
  84. xorl %eax,%eax
  85. movl p,%edi
  86. orl %edi,%edi
  87. jz .LNil
  88. movl $0xffffffff,%ecx
  89. repne
  90. scasb
  91. movl $0xfffffffe,%eax
  92. subl %ecx,%eax
  93. .LNil:
  94. end ['EDI','ECX','EAX'];
  95. function strend(p : pchar) : pchar;assembler;
  96. asm
  97. cld
  98. xorl %eax,%eax
  99. movl p,%edi
  100. orl %edi,%edi
  101. jz .LStrEndNil
  102. movl $0xffffffff,%ecx
  103. xorl %eax,%eax
  104. repne
  105. scasb
  106. movl %edi,%eax
  107. decl %eax
  108. .LStrEndNil:
  109. end ['EDI','ECX','EAX'];
  110. function strcomp(str1,str2 : pchar) : longint;assembler;
  111. asm
  112. movl str2,%edi
  113. movl $0xffffffff,%ecx
  114. cld
  115. xorl %eax,%eax
  116. repne
  117. scasb
  118. not %ecx
  119. movl str2,%edi
  120. movl str1,%esi
  121. repe
  122. cmpsb
  123. movb -1(%esi),%al
  124. movzbl -1(%edi),%ecx
  125. subl %ecx,%eax
  126. end ['EAX','ECX','ESI','EDI'];
  127. function strlcomp(str1,str2 : pchar;l : longint) : longint;assembler;
  128. asm
  129. movl str2,%edi
  130. movl $0xffffffff,%ecx
  131. cld
  132. xorl %eax,%eax
  133. repne
  134. scasb
  135. not %ecx
  136. cmpl l,%ecx
  137. jl .LSTRLCOMP1
  138. movl l,%ecx
  139. .LSTRLCOMP1:
  140. movl str2,%edi
  141. movl str1,%esi
  142. repe
  143. cmpsb
  144. movb -1(%esi),%al
  145. movzbl -1(%edi),%ecx
  146. subl %ecx,%eax
  147. end ['EAX','ECX','ESI','EDI'];
  148. function stricomp(str1,str2 : pchar) : longint;assembler;
  149. asm
  150. movl str2,%edi
  151. movl $0xffffffff,%ecx
  152. cld
  153. xorl %eax,%eax
  154. repne
  155. scasb
  156. not %ecx
  157. movl str2,%edi
  158. movl str1,%esi
  159. .LSTRICOMP2:
  160. repe
  161. cmpsb
  162. jz .LSTRICOMP3 // If last reached then exit
  163. movzbl -1(%esi),%eax
  164. movzbl -1(%edi),%ebx
  165. cmpb $97,%al
  166. jb .LSTRICOMP1
  167. cmpb $122,%al
  168. ja .LSTRICOMP1
  169. subb $0x20,%al
  170. .LSTRICOMP1:
  171. cmpb $97,%bl
  172. jb .LSTRICOMP4
  173. cmpb $122,%bl
  174. ja .LSTRICOMP4
  175. subb $0x20,%bl
  176. .LSTRICOMP4:
  177. subl %ebx,%eax
  178. jz .LSTRICOMP2 // If still equal, compare again
  179. .LSTRICOMP3:
  180. end ['EAX','ECX','ESI','EDI'];
  181. function strlicomp(str1,str2 : pchar;l : longint) : longint;assembler;
  182. asm
  183. movl str2,%edi
  184. movl $0xffffffff,%ecx
  185. cld
  186. xorl %eax,%eax
  187. repne
  188. scasb
  189. not %ecx
  190. cmpl l,%ecx
  191. jl .LSTRLICOMP5
  192. movl l,%ecx
  193. .LSTRLICOMP5:
  194. movl str2,%edi
  195. movl str1,%esi
  196. .LSTRLICOMP2:
  197. repe
  198. cmpsb
  199. jz .LSTRLICOMP3 // If last reached, exit
  200. movzbl -1(%esi),%eax
  201. movzbl -1(%edi),%ebx
  202. cmpb $97,%al
  203. jb .LSTRLICOMP1
  204. cmpb $122,%al
  205. ja .LSTRLICOMP1
  206. subb $0x20,%al
  207. .LSTRLICOMP1:
  208. cmpb $97,%bl
  209. jb .LSTRLICOMP4
  210. cmpb $122,%bl
  211. ja .LSTRLICOMP4
  212. subb $0x20,%bl
  213. .LSTRLICOMP4:
  214. subl %ebx,%eax
  215. jz .LSTRLICOMP2
  216. .LSTRLICOMP3:
  217. end ['EAX','ECX','ESI','EDI'];
  218. function strscan(p : pchar;c : char) : pchar;assembler;
  219. asm
  220. xorl %eax,%eax
  221. movl p,%edi
  222. orl %edi,%edi
  223. jz .LSTRSCAN
  224. movl $0xffffffff,%ecx
  225. cld
  226. repne
  227. scasb
  228. not %ecx
  229. movb c,%al
  230. movl p,%edi
  231. repne
  232. scasb
  233. movl $0,%eax
  234. jnz .LSTRSCAN
  235. movl %edi,%eax
  236. decl %eax
  237. .LSTRSCAN:
  238. end;
  239. function strrscan(p : pchar;c : char) : pchar;assembler;
  240. asm
  241. xorl %eax,%eax
  242. movl p,%edi
  243. orl %edi,%edi
  244. jz .LSTRRSCAN
  245. movl $0xffffffff,%ecx
  246. cld
  247. xorb %al,%al
  248. repne
  249. scasb
  250. not %ecx
  251. movb c,%al
  252. movl p,%edi
  253. addl %ecx,%edi
  254. decl %edi
  255. std
  256. repne
  257. scasb
  258. cld
  259. movl $0,%eax
  260. jnz .LSTRRSCAN
  261. movl %edi,%eax
  262. incl %eax
  263. .LSTRRSCAN:
  264. end;
  265. function strupper(p : pchar) : pchar;assembler;
  266. asm
  267. movl p,%esi
  268. orl %esi,%esi
  269. jz .LStrUpperNil
  270. movl %esi,%edi
  271. .LSTRUPPER1:
  272. lodsb
  273. cmpb $97,%al
  274. jb .LSTRUPPER3
  275. cmpb $122,%al
  276. ja .LSTRUPPER3
  277. subb $0x20,%al
  278. .LSTRUPPER3:
  279. stosb
  280. orb %al,%al
  281. jnz .LSTRUPPER1
  282. .LStrUpperNil:
  283. movl p,%eax
  284. end;
  285. function strlower(p : pchar) : pchar;assembler;
  286. asm
  287. movl p,%esi
  288. orl %esi,%esi
  289. jz .LStrLowerNil
  290. movl %esi,%edi
  291. .LSTRLOWER1:
  292. lodsb
  293. cmpb $65,%al
  294. jb .LSTRLOWER3
  295. cmpb $90,%al
  296. ja .LSTRLOWER3
  297. addb $0x20,%al
  298. .LSTRLOWER3:
  299. stosb
  300. orb %al,%al
  301. jnz .LSTRLOWER1
  302. .LStrLowerNil:
  303. movl p,%eax
  304. end;
  305. {
  306. $Log$
  307. Revision 1.4 1999-04-09 07:58:41 michael
  308. +Added checking for nil on most functions.
  309. Revision 1.3 1999/03/30 16:58:49 peter
  310. * use assembler and remove all rets
  311. Revision 1.2 1999/02/25 10:07:01 michael
  312. + Added header and log
  313. }