strings.inc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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;
  15. begin
  16. asm
  17. cld
  18. movl 12(%ebp),%edi
  19. movl $0xffffffff,%ecx
  20. xorb %al,%al
  21. repne
  22. scasb
  23. not %ecx
  24. movl 8(%ebp),%edi
  25. movl 12(%ebp),%esi
  26. movl %ecx,%eax
  27. shrl $2,%ecx
  28. rep
  29. movsl
  30. movl %eax,%ecx
  31. andl $3,%ecx
  32. rep
  33. movsb
  34. movl 8(%ebp),%eax
  35. leave
  36. ret $8
  37. end;
  38. end;
  39. function strecopy(dest,source : pchar) : pchar;
  40. begin
  41. asm
  42. cld
  43. movl 12(%ebp),%edi
  44. movl $0xffffffff,%ecx
  45. xorl %eax,%eax
  46. repne
  47. scasb
  48. not %ecx
  49. movl 8(%ebp),%edi
  50. movl 12(%ebp),%esi
  51. movl %ecx,%eax
  52. shrl $2,%ecx
  53. rep
  54. movsl
  55. movl %eax,%ecx
  56. andl $3,%ecx
  57. rep
  58. movsb
  59. movl 8(%ebp),%eax
  60. decl %edi
  61. movl %edi,%eax
  62. leave
  63. ret $8
  64. end ['EAX','ESI','EDI'];
  65. end;
  66. function strlcopy(dest,source : pchar;maxlen : longint) : pchar;
  67. begin
  68. asm
  69. movl 8(%ebp),%edi
  70. movl 12(%ebp),%esi
  71. movl 16(%ebp),%ecx
  72. cld
  73. .LSTRLCOPY1:
  74. lodsb
  75. stosb
  76. decl %ecx // Lower maximum
  77. jz .LSTRLCOPY2 // 0 reached ends
  78. orb %al,%al
  79. jnz .LSTRLCOPY1
  80. movl 8(%ebp),%eax
  81. leave
  82. ret $12
  83. .LSTRLCOPY2:
  84. xorb %al,%al // If cutted
  85. stosb // add a #0
  86. movl 8(%ebp),%eax
  87. leave
  88. ret $12
  89. end ['EAX','ECX','ESI','EDI'];
  90. end;
  91. function strlen(p : pchar) : longint;
  92. begin
  93. asm
  94. cld
  95. movl 8(%ebp),%edi
  96. movl $0xffffffff,%ecx
  97. xorl %eax,%eax
  98. repne
  99. scasb
  100. movl $0xfffffffe,%eax
  101. subl %ecx,%eax
  102. leave
  103. ret $4
  104. end ['EDI','ECX','EAX'];
  105. end;
  106. function strend(p : pchar) : pchar;
  107. begin
  108. asm
  109. cld
  110. movl 8(%ebp),%edi
  111. movl $0xffffffff,%ecx
  112. xorl %eax,%eax
  113. repne
  114. scasb
  115. movl %edi,%eax
  116. decl %eax
  117. leave
  118. ret $4
  119. end ['EDI','ECX','EAX'];
  120. end;
  121. function strcomp(str1,str2 : pchar) : longint;
  122. begin
  123. asm
  124. // Find terminating zero
  125. movl 12(%ebp),%edi
  126. movl $0xffffffff,%ecx
  127. cld
  128. xorl %eax,%eax
  129. repne
  130. scasb
  131. not %ecx
  132. movl 12(%ebp),%edi
  133. movl 8(%ebp),%esi
  134. repe
  135. cmpsb
  136. movb -1(%esi),%al
  137. movzbl -1(%edi),%ecx
  138. subl %ecx,%eax
  139. leave
  140. ret $8
  141. end ['EAX','ECX','ESI','EDI'];
  142. end;
  143. function strlcomp(str1,str2 : pchar;l : longint) : longint;
  144. begin
  145. asm
  146. // Find terminating zero
  147. movl 12(%ebp),%edi
  148. movl $0xffffffff,%ecx
  149. cld
  150. xorl %eax,%eax
  151. repne
  152. scasb
  153. not %ecx
  154. cmpl 16(%ebp),%ecx
  155. jl .LSTRLCOMP1
  156. movl 16(%ebp),%ecx
  157. .LSTRLCOMP1:
  158. movl 12(%ebp),%edi
  159. movl 8(%ebp),%esi
  160. repe
  161. cmpsb
  162. movb -1(%esi),%al
  163. movzbl -1(%edi),%ecx
  164. subl %ecx,%eax
  165. leave
  166. ret $12
  167. end ['EAX','ECX','ESI','EDI'];
  168. end;
  169. function stricomp(str1,str2 : pchar) : longint;
  170. begin
  171. asm
  172. // Find terminating zero
  173. movl 12(%ebp),%edi
  174. movl $0xffffffff,%ecx
  175. cld
  176. xorl %eax,%eax
  177. repne
  178. scasb
  179. not %ecx
  180. movl 12(%ebp),%edi
  181. movl 8(%ebp),%esi
  182. .LSTRICOMP2:
  183. repe
  184. cmpsb
  185. jz .LSTRICOMP3 // If last reached then exit
  186. movzbl -1(%esi),%eax
  187. movzbl -1(%edi),%ebx
  188. cmpb $97,%al
  189. jb .LSTRICOMP1
  190. cmpb $122,%al
  191. ja .LSTRICOMP1
  192. subb $0x20,%al
  193. .LSTRICOMP1:
  194. cmpb $97,%bl
  195. jb .LSTRICOMP4
  196. cmpb $122,%bl
  197. ja .LSTRICOMP4
  198. subb $0x20,%bl
  199. .LSTRICOMP4:
  200. subl %ebx,%eax
  201. jz .LSTRICOMP2 // If still equal, compare again
  202. .LSTRICOMP3:
  203. leave
  204. ret $8
  205. end ['EAX','ECX','ESI','EDI'];
  206. end;
  207. function strlicomp(str1,str2 : pchar;l : longint) : longint;
  208. begin
  209. asm
  210. // Search terminating zero
  211. movl 12(%ebp),%edi
  212. movl $0xffffffff,%ecx
  213. cld
  214. xorl %eax,%eax
  215. repne
  216. scasb
  217. not %ecx
  218. cmpl 16(%ebp),%ecx
  219. jl .LSTRLICOMP5
  220. movl 16(%ebp),%ecx
  221. .LSTRLICOMP5:
  222. movl 12(%ebp),%edi
  223. movl 8(%ebp),%esi
  224. .LSTRLICOMP2:
  225. repe
  226. cmpsb
  227. jz .LSTRLICOMP3 // If last reached, exit
  228. movzbl -1(%esi),%eax
  229. movzbl -1(%edi),%ebx
  230. cmpb $97,%al
  231. jb .LSTRLICOMP1
  232. cmpb $122,%al
  233. ja .LSTRLICOMP1
  234. subb $0x20,%al
  235. .LSTRLICOMP1:
  236. cmpb $97,%bl
  237. jb .LSTRLICOMP4
  238. cmpb $122,%bl
  239. ja .LSTRLICOMP4
  240. subb $0x20,%bl
  241. .LSTRLICOMP4:
  242. subl %ebx,%eax
  243. jz .LSTRLICOMP2
  244. .LSTRLICOMP3:
  245. leave
  246. ret $12
  247. end ['EAX','ECX','ESI','EDI'];
  248. end;
  249. function strscan(p : pchar;c : char) : pchar;
  250. begin
  251. asm
  252. movl 8(%ebp),%edi
  253. movl $0xffffffff,%ecx
  254. cld
  255. xorb %al,%al
  256. repne
  257. scasb
  258. not %ecx
  259. movb 12(%ebp),%al
  260. movl 8(%ebp),%edi
  261. repne
  262. scasb
  263. movl $0,%eax
  264. jnz .LSTRSCAN
  265. movl %edi,%eax
  266. decl %eax
  267. .LSTRSCAN:
  268. leave
  269. ret $6
  270. end;
  271. end;
  272. function strrscan(p : pchar;c : char) : pchar;
  273. begin
  274. asm
  275. movl 8(%ebp),%edi
  276. movl $0xffffffff,%ecx
  277. cld
  278. xorb %al,%al
  279. repne
  280. scasb
  281. not %ecx
  282. movb 12(%ebp),%al
  283. movl 8(%ebp),%edi
  284. addl %ecx,%edi
  285. decl %edi
  286. std
  287. repne
  288. scasb
  289. movl $0,%eax
  290. jnz .LSTRRSCAN
  291. movl %edi,%eax
  292. incl %eax
  293. .LSTRRSCAN:
  294. leave
  295. ret $6
  296. end;
  297. end;
  298. function strupper(p : pchar) : pchar;
  299. begin
  300. asm
  301. movl 8(%ebp),%esi
  302. movl %esi,%edi
  303. .LSTRUPPER1:
  304. lodsb
  305. cmpb $97,%al
  306. jb .LSTRUPPER3
  307. cmpb $122,%al
  308. ja .LSTRUPPER3
  309. subb $0x20,%al
  310. .LSTRUPPER3:
  311. stosb
  312. orb %al,%al
  313. jnz .LSTRUPPER1
  314. movl 8(%ebp),%eax
  315. leave
  316. ret $4
  317. end;
  318. end;
  319. function strlower(p : pchar) : pchar;
  320. begin
  321. asm
  322. movl 8(%ebp),%esi
  323. movl %esi,%edi
  324. .LSTRLOWER1:
  325. lodsb
  326. cmpb $65,%al
  327. jb .LSTRLOWER3
  328. cmpb $90,%al
  329. ja .LSTRLOWER3
  330. addb $0x20,%al
  331. .LSTRLOWER3:
  332. stosb
  333. orb %al,%al
  334. jnz .LSTRLOWER1
  335. movl 8(%ebp),%eax
  336. leave
  337. ret $4
  338. end;
  339. end;
  340. {
  341. $Log$
  342. Revision 1.2 1999-02-25 10:07:01 michael
  343. + Added header and log
  344. }