strpas.inc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.3 2002-08-10 17:14:36 jonas
  46. * various fixes, mostly changing the names of the modifies registers to
  47. upper case since that seems to be required by the compiler
  48. Revision 1.2 2001/09/28 13:23:44 jonas
  49. * small optimization
  50. Revision 1.1 2001/09/27 15:30:29 jonas
  51. * conversion to compilerproc and to structure used by i386 rtl
  52. * some bugfixes
  53. * powerpc.inc is almost complete (only fillchar/word/dword, get_frame etc
  54. and the class helpers are still needed
  55. - removed unnecessary register saving in set.inc (thanks to compilerproc)
  56. * use registers reserved for parameters as much as possible instead of
  57. those reserved for local vars (since those have to be saved by the
  58. called anyway, while the ones for local vars have to be saved by the
  59. callee)
  60. }