strpas.inc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 specific implementation of strpas
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. asm
  13. { load the begin of the string in the data cache }
  14. dcbt 0,r3
  15. { load result address in r9 }
  16. li r0,__RESULT@l
  17. addis r0,__RESULT@ha
  18. { maxlength }
  19. li r10,255
  20. mtctr r10
  21. lwz r0,0(r0)
  22. { save address for at the end }
  23. mr r3,r0
  24. { no "subi r0,r0,1" because the first byte = length byte }
  25. subi r4,r4,1
  26. LStrPasLoop:
  27. lbzu r10,1(r4)
  28. cmpli r10,0
  29. stbu r10,1(r0)
  30. bdnzf cr0*4+eq, LStrPasLoop
  31. { if we stopped because of a terminating #0, decrease the length by 1 }
  32. cntlzw r4,r10
  33. { get remaining count for length }
  34. mfctr r10
  35. { if r10 was zero (-> stopped because of zero byte), then r4 will be 32 }
  36. { (32 leading zero bits) -> shr 31 = 1, otherwise this will be zero }
  37. srwi r4,r4,31
  38. subfic r10,r10,255
  39. sub r10,r10,r4
  40. { store length }
  41. stb r10,0(r3)
  42. end ['r0','r3','r4','r10','cr0','ctr'];
  43. {
  44. $Log$
  45. Revision 1.2 2001-09-28 13:23:44 jonas
  46. * small optimization
  47. Revision 1.1 2001/09/27 15:30:29 jonas
  48. * conversion to compilerproc and to structure used by i386 rtl
  49. * some bugfixes
  50. * powerpc.inc is almost complete (only fillchar/word/dword, get_frame etc
  51. and the class helpers are still needed
  52. - removed unnecessary register saving in set.inc (thanks to compilerproc)
  53. * use registers reserved for parameters as much as possible instead of
  54. those reserved for local vars (since those have to be saved by the
  55. called anyway, while the ones for local vars have to be saved by the
  56. callee)
  57. }