stringss.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.2 2000-07-13 11:33:42 michael
  95. + removed logs
  96. }