stringss.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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, not 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. function strpas(p : pchar) : string;
  14. begin
  15. asm
  16. movl p,%esi
  17. movl __RESULT,%edi
  18. movl %esi,%edx
  19. movl $1,%ecx
  20. andl $0x0fffffff8,%esi
  21. // skip length byte
  22. incl %edi
  23. subl %esi,%edx
  24. jz .LStrPasAligned
  25. movl p,%esi
  26. // align source to multiple of 4 (not dest, because we can't read past
  27. // the end of the source, since that may be past the end of the heap
  28. // -> sigsegv!!)
  29. .LStrPasAlignLoop:
  30. movb (%esi),%al
  31. incl %esi
  32. testb %al,%al
  33. jz .LStrPasDone
  34. incl %edi
  35. incb %cl
  36. decb %dl
  37. movb %al,-1(%edi)
  38. jne .LStrPasAlignLoop
  39. .balign 16
  40. .LStrPasAligned:
  41. movl (%esi),%eax
  42. addl $4,%esi
  43. // this won't overwrite data since the result = 255 char string
  44. // and we never process more than the first 255 chars of p
  45. movl %eax,(%edi)
  46. testl $0x0ff,%eax
  47. jz .LStrPasDone
  48. incl %ecx
  49. testl $0x0ff00,%eax
  50. jz .LStrPasDone
  51. incl %ecx
  52. testl $0x0ff0000,%eax
  53. jz .LStrPasDone
  54. incl %ecx
  55. testl $0x0ff000000,%eax
  56. jz .LStrPasDone
  57. incl %ecx
  58. addl $4,%edi
  59. cmpl $252,%ecx
  60. jbe .LStrPasAligned
  61. testb %cl,%cl
  62. jz .LStrPasDone
  63. movl (%esi),%eax
  64. .LStrPasEndLoop:
  65. testb %al,%al
  66. jz .LStrPasDone
  67. movb %al,(%edi)
  68. shrl $8,%eax
  69. incl %edi
  70. incb %cl
  71. jnz .LStrPasEndLoop
  72. .LStrPasDone:
  73. movl __RESULT,%edi
  74. addb $255,%cl
  75. movb %cl,(%edi)
  76. end ['EAX','ECX','EDX','ESI','EDI'];
  77. end;
  78. function strpcopy(d : pchar;const s : string) : pchar;assembler;
  79. asm
  80. pushl %esi // Save ESI
  81. cld
  82. movl s,%esi // Load Source adress
  83. movl d,%edi // load destination address
  84. movzbl (%esi),%ecx // load length in ECX
  85. incl %esi
  86. rep
  87. movsb
  88. movb $0,(%edi)
  89. movl d,%eax // return value to EAX
  90. popl %esi
  91. end ['EDI','EAX','ECX'];
  92. {
  93. $Log$
  94. Revision 1.1 2000-07-13 06:30:43 michael
  95. + Initial import
  96. Revision 1.15 2000/07/01 10:52:12 jonas
  97. * fixed reading past end-of-heap again (correctly this time I hope)
  98. Revision 1.14 2000/06/30 12:20:20 jonas
  99. * strpas is again slightly slower, but won't crash anymore if a pchar
  100. is passed to it that starts less than 4 bbytes from the heap end
  101. Revision 1.13 2000/06/12 19:53:32 peter
  102. * change .align to .balign
  103. Revision 1.12 2000/06/12 13:17:56 jonas
  104. * fixed typo :(
  105. Revision 1.11 2000/06/12 08:33:26 jonas
  106. * new fixed and faster strpas (previous version only returned the first
  107. 254 chars when the pchar was aligned on a 4 byte boundary and was >=
  108. 255 chars)
  109. Revision 1.10 2000/03/28 11:14:33 jonas
  110. * added missing register that is destroyed by strecopy
  111. + some destroyed register lists for procedures that didn't have one yet
  112. Revision 1.9 2000/02/09 16:59:29 peter
  113. * truncated log
  114. Revision 1.8 2000/01/11 22:56:57 pierre
  115. * wrong change for StrPas function corrected
  116. Revision 1.7 2000/01/11 21:12:15 marco
  117. * direct params to internal asm.
  118. Revision 1.6 2000/01/07 16:41:33 daniel
  119. * copyright 2000
  120. }